Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To answer your specific question, you can use the enabled property on the button. Inside your playSound() method, do this::</p> <pre><code>public function playSound():void { sndChannel=snd.play(); playButton.enabled = false; } </code></pre> <p>Be sure to add an Id to your playButton:</p> <pre><code>&lt;s:Button id="playButton" label="play" click="playSound();"/&gt; </code></pre> <p>You may want to consider just adding a check inside your playSound() method to not play the sound if it is already playing. To do this, first create a variable:</p> <pre><code>protected var isPlaying : Boolean = false; </code></pre> <p>Then tweak the playButton() method like this:</p> <pre><code>public function playSound():void { if(!isPlaying){ sndChannel=snd.play(); isPlaying = true; } } </code></pre> <p>In either of the above situations, you'll probably want to add an event listener to the <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Sound.html#event%3acomplete" rel="nofollow">complete</a> event in order to re-enable to button or change the isPlaying flag. The approach would be something like this:</p> <pre><code>public function playSound():void { if(!isPlaying){ snd.addEventListener(Event.COMPLETE,onSoundComplete); sndChannel=snd.play(); isPlaying = true; } } public function onSoundComplete(event:Event):void{ isPlaying = false; playButton.enabled = true; snd.removeEventListener(Event.COMPLETE,onSoundComplete); } </code></pre> <p>You can also call the onSoundComplete method from your stop sound method:</p> <pre><code> public function stopSound():void { sndChannel.stop(); onSoundComplete(new Event()); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload