I'm working on an animation that requires "Next" buttons at the end of each scene.
The movie resumes after the button is pressed. During the pause, I'd like the background music to pause as well. I've tried several solutions but none seemed to work.
I am using Flash Professional CS 5.5
Assume you are using "timeline" instead pure AS3.
At the start of whole project(MySound is your specified sound):
var position:Number = 0;
var mySound:Sound = new MySound();
var sc:SoundChannel;
When you start to play every scene(or press on resume button):
sc = mySound.play(position);
End of scene:
position = sc.position;
sc.stop();
Related
with University done I've finally had time to go back to practicing my Flash work, and I need some help with getting sound to loop and change depending on what part of the animation is playing.
This is also partly a follow up question to an older one I asked, so look here to get more detail as to where I'm coming from if you don't understand! (I've solved that issue, the current one relates to following up on it!)
Flash AS3 | Finishing current animation set before code is executed
The situation is basic: I have two different scenes, one of a man walking and one of a man running. It loops seamlessly of the man walking until you hit a button, where it finishes the animation then starts looping the run animation. Likewise, hitting the button again, finishes the loop before going back to the looping walk animation. The code for the button is below.
import flash.events.MouseEvent;
Next2.addEventListener(MouseEvent.CLICK, Change_2);
function Change_2(event: MouseEvent): void
{
addEventListener(Event.ENTER_FRAME, enterFrame);
function enterFrame(e:Event):void {
if (currentFrame == 30) {
gotoAndPlay(31);
removeEventListener(Event.ENTER_FRAME, enterFrame);
}
}
}
My issue is trying to get a footstep sound to match up with these animations. So while the man is walking, the 'walking footsteps' sound clip will play and loop alongside the animation, and when the button is pushed and the animation moves into the running animation, the 'running footsteps'' sound will play.
Any help on this would be much appreciated. I'm terrible when it comes to anything audio/code based.
Well u can check about soundChannel. soundChannel can stop() and play() ur audio.
So import ur external sound or use internal one. ur code probably seems like this.
var mySound:Sound = new Sound(new URLRequest("YourSoundPath"));
var sc:SoundChannel = new SoundChannel();
//when u wanna play
sc = mySound.play();
//when u wanna stop
sc = mySound.stop();
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/SoundChannel.html
also look this link for more info
If you want to really MATCH the footsteps to the animation (for example, the step sound should play when the player have put his feet down) the only sure way to do that is to place the sound on a different layer where your animation is and set the sound to play as "stream" (if i remember correctly).
Otherwise the animation might be out of sync because of different computer capabilities, current computer or graphics card load etc.
When the sound is set to play as "stream" the flash player is orienting on the sound and drop frames if the graphics are slow to keep the sound and animation in sync
I'm a beginner in AS3 and Flash CS6.
I tried to search for a solution, but couldn't find anything that would've worked for me.
I have a small game where you must avoid particles coming at you, and as usual, when you hit one, you goto The End scene.
The problem is that when you replay the game from The End screen, the music won't stop, but start again on top of the other one.
I've included my sound from Library -> mysound.mp3 -> Properties -> ActionScript3 -> Export for ActionScript & Export in Frame 1.
Is there a way I could stop the sound from ActionScript?
Is there a way I could stop the sound from ActionScript?
Don't place Sound object on the timeline, control it yourself, It's pretty easy and straightforward.
//Start background music somewhere
var soundFromLibrary: SomeSound = new SomeSound();
var myBackgroundMusic: SoundChannel = soundFromLibrary.play(0, int.MAX_VALUE);
//Now you have reference on background music, stop it
myBackgroundMusic.stop();
If you have the music set on a specific keyframe, then in the properties panel, set it to
Sync: Start
Repeat: 1
And on the frame where you want to stop the music:
Sync: Stop
Repeat: 1
I have an As3 simple game with navigation buttons. It starts off with short intro with sound. When the game loads and the player dies it goes to retry screen with button which when is pressed goes back to the game. The problem is that when that happens flash plays the music from the short intro when returning to the game. How Do I stop this from happening. Currently I have no code for the sound. I just added the music directly to the frame with the intro and that's it. So what code do I write for the sound to execute only once?
I googled 'as3 load sound' and this popped up
http://www.republicofcode.com/tutorials/flash/as3sound/
This will show you how to do it if the sound is in your library or if it's external.
With your audio file in the library right click on it and in properties>actionscript check export for actionscript and give it a class name yourAudioFileName
...then the code to start and stop will be
var mySound:Sound = new yourAudioFileName();
var myChannel:SoundChannel = new SoundChannel();
// start it with
myChannel = mySound.play();
// stop it with
myChannel.stop();
I am using sound files from the library, not URLs.
I am making a soundboard and have a button that plays background music. The reason I have a button instead of automatically playing on load is that there are a few different background musics to choose from, each with their own button.
I also have several other buttons that play sounds. I want the background music volume to lower to something like 0.3 while other sounds are playing. I believe I need to create a variable like soundCount that goes up when a sound plays, and decreases when the sound finishes playing (so that if there are multiple sounds playing at once, the background music won't go back to normal until the count is at 0).
What's the best way to set this up? I made the soundCount variable but I'm having trouble creating an event listener for when sound effect finishes playing.
To change the volume of a sound in AS3, you need to use the SoundChannel and SoundTransform classes:
var backgroundMusic:Sound = // Assuming you've loaded a sound
var myChannel:SoundChannel = new SoundChannel();
myChannel = backgroundMusic.play();
var myTransform = new SoundTransform();
myChannel.soundTransform = myTransform;
Keep track of total sounds in the background by incrementing your count during calls to play and decrementing during SOUND_COMPLETE events. Add event listeners to other sounds' channels so they can modify background's volume:
var totalCurrentSounds:int = 0;
otherSoundChannel.addEventListener(Event.SOUND_COMPLETE, otherSoundComplete);
// Make sure this is on a SoundChannel, not the Sound itself.
Finally, modify the SoundTransform's volume member when the count is 0:
function otherSoundComplete(e:Event):void {
totalCurrentSounds--;
if (totalCurrentSounds <= 0)
myTransform.volume = 0.5;
}
I have an AS3 project which when the user clicks a button the browser is set to fullscreen. This works great, however the playback sticks after the navigation is sent to the next frame. The MC on frame two plays, but then the playback head doesn't move forward to frame 3. Once escape is pressed, the fullscreen is broken and then the movie skips to where it would have been normally if it hadn't have gotten stuck on frame two (as if the project was running in the background). This problem also occurs without the fullscreen AS3, just using the controls for a projector to go to fullscreen, and it also occurs if the .swf file plays back directly in a flashplayer without the browser. I don't understand, without fullscreen, everything plays back perfectly....
Here's the code on frame 1:
fullscreenMe.addEventListener(MouseEvent.CLICK, fullScreenIt);
function fullScreenIt(event:MouseEvent):void {
MovieClip(root).gotoAndPlay('two');
stage.displayState=StageDisplayState.FULL_SCREEN;}
And here's the code on frame 2:
var titlesTimer = new Timer(11000,1);
titlesTimer.addEventListener(TimerEvent.TIMER_COMPLETE, titlesTimerFinished);
titlesTimer.start();
function titlesTimerFinished(e:TimerEvent):void {
//trace("timer is finished");
MovieClip(root).nextFrame();
}
var creditsSound:credits = new credits();
var creditsChannel:SoundChannel = new SoundChannel();
creditsChannel = creditsSound.play();
And here's the code on frame 3:
import fl.transitions.Tween;
import fl.transitions.easing.*;
function alphaTween(mc,b,f,d) {
var Alpha:Tween = new Tween(mc, "alpha", Regular.easeIn, b, f, d, true);
}
alphaTween(moon1,0,1,7);
var moonTimer = new Timer(1000,7);
moonTimer.addEventListener(TimerEvent.TIMER_COMPLETE, moonTimerFinished);
moonTimer.start();
function moonTimerFinished(e:TimerEvent):void {
//trace("timer is finished");
MovieClip(root).nextFrame();
}
Hmm from the information given I am not sure if the Playhead is in play mode or stop mode in a frame.
Before we can solve it
Is there a this.stop(); command added before any code is written in the frame. This ensures the Playhead is not in playing mode and stops in the present frame. If you want it playing, then no issues. But looking at the timers, I assume you must have added the stop() command.
Documentation for MovieClip for nextFrame says it sends the playhead to the next frame and stops it. This happens after all remaining actions in the frame have finished executing. So is this intended?