Skip to main content
Known Participant
June 28, 2011
Question

Preloader

  • June 28, 2011
  • 2 replies
  • 1004 views

Adobe Flash CS3
Action Script 1.0 & 2.0

Hello, Im just almost done with my site. Just put in a preloader in the 1st scene of my site, and this is the script I put in:

stop();

addEventListener(Event.ENTER_FRAME, loading);

function loading(e:Event):void{
var total_bytes:Number = this.stage.loaderInfo.bytesTotal;
var loaded_bytes:Number = this.stage.loaderInfo.bytesLoaded;
rectangle_clip.scaleX = loaded_bytes/total_bytes;
text_clip.text = Math.floor((loaded_bytes/total_bytes)*100)+="%";
if (total_bytes==loaded_bytes){
  gotoAndPlay(2);
  this.removeEventListener(Event.ENTER_FRAME, preload1);
}
}

Went to go test my site, this is the error message I got:

Why am I getting these error messages? Any help would be appreciated. Thanks

This topic has been closed for replies.

2 replies

Known Participant
June 28, 2011

is there any way to incorporate the scale action, and show the percent that the user has left using this tutorial?

http://www.youtube.com/watch?v=mfT84Bvy9yU

Known Participant
June 28, 2011

I found some AS for the AS2 preloader that MIGHT work, BUT, I would like to incorporate the scale action for the load bar itself without having to make a tween action. So, my question is this:

Is there any way to incorporate this:

)else (
        preLoader.Fill.scaleX = numberLoaded/bytesLoad;
  preLoader.bytesPercent.text = Math.floor(numberLoaded/byteLoad*100) + "%";

Into this:

this.onEnterFrame = function(){
amount = this.getBytesLoaded() / this.getBytesTotal;
preLoader._width = Math.round(amount * 860.2);
if(amount == 1){
  this.gotoAndStop(2);
}
}

And still have it work properly with no errors? Any help and advice would be appreciated. Thanks.

Ned Murphy
Legend
June 28, 2011

Then just incorporate it, try...

this.onEnterFrame = function(){
  amount = this.getBytesLoaded() / this.getBytesTotal();
 

  preLoader.Fill._xscale = amount;
  preLoader.bytesPercent.text = Math.floor(amount*100) + "%";

 
  if(amount == 1){
     this.gotoAndStop(2);
  }
}

Ned Murphy
Legend
June 28, 2011

That's AS3 code, so if you're working in AS2, you should find yourself an AS2 preloader.

Known Participant
June 28, 2011

would this work?

bytes_loaded = Math.round(this.getBytesLoaded());
bytes_total = Math.round (this.getBytesTotal());
getPercent = bytes_loaded/bytes_total;
this.rectangle_clip._width = getPercent*200;
this.text_clip = Math.round(getPercent*100)+"%";
if (bytes_loaded == bytes_total){
gotoAndPlay(2);
}

I get no error message with this one, but when I went to go test it out and did "simulate download" I did not see the load bar move at all. And on top of that, I don't even see the percent number. is this good or bad? If bad, how can I fix it?

Ned Murphy
Legend
June 28, 2011

No that won't work, at least not in any way you might expect it to.  You should search Google for an example of an AS2 preloader.  That way, not only will you find code to help you, you will hopefully also get an explanation so that you can try to understand what the different parts do.