2012-09-05 75 views
0

我是ActionScript 3新手,並使用Flash CS6。爲音樂切換mc播放/暫停按鈕不起作用。在庫中鏈接導出(AS)的音樂

- 我試圖播放/暫停countrymeadow命名

-countrymeadow.mp3是與出口的圖書館動作(countrymeadow)20分鐘的MP3。

  • playpause mc按鈕在按鈕內的第1幀(播放)和第10幀(暫停)停止。

  • AS3低於它,但它不工作,因爲mc playpause按鈕在測試時沒有聲音播放時不斷切換'play'和'pause'。

任何幫助表示讚賞,並提前非常感謝。

//set appearance of button, mode to true 
playpause_mc.gotoAndStop("play"); 
playpause_mc.buttonMode = true; 

//sound is stopped after loaded 
var isPaused:Boolean = true; 

//saves current position of sound 
var currPos:int = 0.00; 

var theSound:countrymeadow = new countrymeadow(); 
snd.play(); 

var soundCnl:SoundChannel = new SoundChannel(); 

//Listener updates after sound loads, and stops   soundtheSound.addEventListener(Event.COMPLETE, onComplete, false, 0, true); 
function onComplete(evt:Event):void { 
    //Stop loaded sound 
    soundCnl.stop(); 
} 


// movie clip button control 
playpause_mc.addEventListener(MouseEvent.CLICK, clickHandler); 
function clickHandler(event:MouseEvent):void { 

    if(isPaused){ 
     //change state to playing, and play sound from position 
     isPaused = false; 
     soundCnl = theSound.play(currPos); 

     //reverse the appearance of the button 
     playpause_mc.gotoAndStop("pause") 

     //if sound completes while playing, run function 
     soundCnl.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler); 

    }else{ 
     //it's playing, so save position and pause sound 
     currPos = soundCnl.position; 
     isPaused = true; 
     soundCnl.stop(); 

     //change the appearance of the buttons 
     playpause_mc.gotoAndStop("play") 
    } 
} 

回答

0

SoundChannel position是一個Number變量。即範圍0到1,但您設置了int變量。 int不是浮點類型。因爲您已明確聲明爲int類型。即使當你變成浮點初始化,轉換爲int類型。

enter image description here

你應該跟隨這個。你的clickHandler函數有些更正了。

var currPos:Number = 0.0; 

soundCnl.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler); 
function clickHandler(event:MouseEvent):void { 

    if(isPaused){ 
     //change state to playing, and play sound from position 
     isPaused = false; 
     soundCnl.play(currPos); 

     //reverse the appearance of the button 
     playpause_mc.gotoAndStop("pause") 

    }else{ 
     //it's playing, so save position and pause sound 
     currPos = soundCnl.position; 
     isPaused = true; 
     soundCnl.stop(); 

     //change the appearance of the buttons 
     playpause_mc.gotoAndStop("play") 
    } 
} 

測試代碼:

var n:int = 0.0; 

n = 0.5; 

trace("n: " + n); //you may expected 0.5, but return 0. 
+0

還是要謝謝你,但我不明白我應該更換。我從自己的代碼中得到了什麼,我將取代什麼?你能否給出一個更好更詳細的例子?回覆:我的代碼包括您的更正... – user1632767