ActionScript 3: Enter frame with movieclip and play a sound just once - actionscript-3

I'm a beginner in as3 and now I'm working on a little game where you can explore different rooms with different events. Every single room is in a movieclip and now I want to play a single sound in a few rooms, but this sound should just played once in the whole game.
I've tryed to insert the sound in the main-timeline, where the certain room is in it, with a "synchronization" as "start" and no repeats, but this didn't work. So the sound is playing everytime you go in this room and that's annoying.
What can I do?

Related

ActionScript3: How to "offset" playing of sound object(with multiple objects playing at same time)

I want to make a program where you arrange sound samples. A cursor plays the sound it sweeps over and there can be many sound samples played at once. I want the user to be able to change/intterupt the playing(aka cursor progress) with a mouse click(similar to a progress bar).
I understand there are some ways of playing multiple sounds files at once, but thats not the problem. I wonder how I can play a sound sample from an offset when a click interrupt is generated.
Which AS3 class should I look at? Any other tips are appreciated.
You can use Sound.play() supplying the offset in milliseconds. You should first calculate the offset by measuring mouse position vs the progress bar, then stop the sound if it's playing, then call theSound.play(yourOffset) and you should be set.

Flash Game objects won't go away

I have a flash movie with a interactive game in the middle. The game is a simple drag and drop with a target.
Now to my problem:
When the user plays the game the drag and drop symbols stays in the target spot on the next frame to the end of the movie.
I would like them to disappear after the game is over.
I am a noobie to actionscript 3.0 - is the a code i can implement on the frames after the game to make sure that the objects wont showup.
Thanks..
Frame navigation does not affect objects that were created by code (or even objects that were created by frames but modified by code). So you need to manually remove them via removeChild().

AS3 Timer Class causing odd behaviors, black screen, not starting, etc - Full code available

So I'm trying to use the timer class in a Flash CC AS3 script.
When the SWF loads, it plays this looping video. When the user clicks the video, it goes to the next frame where there are 4 buttons which play movies, and a timer.
The timer is there so that if the user doesn't click after a few minutes (in this case a couple seconds) the SWF returns to frame 1 and plays the looping video, once again, until the user clicks.
After adding this to my COMPLETE and MOUSE_EVENT event listeners...
this(root).attractTimer.start();
when I click on the video, it removes it from stage and I'm again presented with the 4 buttons.
It's at that moment I need it to start the timer once again. If the timer runs out, it needs to gotoAndPlay(1).
I'm banging my head on the desk with this right now.
Looks like I got it working.
The buttons that fire off the video, I was using...
this(root).attractTimer.star();
I didn't need to use 'this'
instead I used
attractTimer.start();

Flash CS6 AS3 play sound on one frame only, stop when left frame

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.

Disabling Audio Flash

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.