Play a frame of a Movieclip when MOUSE_OVER - actionscript-3

I have a map with different countries. When i hover over one of the countries, i want it to play a certain frame of a movieclip. I've made a movieclip for each country, which has 2 frames. The 1. frame is just the picture of the country like it appears on the map. Frame 2 is the country with the name over it. The second frame contains a stop(); Here is my code:
rømskog.addEventListener(MouseEvent.MOUSE_OVER,mover);
halden.addEventListener(MouseEvent.MOUSE_OVER,mover);
askim.addEventListener(MouseEvent.MOUSE_OVER,mover);
rømskog.addEventListener(MouseEvent.MOUSE_OUT,outer);
halden.addEventListener(MouseEvent.MOUSE_OUT,outer);
askim.addEventListener(MouseEvent.MOUSE_OUT,outer);
function mover(e:MouseEvent):void {
gotoAndPlay(2);
}
function outer(e:MouseEvent):void {
gotoAndPlay(1);
}
I know this code is incorrect, but i'm struggling to solve the problem. My movieclip starts automatic also, as the name of the country is visiable from the start. If somebody could learn me in the easiest way possible i would be very happy!

Your current code will do gotoAndPlay on the main timeline. You need to make the country movie clips timeline go to the appropriate frame instead.
All you should need to do is modify your two function like this:
function mover(e:MouseEvent):void {
//e.currentTarget is a reference to the object that was clicked. To avoid a compiler warning, we tell flash it's a movie clip.
MovieClip(e.currentTarget).gotoAndStop(2); //if you don't want to actually play the timeline, use gotoAndStop
}
function outer(e:MouseEvent):void {
//since this code is in the main timeline, doing gotoAndPlay will apply to it, not the object clicked
//so like above, we tell the current target of the event to gotoAndPlay
MovieClip(e.currentTarget).gotoAndStop(1);
}

Related

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

Actionscript 3 how to gotoAndPlay without pressing buttons

So, I have movieclip named intro. When the intro runs out of frames, how do I tell it to gotoandPlay to maintimeline or upper movieclip without needing user to press any buttons? shouldnt be that hard, right? it was really super easy in actionscript 2, but in 3 I cant even seem to find help/tutorial to do this!
thanks!
Clarify what exactly you would like to play afterwards?
It could be as simple as adding a line of code to the last frame of the animation:
gotoAndPlay(3); // will goto a frame within the same move clip
Or to play a different movieclip:
MovieClip(this.parent as MovieClip).gotoAndPlay(3); //tell your parent to goto a specific frame
Or
MovieClip(this.parent as MovieClip).parentObject.gotoAndPlay(3); //tell one of your parents movieclips to start playing
EDIT:
A bit more out there method, placing this code on the parents timeline to check when the movieclip is finished:
intro.addEventListener(Event.ENTER_FRAME, checkFrame);
function checkFrame(e:Event):void{
if(intro.currentFrame==intro.totalFrames){
//do something
someMovieClip.gotoAndPlay(3);
}
}

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.

add movie clip on the second frame with as3

how can i add a movie clip on a specific frame using addChild called in a class with AS3 ,
my problem is how access to the specific frame
thank you
The tricky thing about this would be to handle the frame 'live cycle'...
The way I would do it, is:
Add an event listener for FRAME_CONSTRUCTED
Send your movieclip and stop it at your desired frame.
Attach your symbol on the handler of the event.
Something like this:
mc.addEventListener(Event.FRAME_CONSTRUCTED, _addChild );
mc.gotoAndStop(2);
function _addChild(e:Event):void{
mc.addChild( new Square) //Library symbol
}

stopping on the last frame (flash)

I want my movieclip to play once and stop on the last frame. I use the following code in the loop of my movieclip class. (this is as3)
if(currentFrame == 120)
stop();
120 is the last frame. It plays once. but the problem is it goes back to frame 1 again. is there a better method of stopping a movieclip on a particular frame.
If you want to do it with actionscript and not add a stop() to the last frame on the timeline manually, then you can use the undocumented addFrameScript() method.
mc.addFrameScript(mc.totalFrames - 1, function():void
{
mc.stop();
});
Can't remember the scope of the function, but you can either use mc.stop(), or just stop().
*EDIT - Added -1 to the first parameter of addFrameScript, because it is zero based (so to put a frameScript on frame 10 you would put 9).
On the timeline, you can just put a keyframe at the end, and add the stop(); method there. When it reaches that frame, the stop(); method will execute, and the clip will stop.
Assuming you are using the timeline that is, but sounds like you are.
Easiest way:
Just select the last Frame in the timeline. Open the Actions pane(F8). Ensure the frame u selected is still selected, if not then select again while the Actions pane is open.
After selecting, just add the simple stop() function in the the 'Action-Frame' pane.
//add the following line to the actions pane of the last frame.
stop();
You're done. You can optionally add a replay button if needed.
This seems more along the lines of what you're looking for:
addEventListener(Event.ENTER_FRAME, function(e:Event){
if(currentFrame == totalFrames){
stop();
removeEventListener(event.type, arguments.callee);
}
});
I added an event listener (for Actionscript 3) so on every frame this function will fire and check what frame it is on. If it's the last frame it will stop. Based on your example I'm presuming you have a class that's extending MovieClip.