Please help! Simple question. There are 5 movieclips on the stage (btn0 to btn4). I wanted to change focus pressing Keyboard.UP and Keyboard.DOWN. But the focus changes not in correct order. It jumps in mysterious way from 0 to 2 and so on. Please help!!! In case, .fla file is in attachment.
stage.addEventListener(KeyboardEvent.KEY_DOWN, reportKeyDown);
//hold active position
var activeElem:uint=0;
btn0.tabIndex=0;
btn1.tabIndex=1;
btn2.tabIndex=2;
btn3.tabIndex=3;
btn4.tabIndex=4;
//set focus on firs btn
setFocusOn(0);
function setFocusOn(id:uint):void {
var tempMc:MovieClip = MovieClip(this.getChildByName("btn"+id));
trace("tempMc= "+tempMc.name+ " at index="+tempMc.tabIndex);
stage.focus = tempMc;
trace("focus on= "+stage.focus.name);
trace("------");
}
function reportKeyDown(event:KeyboardEvent):void {
switch (event.keyCode) {
case Keyboard.UP :
if (activeElem>0) {
trace("up");
activeElem--;
setFocusOn(activeElem);
}
break;
case Keyboard.DOWN :
if (activeElem<4) {
trace("down");
activeElem++;
setFocusOn(activeElem);
}
}
}