0

当我单击按钮时,我退出了 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");
}
4

1 回答 1

0

有一些奇怪button1的类你没有提供任何细节,你试图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 开发人员指南

于 2014-02-02T05:58:26.527 回答