1

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

1 回答 1

4

认为你错了。

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");
}
于 2012-08-22T10:52:53.347 回答