Copy link to clipboard
Copied
Hi all
Say if I have a MovieClip, that gets instantiated on a Class like this:
var myMC:MyMC = new MyMC();
addChild(myMC);
And that MovieClip has a class that looks something like this:
package{
import flash.display.MovieClip;
public class MyMC extends MovieClip{
public function MyMC(){
stop();
}
}
}
This myMC is an animation, which has a series of Labels in the timeline. However, there aren't any actions in the timeline, because in MovieClips that have custom classes that get added to the stage, I find that the actions in the timeline get ignored.
So if I want to play the animation for a sequence, and stop it when it reaches a label, the only way I've ever got this to work is to add a bunch of listeners to the MovieClip's class, like this:
public function playAnimation():void{
gotoAndPlay("animateIn");
addEventListener(Event.ENTER_FRAME, animateInHandler);
}
...
private function animateInHandler(e:Event):void{
if(currentLabel=="stopAnimateIn"){
stop();
}
removeEventListener(Event.ENTER_FRAME, animateInHandler);
}
This seems like a giant pain to do, especially when you start talking about more than 10 animation sequences in 1 MovieClip, and dozens of hese MovieClips on screen.
Is there an easier way to do this? Any help is always appreciated.
Thanks
Chris
Copy link to clipboard
Copied
you can create one playF(mc:MovieClip,startFrame:Number,endFrame:Number); so you don't have to rewrite the same code repeatedly.
Copy link to clipboard
Copied
I find that stop scripts in a movieclip work fine. I literally copied and pasted your scripts into a test movie/AS file, and put in a tween in the movieclip in the library, and could play from anywhere, and teh stop action would stop it from continuing.
If that doesn't work out for you, you might search for addFrameScript in Google. With that you can add a frame script to a movieclip at runtime.