Quantcast
Viewing all articles
Browse latest Browse all 13519

Having a case Keyboard.UP and .LEFT issue

Hello,

 

Putting together a simple slide show and looking to tie the slides to the arrow keys when an odd thing happened. I can move forward through the program but not backward. This issue is happening with both the Up and LEFT arrows which I want to move back through the program while the RIGHT and DOWN arrow move forward. Simple stuff right? But the LEFT and UP arrows do not shift the frames. The trace is showing me that the buttons are being pressed just like the DOWN and RIGHT arrows but the functions are not being completed. I thought the problem was with the prevFrame(); since it was the obvious difference between the lines of code.

 

stop();

 

 

stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_KeyboardDownHandler);

 

 

function fl_KeyboardDownHandler(event:KeyboardEvent):void

{

          trace("Key Code Pressed: " + event.keyCode);

  switch (event.keyCode)

          {

                    case Keyboard.UP:

                    {

                              if(currentFrame == 1){

                    gotoAndStop(10); }

                              else{                     

                    prevFrame(); }

                    }

 

                    case Keyboard.DOWN:

                    {

                              if(currentFrame == 10){

                    gotoAndStop(1); }

         else{

                    nextFrame(); }

                    }

 

             case Keyboard.LEFT:

                    {

                              if(currentFrame == 1){

                    gotoAndStop(10); }

                              else{

                    prevFrame(); }

                    }

 

                    case Keyboard.RIGHT:

                    {

                              if(currentFrame == 10){

                    gotoAndStop(1); }

          else{

                    nextFrame(); }

                    }

          }

}

 

 

 

Then I thought to switch around the code corresponding to the LEFT and RIGHT arrows and found that it was not the prevFrame(); that I thought it was. No, the buttons themselves are not responding, here is the changed code.

 

stop();

 

 

stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_KeyboardDownHandler);

 

 

function fl_KeyboardDownHandler(event:KeyboardEvent):void

{

          trace("Key Code Pressed: " + event.keyCode);

  switch (event.keyCode)

          {

                    case Keyboard.UP:

                    {

                              if(currentFrame == 1){

                    gotoAndStop(10); }

                              else{                     

                    prevFrame(); }

                    }

 

                    case Keyboard.DOWN:

                    {

                              if(currentFrame == 10){

                    gotoAndStop(1); }

         else{

                    nextFrame(); }

                    }

 

  case Keyboard.LEFT:

                    {

                              if(currentFrame == 10){

                    gotoAndStop(1); }

                              else{

                    nextFrame(); }

 

 

                    }

 

                    case Keyboard.RIGHT:

                    {

                              if(currentFrame == 1){

                    gotoAndStop(10); }

                              else{

                    prevFrame(); }

                    }

          }

}

When I swapped the actions connected to the LEFT arrow and the RIGHT arrow, the RIGHT arrow activated the prevFrame(); but the LEFT arrow was now dead. Something is preventing AS3 from triggering the action on the LEFT arrow and UP arrow that is not preventing it from happening on the DOWN and RIGHT arrow presses. Anyone have an idea as to why?

 

Thanks for your thoughts,

Brett


Viewing all articles
Browse latest Browse all 13519


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>