flash - actionscript on/off sound not working properly -


Actually I have two buttons on / off. If I click on the button more than once, the sound is off The button does not work any more, so I can not stop the sound. Can someone help?

Import flash.media.Sound; Import Flash. Media. Sound channel; Import flash.events.MouseEvent; Var mySound: Sound = New Classical_seend (); Var myChannel: SoundChannel = new soundchannel (); MyChannel.stop (); Soundon_btn.addEventListener (Mouse Event. Paste, Sound); Function soundon (Event: MouseEvent): Zero {myChannel = mySound.play (); } SoundOFF_btn.addEventListener (MouseEvent.CLICK, soundOFF); Function Voiceoff (Event: Mouse Event): Zero {myChannel.stop (); }

Why is this happening because every time you call MySound .play () A new SoundChannel object is generated to play back the sound and that function comes back from the call. So if you say it twice, the most recent voice channel object is stored in your myChannel variable; However, any first soundchannel that was generated was lost because you no longer have any reference to it and it remains on.

I will try:

import flash.media.Sound; Import Flash. Media. Sound channel; Import flash.events.MouseEvent; Var mySound: Sound = New Classical_seend (); Var myChannel: SoundChannel = new soundchannel (); MyChannel.stop (); Playing instrumental music: Boolean = false; Soundon_btn.addEventListener (Mouse Event. Paste, Sound); Function soundon (Event: MouseEvent): Zero {if playing (music!) {MyChannel = mySound.play (); MusicPlaying = True; }} SoundOFF_btn.addEventListener (MouseEvent.CLICK, soundOFF); Function Voiceoff (Event: Mouse Event): Zero {myChannel.stop (); MusicPlaying = false; }

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -