0

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

Sbml
  • 1,907
  • 2
  • 16
  • 26

1 Answers1

1

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;
weltraumpirat
  • 22,544
  • 5
  • 40
  • 54
  • Thanks for your answer, resolve one problem that I have if I loop more than one time between labels. My big problem still is, if my location is label_2 and I click in right arrow key my presentation don't goes to Label_3, goes always to label_1. I don't know how to define current label. Thanks – Sbml Jan 06 '11 at 15:06
  • Did you change anything else int he code, or just added the line suggested above? – Roy Jan 06 '11 at 15:24
  • Just add The line. But still don't work correctly, if I begin presentation in label_3 and press right key, goes always to first label. – Sbml Jan 06 '11 at 15:31