从sound.length位置开始播放时,为什么没有触发SOUND_COMPLETE事件?

时间:2014-05-31 17:30:44

标签: actionscript-3

我意识到从sound.length位置开始播放时不会触发Event.SOUND_COMPLETE事件(它可以在实现scrubber时使用:用户可以寻求100%并开始播放)。

这个错误吗?解决它的常见做法是什么?

重现此行为的示例代码:

import flash.media.Sound;
import flash.media.SoundChannel;

private var sound:Sound;
private var channel:SoundChannel;

public function test():void {
    sound = new Sound();
    sound.addEventListener(Event.COMPLETE, testLoadingCompleteHandler);
    sound.load(new URLRequest("/song.mp3"));
}

private function testLoadingCompleteHandler(event:Event):void {
    // SOUND_COMPLETE doesn't fire when we start playing from sound.length position
    trace("# testSoundLoadingCompleteHandler()");
    channel = sound.play(sound.length);

    channel.addEventListener(Event.SOUND_COMPLETE, testPlaybackCompleteHandler);
}

private function testPlaybackCompleteHandler(event:Event):void {
    // This message won't be printed because SOUND_COMPLETE event isn't fired
    trace("# testPlaybackCompleteHandler()");
}

1 个答案:

答案 0 :(得分:0)

也许sound.play(sound.length)不会开始播放,甚至会返回错误。我想这可能是因为sound.length比允许值大。就像在数组中一样,你不能使用array [array.length],因为它将超出范围。

我推荐triyng array.length-1