AS3驻波图书馆完成事件未触发

时间:2011-11-06 00:09:17

标签: actionscript-3

我正在使用AS3 Library StandingWave并尝试为音频播放器启动“COMPLETE”事件。我有下面的代码,事件似乎永远不会触发。我没有得到跟踪而没有重新启用按钮。

var player:AudioPlayer = new AudioPlayer();
play_btn.addEventListener(MouseEvent.CLICK,playSinewave);

function playSinewave(e:Event):void{
var sinewave:IAudioSource = new SineSource(new AudioDescriptor(),5,440,0.2);
play_btn.enabled = false;
player.addEventListener(Event.COMPLETE,doComplete);
player.play(sinewave);
}

function doComplete(e:Event):void{
trace("COMPLETE")
play_btn.enabled = true;
}

1 个答案:

答案 0 :(得分:0)

问题在于player.play(正弦波);不会触发Event.COMPLETE。我认为它可能触发SampleDataEvent.SAMPLE_DATA。加载声源时会触发Event.COMPLETE。以下代码应该有所帮助:

import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.Event;
import flash.net.URLRequest;
import flash.events.MouseEvent;

//Load the song.
var song:Sound = new Sound();
var songChannel:SoundChannel = new SoundChannel();

song.addEventListener(Event.COMPLETE, hdSongLoaded);
song.load(new URLRequest("assets/songs/VMBach.mp3"));

//Buttons
buttons.onBTN.addEventListener(MouseEvent.CLICK, hdSoundOn);
buttons.offBTN.addEventListener(MouseEvent.CLICK, hdSoundOff);
buttons.skipBTN.addEventListener(MouseEvent.CLICK, hdSkip);

//Handlers.
function hdSongLoaded(e:Event) {
    //e.currentTarget.play();
    songChannel = song.play();
}

function hdSoundOn(e:MouseEvent) {
    songChannel = song.play();
}

function hdSoundOff(e:MouseEvent) {
    songChannel.stop();
}

function hdSkip(e:MouseEvent) {
    //removeChild(onBTN);
    //removeChild(offBTN);
    removeChild(buttons);
    songChannel.stop();
    gotoAndStop(2);
}

stop();