-
External Sound Play Button
This is code loads the music internally:
var url:String = "C:/Users/George/Desktop/erevemusic.mp3";
var urlRequest:URLRequest = new URLRequest(url);
var sound:Sound = new Sound();
sound.load(urlRequest);
sound.play();
And this makes it so when you click the button it stops the music:
ToggleButton.addEventListener(MouseEvent.CLICK, beQuiet);
function beQuiet(e:MouseEvent):void
{
SoundMixer.stopAll();
}
What code do I need to click on ToggleButton button for the music to play again?
-
Senior Member
I am not going to test this example, let me know if it works and if there are any errors;
Actionscript Code:
var url:String = "C:/Users/George/Desktop/erevemusic.mp3"; var urlRequest:URLRequest = new URLRequest(url); var sound:Sound = new Sound(); sound.load(urlRequest); sound.play(); var isPlaying:Boolean = true;
//And this makes it so when you click the button it stops the music:
ToggleButton.addEventListener(MouseEvent.CLICK, toggleSound);
function toggleSound(e:MouseEvent):void { if(isPlaying) //If the sound is playing SoundMixer.stopAll();//stop all sounds else//otherwise sound.play();//play the sound isPlaying=!isPlaying;//whatever it was last set to, you are now the opposite. }
ps. there might be a isPlaying variable on the sound object, I cant remember right off the top of my head. You can use that in place of keeping track of the state yourself (if it exists that is).
Let me know if this works out for you, or if it doesn't compile. Good Luck
~!GK!>'.'<
Last edited by guardiankitty; 01-04-2012 at 08:48 PM.
-
Thank you sooooooo much guardiankitty! It works perfectly! I've been trying to figure this about for a good amount of days.
-
Actually now that it works I do have 1 more question:
Is there any way to make the music loop? (if it's not already)
-
Flash Genie
Actionscript Code:
public function playMusic():void { musicChannel = music.play(); musicChannel.addEventListener(Event.SOUND_COMPLETE, loopMusic); }
public function loopMusic(e:Event):void { if (musicChannel != null) { musicChannel.removeEventListener(Event.SOUND_COMPLETE, loopBackgroundMusic); playMusic(); } }
http://doogog.com/music-looping-in-as3.html
or veiw this http://board.flashkit.com/board/showthread.php?t=769120
Actionscript Code:
import flash.media.Sound; import flash.media.SoundChannel;
status.text = "Chimes Off";
playButton.addEventListener(MouseEvent.MOUSE_DOWN, playChimes);
var chimesSound:SoundChannel;
function playChimes(e:MouseEvent):void{ if(status.text == "Chimes Off"){ var chimes:Chimes = new Chimes(); chimesSound = chimes.play(0,int.MAX_VALUE); status.text = "Chimes On"; }else{ chimesSound.stop(); status.text = "Chimes Off"; } }
Charag - 3D, Flash Games, Animations,
Website Development & More...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|