2012-09-05 38 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