开发者

AS3 - remove external interface callback during loading?

开发者 https://www.devze.com 2023-04-12 15:31 出处:网络
I have a series of 10 external interface callbacks t开发者_运维技巧hat are called through javascript and load mp3 files.The problem is, someone is able to click these while my pre-load function is run

I have a series of 10 external interface callbacks t开发者_运维技巧hat are called through javascript and load mp3 files. The problem is, someone is able to click these while my pre-load function is running and it causes multiple files to load. Is there a way to disable the callbacks while the pre-load function is running?

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

loading function

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


Just keep a variable in Flex and ignore multiple calls.

Example:

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 = "";
}
0

精彩评论

暂无评论...
验证码 换一张
取 消