FLASH AS3 SOUND_COMPLETE在声音开始时启动



在加载的声音上调用gotoAndStop()方法,在声音完成时激发跟踪。如有任何帮助,我们将不胜感激!

这是我的代码:

 import flash.events.Event;
import flash.media.Sound;
import flash.net.URLRequest;
var sound:Sound = new Sound();
var soundReq:URLRequest = new 
URLRequest("testmp3.mp3");
sound.load(soundReq);
sound.addEventListener(Event.COMPLETE, soundPlay);
function soundPlay(event:Event):void
{   
    var soundChannel:SoundChannel;
    soundChannel = sound.play();
    soundChannel.addEventListener(Event.SOUND_COMPLETE, soundComplete);
}
function soundComplete(event:Event):void
{
    trace("The sound has finished playing.");
    gotoAndStop(3);
}

认为你错了。

当声音文件加载完成时调用Event.COMPLETE

sound.addEventListener(Event.COMPLETE, soundPlay);

声音播放结束时调用了Event.SOUND_COMPLETE

soundChannel.addEventListener(Event.SOUND_COMPLETE, soundComplete);

请参阅以下代码。


import flash.events.Event;
import flash.media.Sound;
import flash.net.URLRequest;
var sound:Sound = new Sound();
var soundReq:URLRequest = new URLRequest("testmp3.mp3");
sound.load(soundReq);
sound.addEventListener(Event.COMPLETE, soundFileLoaded);
function soundFileLoaded(event:Event):void
{   
    trace("sound file loaded!");
    gotoAndStop(3);
    var soundChannel:SoundChannel;
    soundChannel = sound.play();
    soundChannel.addEventListener(Event.SOUND_COMPLETE, soundPlaybackEnded);
}
function soundPlaybackEnded(event:Event):void
{
    trace("sound playback ended");
}

最新更新