当我单击按钮时,我退出了 Flash 应用程序。我想要的是当我点击他的声音响起并完成后,然后退出flash应用程序。
这是我的代码
Exit.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_4);
function fl_MouseClickHandler_4(event:MouseEvent):void
{
var button:button1 = new button1();
var myChannel:SoundChannel = button.play();
if (myChannel !=null)
{
fscommand("quit");
}
}
我应该怎么做这些代码
是的,我已经明白了
这是我的有效代码
import flash.events.MouseEvent;
import flash.media.Sound;
function fl_MouseClickHandler_4(event:MouseEvent):void
{
var button:button2 = new button2();
var myChannel1:SoundChannel = button.play();
myChannel1.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
}
function onPlaybackComplete(event:Event)
{
fscommand("quit");
}
最佳答案
有一些奇怪的button1
您没有提供任何详细信息的类,并且您试图调用 play()
方法就可以了。也许您确实已经实现了它,并且此方法将播放命令委托(delegate)给适当的声音对象,但我假设您没有。
您的代码应如下所示:
function fl_MouseClickHandler_4(event:MouseEvent):void
{
var snd:Sound = new Sound(new URLRequest("yourSound.mp3"));
var channel:SoundChannel = snd.play();
channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
}
function onPlaybackComplete(event:Event)
{
fscommand("quit");
}
如果您遇到任何其他问题,我建议您阅读以下有关播放声音的文章:
Playing sounds. ActionScript 3.0 Developer's Guide
关于actionscript-3 - 在关闭as3之前播放声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21507420/