actionscript-3 - 在关闭as3之前播放声音

标签 actionscript-3 flash audio fscommand

当我单击按钮时,我退出了 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/

相关文章:

audio - Beaglebone Black Custom Audio Cape DMA/IRQ麻烦

audio - FFMPEG 复用两个视频中的视频和音频

flash - 访问 Flash CS3 AS3 项目中的 Web 服务

Flash AS3 EventDispatcher-以任何方式获取已注册监听器的列表?

apache-flex - 需要对 MVC 的模型方面进行一些说明

flash as3 使用 curveTo 绘制一个 donut 楔形(具有内外半径的圆弧)

actionscript-3 - 用于处理 Apple HTTP Live Streaming 的 AS3 库

flash - 我试图让 "robot"似乎在我的网站上说话。嘴巴必须与声音同步,我在想....闪光?

c# - 如何在桌面 WPF 应用程序中播放 OGG 声音文件?

flash - Actionscript 对象的属性数