There's an animation (MovieClip) in my scene. There's a sound accompanying animation. I inserted it into the first frame of the animation.
I want this animation to be inactive initially. I plan to activate it when some button is pressed.
I don't know how to set it "inactive" from within Adobe Flash workspace, so I just put in constructor of my scene:
MovieClip(getChildByName("MyAnim")).stop();
By it does not prevent that sound to start playing when my scene appears!
How do I manage it?
In my experience, it usually isn't a good idea to insert sounds directly onto the timeline in flash. I strongly advice to import the .mp3 into the Flash program and play it by code using the AS3 Sound class.
EDIT: This way, the sound won't play until you use the Sound Class .play() method, which you could do at the beginning of your animation on the timeline OR from the button that activates it.
Here is a nice Republic of Code tutorial giving you a step by step on how to play a Sound file using the AS3 Sound Class.
Put the sound on frame two in your movieclip. Then go to that frame when you click the button.
private function onButtonClick(event : MouseEvent) : void
{
mySoundClip.gotoAndStop(2);
}
Related
I have 3 mc_MovieClips.
Each clip is on a different frame of the same layer in the main scene.
I do not want to use a button to control the play.
On startup, I want Clip1(On Frame1) to play, and when that is finished, Clip2(On Frame2) will play and so on.
I am a very beginner and using Flash Professional CC and actionscript 3.0. The only help I can seem to find calls for global variables, which no longer seem to exist.
I can provide more information if needed, I am just a really big beginner.
Try placing a parent.nextFrame(); on the last frame of each MovieClip and a stop(); on each frame of the parent clip (actual frames of your main scene).
I have a scene which has a frame for each screen that I want to display to the user. Each frame has a movieclip which contains all the elements for that screen. The first frame's movieclip has frame1 set up with a sound layer. Problem is, when I navigate to a different screen, the music continues to play.
How can I get it to only play whilst the movieclip is visible on the screen? I tried to have an "ENTER_FRAME" listener of the other screens and used SoundMixer.stopAll(); which stopped the music. The only problem is, when I reentered the frame with music, it wouldn't start.
I am using the Sync Setting: Stream.
Flash IDE has a number of different kinds of sounds, the most important being Stream and Event.
It sounds like you're using an Event type sound because the sound continues to play even when you are off the frame. There is no way to stop an Event sound except with SoundMixer.stopAll().
You need to set the sound type to Stream in Flash IDE. Then, place it in a MovieClip and make sure that there enough frames in the clip to last the whole duration of the sound. Then, place that MovieClip in your main scene and it should now stop when you move to a different frame.
When creating an AS3 project and adding audio what I usually do is drag the audio I want to use (for a game menu for example) and when I want to stop the audio I enter
SoundMixer.stopAll();
I do this because if I say go to the about game frame in this menu then I will have the audio, but if I come back to the main frame where I originally had the music it sorta doubles in and the two different timings of the music are playing at the same time.How do I stop this without having to disable the audio when I change frame?
In these cases, it is easier to start and stop the sound directly via code. First, right click the sound clip in your Library panel, and select Properties. In the ActionScript tab, check "Export for ActionScript", and give it a class name of, say, Music. Then, to play and stop this clip, you can use this code:
import flash.media.Sound;
// create the music Sound object so that we can start playing
var music : Sound = new Music();
var musicChannel : SoundChannel;
// play the music
// the play() method returns a SoundChannel,
// which you can later use to stop the music
// notice that we first check to make sure musicChannel is null
// if it isn't null, music is already playing, so don't play it twice
if(musicChannel != null) musicChannel = music.play();
// when you switch screens, stop the music
// clear out the channel, so that we know that it is safe to start the music again
musicChannel.stop();
musicChannel = null;
Alternatively, if you play music and sounds by placing them on the timeline, you can stop it by using the Sync setting of the frame. On the timeline, create a keyframe where you switch screens and want the music to stop playing. Select that frame, and drag the sound clip you want to stop onto that frame. In the Properties panel, change the Sync option to Stop. This will cause only the selected sound to stop playing.
Yet another method is to create an empty MovieClip with the sound placed inside of it. Change the Sync setting to Stream, and pad the clip out with empty frames so that it will play the entire clip. Then, if you place this clip on your main menu screen, then it will only play during the main menu. Stream sounds only play the sound for as long as the MovieClip exists and is playing. Compare this to normal Event sounds, which will play the entire sound regardless.
The latter methods are more old-school and movie-centric. If you are programming a game, it would be more appropriate to use the former method to give you more control of the audio in code.
I made a small game in Actionscript 3.0 and flash.
When the player wins the game or is 'game over' the player should have a option to replay the game.
So my question is: Is there a way to replay the whole movie with Actionscript? I know, i could reset the timeline back to 0, and re-instantiate all the classes, movieclips, var's ect... but i was wondering if anyone knows a easier solution.
Simply do this:
import flash.net.*;
//...
navigateToURL(new URLRequest(stage.loaderInfo.url), "_level0");
You can remove the swfObject and add it again. Look here. This is the swfObject reference.
Reload the page, where you've embedded the swf into, may be the easiest way.
The programmers way would be to encapsulate your whole application into a single class (extending Sprite or MovieClip) which will be attached to the stage. For restarting the game you could simply remove that instance from the stage and add a newly created onto the stage.
Or make a loader swf, that loads your game. Then if the game should be restarted, discard (unload) the instance and load it again.
Its hard to tell you what you can do, if we don't know, how your project is structured.
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 :)