AS3 - 在加载过程中删除外部接口回调?

时间:2011-10-12 05:50:38

标签: flash actionscript-3

我有一系列10个外部接口回调,通过javascript和加载mp3文件调用。问题是,有人能够在我的预加载功能运行时单击这些,并导致加载多个文件。有没有办法在预加载功能运行时禁用回调?

 ExternalInterface.addCallback("receiveText1", receiveText1);

function receiveText1(value:String):void {


        channel.stop();
        channel2.stop();
        lblSongTime.alpha = 0;
        lblSongTotalTime.alpha = 0;
        songPosition = 0;
        soundFile2 = new URLRequest(jsVariableValue1);
        myMusic2= new Sound();  //Intstantation
        myMusic2.addEventListener(ProgressEvent.PROGRESS, onLoadProgress2, false,0, true);
        myMusic2.addEventListener(Event.COMPLETE, playMusicNow, false, 0,true);
        myMusic2.load(soundFile2, myContext);
        soundFile2exist = null;
        trace("text1");
        }

加载功能

function onLoadProgress2(evt:ProgressEvent):void {
    channel.stop();
    channel2.stop();
    songPosition = 0;
    btnPlay.mouseEnabled = false;
    progBar.alpha = .70;
    prcLoaded.alpha = .70;
    var pcent:Number=evt.bytesLoaded/evt.bytesTotal*100;
    prcLoaded.text =int(pcent)+"%";
    progBar.width =  90 * (evt.bytesLoaded / evt.bytesTotal);
}

1 个答案:

答案 0 :(得分:1)

只需在Flex中保留一个变量并忽略多个调用。

示例:

private var currentlyLoading:String = "";

function receiveText1(value:String):void {
    if ( currentlyLoading == value ) { return; /*ignore*/ }

    currentlyLoading = value;

    channel.stop();
    channel2.stop();
    lblSongTime.alpha = 0;
    lblSongTotalTime.alpha = 0;
    songPosition = 0;
    soundFile2 = new URLRequest(jsVariableValue1);
    myMusic2= new Sound();  //Intstantation
    myMusic2.addEventListener(ProgressEvent.PROGRESS, onLoadProgress2, false,0, true);
    myMusic2.addEventListener(Event.COMPLETE, playMusicNow, false, 0,true);
    myMusic2.load(soundFile2, myContext);
    soundFile2exist = null;
    trace("text1");
    }

function playMusicNow(e:Event):void {
    currentlyLoading = "";
}