Flash CS4, AS3 animation issue
I was making an animation in flash cs4 and i was making a play/pause button. Everything pauses when clicked but the play button gives me an issue. I have some movie clips with animations in them so when i tell them to play, instead of resuming where they were, they play regardless of whether or not they should be playing. Is ther开发者_如何学Ce a way to fix this?
you could try recursively going though all the movieclips in a moveclip and stoping them, from there modifiying the below's link source to play wouldn't be too bad either.
http://www.auricom.com/devote/using-recursion-to-perform-an-action-on-all-displayobject-children
one thing in the the above link, is if there is a sprite with a movieclip his code wouldn't traverse into a the sprite, here is a small mod for his code to catch that:
private function stopAllMovieClips(mc:*) : void {
trace("Stop: ", mc.name);
if(mc is MovieClip) mc.stop();
for (var i:int = 0; i < mc.numChildren; i++)
if (mc.getChildAt(i) is DisplayObjectContainer){ /// here is the mod
stopMovieClip(mc.getChildAt(i));
}
}
stopAllMovieClips(this);
Depending on what you're trying to accomplish, you may want to switch your movie clips to graphics.
A movie clip object will play on its own, completely ignoring whether its parent is playing or stopped. A graphic, on the other hand, will only play when its parent is playing, and in fact is locked to its parent's timeline. That is, if you have the parent go back one frame, the graphic will go back a frame as well.
If you want resume option, just do simple work.
- While pausing catch the frame number into a number
If mc is your movieClip,
> mc.stop();<br> var
> mcFrameNumber:Number = mc.currentFrame;
- Then when playing again,use
mc.gotoAndPlay(mcFrameNumber);
It will work.
精彩评论