0

I have a combobox on the stage and changing its value I want to play only a certain range of frames:

stop();

combo01.addEventListener(Event.CHANGE, change);

function change(event:Event):void{
    if (combo01.selectedItem.label == "BAL"){
        gotoAndPlay(50);
        if (currentFrame == 99) {stop();}

    }
}

The game is not stopped but returned to frame 1.

qadenza
  • 9,025
  • 18
  • 73
  • 126
  • Why do you have everything in one time line if you only want to play parts of it. split it into individual MovieClips, then display the right MovieClip. – null Sep 26 '15 at 20:42

1 Answers1

0

You want your current frame check to happen when frame 99 is reached, not when change() is called. One way you can do this is to add a listener to check each frame as it is entered by the timeline until it reaches your desired frame:

addEventListener(Event.ENTER_FRAME, checkFrame);
function checkFrame(e:Event):void {
    if(currentFrame == 99){
        stop();
        removeEventListener(Event.ENTER_FRAME, checkFrame);
    }
}

Another way is to use the undocumented (but long supported) addFrameScript(): actionscript3 whats the point of addFrameScript

You could also just put a conditional stop() on frame 99, such as if (stopFrame == 99) stop(), then simply set stopFrame in your change handler.

You get the idea. You need your check to happen at frame 99.

Community
  • 1
  • 1
Aaron Beall
  • 49,769
  • 26
  • 85
  • 103