Skip to main content
AmethystDragon
Participating Frequently
January 16, 2018
Answered

How to make a button that only advances to next image strip when previous strip ends?

  • January 16, 2018
  • 1 reply
  • 470 views

Hey, I just started using AS for the first time and I have a small flash that I'm working on and everything has been going good. But I'm having a problem with a button.

I have imported two image strips, 100 frames each, and as soon the flash loads, it plays the first strip in a loop until I press the button to move to the next strip. However, here is the issue, while it indeed goes to the next strip, it doesn't wait for the other to finish. How can I make it wait for the previous strip to finish before moving on to the next one when the button is pressed?

This topic has been closed for replies.
Correct answer kglad

yourbutton.addEventListener(MouseEvent.CLICK,f);

function f(e:MouseEvent):void{

this.addEventListener(Event.ENTER_FRAME,ff);

yourbutton.removeEventListener(MouseEvent.CLICK,f);

removeChild(yourbutton);

}

function ff(e:Event):void{

if(firststrip.currentFrame==firststrip.totalFrames){

this.removeEventListener(Event.ENTER_FRAME,ff);

// go to nextstrip

}

}

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
January 16, 2018

yourbutton.addEventListener(MouseEvent.CLICK,f);

function f(e:MouseEvent):void{

this.addEventListener(Event.ENTER_FRAME,ff);

yourbutton.removeEventListener(MouseEvent.CLICK,f);

removeChild(yourbutton);

}

function ff(e:Event):void{

if(firststrip.currentFrame==firststrip.totalFrames){

this.removeEventListener(Event.ENTER_FRAME,ff);

// go to nextstrip

}

}

AmethystDragon
Participating Frequently
January 16, 2018

Am I suppose to replace the firststrip part in this line: if(firststrip.currentFrame==firststrip.totalFrames){ with something?

AmethystDragon
Participating Frequently
January 16, 2018

you need to replace all the instance names with the ones you used and you need to replace "// go to nextstrip"


Oh right, ofcourse! Thank you for the help, it worked!