Skip to main content
Inspiring
July 1, 2011
Answered

AS1/AS2 to AS3 onClipEvent(load),onClipEvent(enterFrame)

  • July 1, 2011
  • 1 reply
  • 12245 views

onClipEvent (load) {

     total = _root.getBytesTotal();

}

onClipEvent (enterFrame) {

     loaded = _root.getBytesLoaded();

     percent = int(loaded/total*100);

     text = percent+"%";

     gotoAndStop(percent);

     if (loaded == total) {

          _root.gotoAndPlay(2);

     }

}

Dear all,

I found a sample code that is writen in AS1/AS2 to see if the load is finished, If finish loading, it will go to the next frame. How do I convent this into AS3? This is my first time looking at AS1/AS2 code, especially onClipEvent (load), _root.getBytesTotal(), onClipEvent (enterFrame), _root.getBytesLoaded(),_root.gotoAndPlay(2).

Can someone help me out with this?

Thanks,

-Zainuu

This topic has been closed for replies.
Correct answer relaxatraja
this.addEventListener(Event.ENTER_FRAME, loading);
function loading(e:Event):void{
    var total:Number = this.stage.loaderInfo.bytesTotal;
    var loaded:Number = this.stage.loaderInfo.bytesLoaded;
    if (total == loaded){
        play();
        ploader.visible=false;
        this.removeEventListener(Event.ENTER_FRAME, loading);
    }
}

1 reply

relaxatraja
relaxatrajaCorrect answer
Inspiring
July 1, 2011
this.addEventListener(Event.ENTER_FRAME, loading);
function loading(e:Event):void{
    var total:Number = this.stage.loaderInfo.bytesTotal;
    var loaded:Number = this.stage.loaderInfo.bytesLoaded;
    if (total == loaded){
        play();
        ploader.visible=false;
        this.removeEventListener(Event.ENTER_FRAME, loading);
    }
}
ZainuuAuthor
Inspiring
July 1, 2011

Hi, Thanks for the reply

stop();

this.addEventListener(Event.ENTER_FRAME, loading);

function loading(e:Event):void{

    var total:Number = this.stage.loaderInfo.bytesTotal;

    var loaded:Number = this.stage.loaderInfo.bytesLoaded;

     trace(total);

     trace(loaded);

    if (total == loaded){

          

        play();

        mc_Loader.visible=false;

        this.removeEventListener(Event.ENTER_FRAME, loading);

    }

}

I tried to trace the total bytes and loaded bytes, it returns me

total = 405668

loaded = 405668

Is there a way to show the loaded bytes starting from 1 till 405668? I'm trying to find out if it is really loading the thing. Otherwise is there any other ways to slow down the loading for a bit because it only shows my loading bar for 0.5secs, not really sure if its really loading it...

relaxatraja
Inspiring
July 1, 2011

Yeah you can see using simulate download on player:

use the download settings to see with different bandwidths.