作者sxazdc (沒啥好說的!)
看板Flash
標題[問題] 用Flash製作pause/play button的AS
時間Tue Nov 15 13:11:55 2011
在練習製作單一play/pause按鈕的flash,
但不知道哪一部分寫錯了,
導致無法按pause??
以下是我的AS:
//create a new sound and new channel
var sound:Sound=new Sound();
var ch:SoundChannel=new SoundChannel();
//load the mp3 and play it
sound.load(new URLRequest("atmosphere.mp3"));
ch=sound.play();
//create variable to store position of pause
var pauseSpot:Number=0;
//add button functionality
function pauseSound(MouseEvent):void{
pauseSpot=ch.position;
ch.stop();
btn.mouseEnabled=true;
}
btn.addEventListener("click", pauseSound);
function playSound(MouseEvent):void{
ch=sound.play(pauseSpot);
btn.mouseEnabled=false;
}
btn.addEventListener("click", playSound);
謝謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 75.13.92.16
推 cjcat2266:兩個listener加到同一個btn上啊 11/15 13:38
→ cjcat2266:按下去當然就會先暫停然後馬上撥放 11/15 13:39
→ cjcat2266:解法之一是用一個Boolean flag和單一listener 11/15 13:39
→ cjcat2266:在這個listener裡面判斷flag狀態來做處理 11/15 13:39
→ puivujh:在pauseSound裡移除puause的listener,然後加上play的 11/15 23:21
→ puivujh:然後playSound則是移除play的listener、加入pause的, 11/15 23:23
→ puivujh:最後就看你的btn要預設成play還是pause就選一個加上去 11/15 23:24
→ sxazdc:謝謝~不過請問要怎麼預設? 11/16 12:01
→ puivujh:唔,就是直接pause 跟 play挑一個適合的add上去.... 11/16 15:29