Actionscript 3 Navigate with Keyboard Between Labels

Posted by Sbml on Stack Overflow See other posts from Stack Overflow or by Sbml
Published on 2011-01-06T14:34:52Z Indexed on 2011/01/06 15:53 UTC
Read the original article Hit count: 307

Hello

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

© Stack Overflow or respective owner

Related posts about flash

Related posts about actionscript-3