Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2><strong>code clean</strong></h2> <ol> <li><p>Push the sound to array previously, and new a <code>Dictionary</code>, and new a <code>Vector</code> for play list.</p> <pre><code>private var soundArray:Array = [ null, sound1, sound2, sound3, sound4, sound5, sound6, sound7, sound8, sound9, sound10 ]; private var soundDic:Dictionary = new Dictionary; private var playList:Vector.&lt;Sound&gt; = new Vector.&lt;Sound&gt;; private static const MAX_BTN_NUM:uint = 10; </code></pre></li> <li><p>Use a <code>for loop</code> to init.</p> <pre><code> for(var i:int = 1; i &lt;= MAX_BTN_NUM; i++) { master["btn"+i].btnText.text = i+""; master["btn"+i].addEventListener(MouseEvent.CLICK, btnClicked); soundDic["btn"+i] = soundArray[i]; } </code></pre></li> <li><p>Use <code>key-value</code> for btnClicked.</p> <pre><code>private function btnClicked(event:MouseEvent):void { playList.push( soundDic[event.currentTarget.name] ); } </code></pre></li> </ol> <h2><strong>play one by one</strong></h2> <ol> <li><p>init a <code>int</code> for <code>clearInterval</code></p> <pre><code>private var tidx:int = -1; </code></pre></li> <li><p>the play one by one logic</p> <pre><code>private function playOneByOne( sounds:Vector.&lt;Sound&gt;, idx:uint = 0 ):void{ clearInterval( tidx ); if( idx &lt; sounds.length ){ (sounds[idx] as Sound).play(); tidx = setInterval( playOneByOne, (sounds[idx] as Sound).length, sounds, idx + 1 ); } } </code></pre></li> </ol> <h2><strong>handle play and clear</strong></h2> <pre><code> private function clearHandler( event:MouseEvent ):void { playList.splice( 0, playList.length ); } private function playHandler( event:MouseEvent ):void{ playOneByOne( playList ); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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