I have the following code which should add a MovieClip and add a frame script to the MovieClip to be executed once the clip has finished playing. The code shown below however triggers the frame script as soon as the MovieClip is added and I can’t figure out why.
function debugClick(e:MouseEvent) : void
{
nextLevAnim = new NextLevelAnim();
gfx.addChild(nextLevAnim);
nextLevAnim.addFrameScript(nextLevAnim.totalFrames, NextLevel);
}
function NextLevel() : void
{
nextLevAnim.addFrameScript(nextLevAnim.totalFrames, null);
// Actions....
}
I’ve tried with simpler examples and it works fine, the MovieClip is 21 frames long and I’ve tried triggering the frame script by totalFrames and totalFrames - 1, running out of ideas!
hmm, I haven’t worked with
addFrameScriptmuch so I can’t tell what is causing the problems, but you could try using a hack.use an onEnterFrame listener and check if the current frame equals the number of frames (-1).
it’s not ideal, but if you’re stuck on this it might just do.
as far as
addFrameScriptgoes, my guess is that it’s not working because addMovieClip doesn’t take effect until the render part of cycle, so the totalframes are still 0 for the child added. You can add a listener foronAddedToStageoronAddedand add the addFrameScript event handler after theMovieClipgets initialized