Flash AS3 | Finishing current animation set before

2019-08-27 12:26发布

问题:

I'm trying to solve a problem I have in Flash CC AS3 regarding button usage. I'll try and make this as easy to explain as I can.

I currently have two sets of frames that have motion in them: one of a man walking slowly (frames 1-30) and the next is the same man but walking much faster (frames 31-60). For both sets of animations, the start and end frames are exactly the same, so a seamless transition can be enabled if the transition happens at the end point of the currently viewed animation.

The sets work by themselves by simply playing from their start frame till the end frame, where AS code makes them stop and then jump back to the original start point and repeat, on endless loop. I have a button that, when pushed, jumps to the start point of the next animation, where the new animation is now played. EG the man is walking, I press the button, now the man is walking faster.

The problem is that when I push the button, the animation instantly changes from whatever frame you are currently on to the new start point, and this creates a 'cut' effect which looks awful because of the skipped frames. How would I be able to make it so that when the button is pushed, the remaining frames finish playing before jumping to the new animation? IE The man is mid walk at the 17th frame, and the user pushes the button. The animation plays out to the 30th frame before jumping over to play the 31st frame of the new loop.

I've tried toying around with an if statement, but I can't find the proper commands to solve this issue. Any help would be much appreciated

TL;DR Once resolved, the animation should perform as follows: Frames 1-30 are playing in a seamless loop. When I press a button, the animation will continue to play until Frame 30, where it will then begin to play Frames 31-60 in a loop.

Any help would be much appreciated!

回答1:

Nice and simple answer for this :) you could use an event listener to check if the current frame is frame 30 once the button is clicked. You could use an if statement for this check.

When the button is clicked add this listener:

addEventListener(Event.ENTER_FRAME, enterFrame);

And then check using this:

function enterFrame(e:Event):void {
    if (someAnimation.currentFrame == 30) {
        //do this
    }
}

A quick note that I'm on my iPhone so cannot check if this works although it's likely to.