在关闭AS3之前播放声音



当我单击按钮时,我会从闪存应用程序中获得。我想要的是,当我单击他的声音发出声音并完成后,然后退出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");
}

有一些WIERD button1类,您尚未提供任何详细信息,并且您尝试在其中调用play()方法。也许您确实已经实现了它,此方法将play命令委托给适当的声音对象,但我会假设您还没有。您的代码应该看起来像:

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");
}

我建议您阅读以下文章,有关播放声音,如果您遇到其他任何问题:播放声音。ActionScript 3.0开发人员指南

最新更新