Question

I need to navigate between labels with arrow keys like a power point presentation. I have an array with labels and a KeyboardEvent. My problem is, if I am in label number four for example and click in arrow click, always goes to first label. So I need help defining my current label to go to the next on key press.

My code:

import flash.events.KeyboardEvent;

var myLabels:Array = [ "label_1", "label_2", "label_3", "label_4"];
var nextLabel:String;
var inc:int = 0;

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);

function keyPressed(evt:KeyboardEvent):void
{
 switch(evt.keyCode)
 {
  case Keyboard.RIGHT :
  nextLabel = String(myLabels[inc]);
                gotoAndStop(nextLabel);
                inc++;
  break;
 }
}

Thanks

Was it helpful?

Solution

Remove var inc:int = 0; then do this:

case Keyboard.RIGHT :
    var inc:int = myLabels.indexOf (currentLabel); 
    inc = inc < myLabels.length-1 ? inc+1 : 0;
    nextLabel = String(myLabels[inc]);
    gotoAndStop(nextLabel);
    break;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top