Ryan
Ryan

Reputation: 709

How to make a movieclip play on a specific frame in AS3?

I'm incredibly rusty at Flash having not touched it in probably 10 years and can't seem to figure this out, or find it online:

I have a MovieClip with two layers, each having a Shape Tween. Basically its a Door that opens and closes.

I dropped it onto the main timeline but now I need it to start and stop. This is where I'm now struggling since the last time I used Flash actions could go on specific keyframes.

I made a new layer called actions just to keep things organized and currently have:

barrier1.stop();

I just want something that lets me state a frame, say 57 to have barrier1 start playing on. Tried using play(); and Event.ENTER_FRAME with no luck. How would I set this up?

Upvotes: 1

Views: 2291

Answers (2)

Özgür Ersil
Özgür Ersil

Reputation: 7013

Well it is easy with the instance name of your movieClip

barrier1.stop(); // Stops the movieClip
barrier1.play(); // Resumes 
barrier1.gotoAndStop(12) // Goes to 12nd frame and stop
barrier1.gotoAndPlay(12) // Goes to 12nd frame and play
barrier1.currentFrame // returns barrier currentframe

For capturing frame from scene level:

this.addEventListener(Event.ENTER_FRAME,onLoop);
function onLoop(event:Event){
  if(barrier1.currentFrame == 57){
     trace("BARRIER is in 57. frame");
  }
}

Inside on the animation clip on the first frame

var root:MovieClip = this.parent as MovieClip
root.makeStartSceneAnimation()

**in timeline scene level [root]**

function makeStartSceneAnimation(){
    /// barrier started to play

}

Upvotes: 1

GeorgeCross
GeorgeCross

Reputation: 359

If you are using timeline, you can add Key frame on the desired frame, and then add stop(); as Action in the action layer. But bear in mind that if you do this in the main timeline - it will stop everything. If you want to stop that MovieClip, then you have to do this inside MoviceClip's timeline.

Upvotes: 0

Related Questions