Restart a Moviclip from the stage after stoping it - actionscript-3

On my main stage I have a few Movieclips, which all start at a different frame position, and also end at a different frame position. So I put a keyframe to the Movieclips, after the animation is finished, and put a stop() on it. After all animations are finished, the main stage also gets a stop() and a replay button appears. Now if I click on the replay button, every movieclip should start again - of course. I have tried gotoAndPlay(1) but the moviclips are not starting with that, only the mainstage (of course, i know that moviclips have their own timeline.. ) So how can I restart every animation with just the one click on the replay button?

In Flash, movieclips are running seperate from the Main Stage.
In order to run all the movieclips, you should restart all the movieclips:
Let's say the names of the movieclips are MovieClip1, MovieClip2 and MovieClip3.
on(release){
gotoAndPlay(1);
MovieClip1.gotoAndPlay(1);
MovieClip2.gotoAndPlay(1);
MovieClip3.gotoAndPlay(1);
}
Hope this will work.

Related

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?
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
}
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.

stop object timeline from looping

I have a movie with several movieClips. One of the movieClips has a timeline with a motion tween. I created an instance of this movieClip:
var board:Board = new Board();
and used board.gotoAndStop(1); to keep the movieClip from playing at the beginning of the movie.
An eventListener checks to see when board collides with something; when it does, a function is invoked that uses board.gotoAndPlay(2) to get the board's timeline going.
I want the playhead on that timeline to stop at the end of the action, rather than looping. I tried to put a stop() on the last frame of that timeline, but Flash tells me I can't put an action on an object.
Can you help me solve this?
Thank you very, very much!
If memory serves, you need to make sure you have clicked in the frame in the timeline, so the frame is selected, and not an object on the stage. Then enter your actionscript.
Make sure you select a single frame where you would like to add actions then add your code
stop();
To make the timeline stop looping

AS3 move object back to first frame from current position in tween

I have an object with an instance name of arrow that moves across the page on a motion tweet when a button is pressed. When the button is released I want the arrow to move back to the start of the tween frame by frame.
I have set up an if statement when the button is released and its current frame is more than 1 to go back 1 frame.
So far the arrow is ignoring the if and stopping due to the else statement.
btn.addEventListener(MouseEvent.MOUSE_OUT, out);
function out(e:MouseEvent){
if(arrow.currentFrame > 1){
arrow.gotoAndStop(arrow.currentFrame - 1);
}else{
stop();
}
}
You would probably be better off making another tween on the timeline that goes backwards then just playing that. Another option is to use a third party tweening library like tweenlite since in there you can easily setup animations to run forward or in reverse.
Are you sure arrow is the name of the movie clip that you want to run the frames backwards on, or is that the instance of the element that changes over some other movie-clips timeline?

Removing Sounds Invoked within a MovieClip from main Time Line

I currently have a difficulty removing specific sounds from playing when I advance through the timeline on a particular project.
The user chooses a particular item on the timeline which will display a specific movieclip and will then play a specific sound on MOUSE_DOWN.
The eventListener for MOUSE_DOWN which exists as follows:
stage.addEventListener(MouseEvent.MOUSE_DOWN, sprayWater);
stage.addEventListener(MouseEvent.MOUSE_UP, stopWater);
function sprayWater(event:MouseEvent):void
{
waterarm.gotoAndStop(2);
trace("SPRAYING WATER");
}
function stopWater(event:MouseEvent):void
{
waterarm.water.gotoAndPlay("waterE");
}
on frame 2 of 'waterarm' is a movieclip called 'water' that contains an animation of water and the following code to start the water sound:
var sfxWater:sfxwater;
var waterChannel:SoundChannel;
sfxWater = new sfxwater;
waterChannel = sfxWater.play();
on the frame "waterE" an animation of the water disappearing exists and the code sfxWater.stop();.
When the user progresses beyond this frame on the root timeline, the sound effect of water still remains on MOUSE_DOWN despite the movieclip no longer existing on the timeline at that point.
The ideal outcome will be the individual sound playing on MOUSE_DOWN and stopping on MOUSE_UP only when this movieclip is visible on the main timeline. If anybody can provide any assistance in being able to prevent the sound from playing and removing this event listener (through code on the main timeline if possible) it would be greatly appreciated.
Regards,
Darren
If stopping the sound is all that you want why not use SoundMixer.stopAll().
You can use it in the MOUSE_UP event after checking if the said movieclip's visible property.

RemoveChild frame animated MovieClip, will stop frame running?

If I removeChild frame animated Movieclip, will it automatically stop running the frames inside it? Actually without calling mc.stop();
I believe it will continue to play, reason being your movie clip is still a flash entity not on stage( so not for you), but for flash (yes he can see all).
So once you create a new movieclip, play it... you can add or remove the running clip without stopping. Basically changing parent doesn't change the state of the mc.
No. The timeline will still play, and all the framescripts you might have in there will still be called.
Beware of the timeline devils :)