2011-09-14 32 views
3

我有这个代码在第二帧播放歌曲,它工作正常。我的音乐库中的声音类别是“MySound”。如何阻止在as3中播放声音?

var snd:MySound = new MySound 
snd.play(); 

现在我需要歌曲停止播放后一帧。

+0

snd.stop()????? –

+0

@The_asMan [声音](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Sound.html)不执行'stop()'。 –

回答

11

你必须使用这个SoundChannel类:

var mySound:Sound = new Sound(); 
var myChannel:SoundChannel = new SoundChannel(); 
mySound.load(new URLRequest("myFavSong.mp3")); 
myChannel = mySound.play(); 

// ... 

myChannel.stop(); 

参考:http://www.republicofcode.com/tutorials/flash/as3sound/(第4章 - 停止一个声音

1
//*This code for playing the sound after import to the library* 
var mySound:Sound = new MenuMusic(); 
var myChannel:SoundChannel = new SoundChannel(); 
myChannel = mySound.play(); 

//*This code for the nextframe button* 
btn_easy.addEventListener(MouseEvent.MOUSE_DOWN, btneasy); 
function btneasy(event:MouseEvent):void 
{ 
    gotoAndPlay(62); 
    myChannel.stop(); 
} 

提醒

你不必拖g将声音文件添加到时间线中。只需将 代码粘贴到按钮的指定操作脚本。

var mySound:Sound = new MenuMusic(); 

'MenuMusic' 可以改变你想要什么。只需右键单击库中的声音 文件,然后选择“属性”。点击动作脚本选项卡和 检查“为ActionScript导出”和你现在可以在 “类”输入框更名..

它的工作这么没什么问题:)

希望它解决了这个问题! :D