Preloader Infinity Problem in Flash AS3
Posted by admin in ActionScript 3, Flash, Tips
Some people have been facing the problem with Flash AS3 preloader. Loading Infinity% seems to be caused by a division by zero error. Below is a little change to the preloader codes which fixed the error. If you are using one of the flash files from flashmo.com, you may update your codes at the preloader scene (Shift + F2, or Main menu bar > Window > Other Panels > Scene). This is located on “actions” layer. You can edit through the actions panel (press F9). You may download 188 chrome black to see the real working example.

-
stop();
-
-
var loaded_bytes:Number;
-
var total_bytes:Number;
-
var percent:Number;
-
-
fm_bar.addEventListener( Event.ENTER_FRAME, load_progress );
-
-
function load_progress(e:Event):void
-
{
-
loaded_bytes = stage.loaderInfo.bytesLoaded;
-
total_bytes = stage.loaderInfo.bytesTotal;
-
-
if( total_bytes == 0 ) total_bytes = 1;
-
-
percent = Math.round(loaded_bytes / total_bytes * 100);
-
fm_bar.scaleX = percent * 0.01;
-
loader_info.text = “Loading… “ + percent + “%”;
-
-
if( percent == 100 )
-
{
-
fm_bar.removeEventListener( Event.ENTER_FRAME, load_progress );
-
play();
-
}
-
}
If you have any question, you may drop a comment below. Thanks!
UPDATES [22 September 2009]: I have found out that a few number of people got a preloader with incorrect loading percent while some people have infinity value problem. Below is the screenshot from David Kennedy’s GFX site while preloader is loading. I guess these 2 different problems seem to be because of different hosting platforms.




[...] UPDATES [15 September 2009]: Please read Preloader Infinity Problem in Flash AS3 [...]
hello,
now i have download the ”188 chrome black”
and copy paste all things from the ”flashmo preloader” into my websites flashmo’s preloader and save everything, but now when i look with internet explorrer the website gives not the error
” Loading Infinity%” but gives now :
”loading” and nothing morge, but the websites dows not loading….?
Yeah…my problem is that when I dload a sample file from Flashmo I can never find the AS code for the preloader….let alone the preloader itself. So where is it in the FLA file??????
Sort of lame to provide examples with no obvious way to view them. I can see all the other AS in these free downloads, but of course, not the AS code I need!!!!!
Not happy!
Hi David,
It is on the preloader scene as written in the post. If you still do not get it, please follow tip number 7 at http://www.hongkiat.com/blog/10-killer-flash-tips-for-beginners/
Hi..yep sorted that out.
I need some clarification as to what I need to do here. I dloaded 188 chrome black FLA file and got the AS code. I was thinking that this code was the fix…..but it’s an example of the Infinity issue…(Correct?)
The code listed above is the fix (Correct?)
Seems that this MUST be the case as I get INFINITY error when I use the 188 chrome black code….but when I use the above code I get a new problem…..I get the loading screen with Bytes instead of 100%….and there the page sits! Nothing happens.
Link to my page: http://users.tpg.com.au/gfx/
(Please dont come back and tell me it works for you as it doesnt under IE7)
Have spent the entire day on this stuff but with no evail. I am about ready to put flash back on the shelf.
Hi David, You are right this code is the fixed one but I see your problem too in different browsers. Can you please upload the original files to test?
Sorry…not sure I follow. The two files are on my site…left them there so that you may look
http://users.tpg.com.au/gfx/
Other than that…not sure what you mean.
2 files are….Index.html and Beachloader.swf
They are both in the root dir.
As for the FLA file….thats 19 meg.
A little more info.
As you can see….Im not getting the Infinity error…It loads (I see the bytes increase and finally….nothing. It just sits there)
Another thing….the loading bar is not centered. It’s to the left. But the Byte counter is centered.
This seems to only be an IE problem. My page loads in Firefox.
Here is my AS preloader code as above:
stop();
var loaded_bytes:Number;
var total_bytes:Number;
var percent:Number;
fm_bar.addEventListener( Event.ENTER_FRAME, load_progress );
function load_progress(e:Event):void
{
loaded_bytes = stage.loaderInfo.bytesLoaded;
total_bytes = stage.loaderInfo.bytesTotal;
if( total_bytes == 0 ) total_bytes = 1;
percent = Math.round(loaded_bytes / total_bytes * 100);
fm_bar.scaleX = percent * 0.01;
loader_info.text = “Loading… ” + percent + “%”;
if( percent == 100 )
{
fm_bar.removeEventListener( Event.ENTER_FRAME, load_progress );
play();
}
}
Hi all,
I’ve been facing the same problem and it was only that I looked at your blog that I learned that the problem was with the preloader. In my situation everything worked fine on IE7 and firefox but not with IE8 and Safari 4.0.3.
I’ve got a quick workaround for you (I don’t dare to call it a solution yet cause I don’t understand it).
Anyway, what seems to be happening is that percent gets larger than 100 causing it never to get in the exit code.
So the quick workaround is to change percent == 100 to percent >=100. In addition if you go there, you might want to update the percent to 100 manually and print the new progress bar text etc.
What happens in my case is that my site is that small in bytes that everything is loaded in the first call to load_progress. loaded_bytes and total_bytes are equal then and larger than 0.
I think in some browsers (?), the rounding is off, causing percent to be rounded above 100.0.
In a different run I saw that loaded_bytes was the complete amount of bytes of my file and total_bytes was 0! I suspect the division by zero guard code for that, and this too I don’t understand yet.
Anyway, my 2 cents. It should get your site working David!
Greetz,
Ray
So….Can anyone shed some light as to why the above code wont work?
Hello Everyone,
I just uploaded original files from flashmo.com just to test this preloader.
Please check
http://www.webdesignmo.com/test/flashmo_188_chrome_black
and
http://www.webdesignmo.com/test/flashmo_184_business
Let me know if they work well in your browsers. For me, I have just tested them in Google Chrome 2.0.172.43, FireFox 3.5.2, Internet Explorer 8, and Safari 4.0 and working correctly.
You may upload them (the same original files) to your web server and post the URLs here. So we all can do testing.
at my website the test results on internet explorrer… just the same problem…
Hi Raymond. Thank you for your detailed response. I have just tried your >=100 suggestion and at least, I think I have progressed a little.
if you look now at http://users.tpg.com.au/gfx/
the page should load. However, flushed my temp internet files and went to the site: Loads a little too quickly. Also, in IE7, the load bar is to the far left when it should be centered.
Would you please be able to let me know if it loads? The SWF is 2meg. So at least, there should be a small delay.
Have tested this on 2 systems. Both now seem to let you enter the site automatically, but as I said, I am not sure it’s actually loading.
Cheers
David
Admin: Yes both those links show loading in both my browsers (IE 7 and Firefox 3.5.3)
And thats the really strange thing.
I go to FLASHMO, dload the file(s)….take them apart, extract the Preloader code: Place it in my AS as preloader…….and it falls over!
Apart from Raymonds suggestion above, what can I now do to make this work the way it is supposed to.
I mean, the code you post above is still valid yes? What are your thoughts (or anyone’s) on Raymonds suggestion? (>=100)
David
Hi everyone¡
I downloaded a flashmo file and i had the infinty problem, I read and read this articule and i had the solution for IE, Chrome y Opera with the Raymonds suggestion (>=100)
but I used the original code of the AS3 preloader, not the one in here.
i post my link here for you to test the site, so please let me know if it works in your browsers
http://tlachco.org/evcorreu/xally/
tnx
PD. sorry for the bad english
Evcorreu….hard to say if it worked….loaded very quick. I saw a quick flash….loading bar was centered at least.
David
evcorreu, yes, I also see it for a second. Your site does not have the preloader infinity problem.
anybody fix the problem?
Hi Jeroen,
In your test files on your server, I see the preloader showing big numbers like 8024250% and then finally stop with “Loading…” but they work fine in my server.
From comparing server specs, I found out that your hosting is FreeBSD 7.1-RELEASE-p5 FreeBSD 7.1-RELEASE-p5 #0 (PHP Version 5.2.8).
My hosting is Linux 2.6.18-92.1.13.el5 #1 (PHP Version 5.2.6).
hello,
the problem is that my hosting as a newer PHP version?
so can the problem fixed in the flash script or something? what can i do now to let work my website on internet explorrer?
hey all. i recently ran into the same problem but I’m not sure that its necesssarily an IE problem.
on a basic preload class i get the infinity thing. if i do the “hack” to avoid divide by zero, it’s hangs but here’s the funny thing. If i run on localhost through xampp – works fine in IE. I upload it to my live server, which is a linux server – and it doesn’t work.
Any one able to confirm for me?
I’ve just done another test using the “hacks” mentioned on this site, now the files don’t preload properly on firefox or IE.
the file loads before all the items are available, but once you refresh , then the missing items are loaded. Not good. I’ll play around a bit more, then upload on a public URL and share the link.
okay I run the chrome site in IE on their server / perfect -on my server – nada
http://www.blue-genie.co.za/ietest/
jeroen have you removed the stuff of your server?
Hi uni, can you please tell me what OS does your server installed?
Hi admin, my server OS is Linux
i’ve managed to put it on a windows server to test and it works fine there.
http://www.biddcom.co.za/games/test/index.html
uni,
what kind of stuff do you mean?
Just a small follow up.
As we seem to still have some issues….and consistency is all over the place. I have a small fix for preloading….except my new method does not use a loading percentage / bar.
Put simply, I load a small SWF that loads my site. My site is only displayed once the COMPLETE status is reached. It will not proceed to my site until this variable is met.
To see my workaround, visit:
http://users.tpg.com.au/gfx/index.html
Cheers and goodluck
David
@David Kennedy,
Sorry, but your site never loaded. Is it really big?
Hello to all:
I also have that problem and I have not been able to solve it I complete, it all that I obtained is that it remains the static rod and the word “Loading”, but never the bar with the percentage moves. After seconds the page is loaded.
My conclusions are that the problem this in the Host (because I tried perfectly in other servers).
I found a article that said that the server compresses by means of PHP some archives (SWF for example) to create an exit buffer and to make but the loading fast (something thus I understood, because not much of programming). Then maybe one solution to disable that method of uncompres (GZIP).
My supplier of hostes does not say to me that it cannot do nothing and tries to disable it by means of client (forming the file htacces that is in my site, but I work either. At the end of accounts I occurred by won, I hope to have time but ahead to continue trying. Sorry for my bad english and please to meet you.
Only one thing, in AS2 work perfect this code:
stop();
preloader._width = 0;
preloader._visible = preloader_bg._visible = true;
preloader.onEnterFrame = function()
{
filesize_total = _root.getBytesTotal();
if( filesize_total == 0 ) filesize_total = 1;
percent = Math.round( _root.getBytesLoaded() / filesize_total * 100 );
txt = percent + “%”;
preloader._width = percent * 3;
if( percent == 100 )
{
txt = “”;
preloader._visible = preloader_bg._visible = false;
_root.play();
delete this.onEnterFrame;
}
}
I’ve also come up with this problem on preloaders.
If you don’t feel like reading the article, it basically comes down to not using the ENTER_FRAME event and using the ProgressEvent and COMPLETE events. I too was running on a server with gzip. Hopefully this is a solution that will help everyone: http://bit.ly/7m2Wru
Dear Min Thu,
let me thank you for this little preloader: it’s really a smart and effective solution! I’m quite new at Flash, but I found it very practical and I make it working in a so short time!
However I experienced a little problem and I’d like you to give me your opinion about it. First of all, let me tell that I’ve put the preloader even in the “main.fla” of my project, and in the secondary movieclip it loads when the pages are choosen. Obviously, in every case I put the preloader in the first scene (of two) of the .fla.
But, while it works in the main .fla (I can see the progress bar going regularly to the completion), the other movieclips (corresponding each to a different .fla file) show the bar only when it’s already completed, then pass to the main scene.
Do you have any idea about this behaviour? Maybe the loading of file into a main.fla makes unapplicable this preloading solution?
Thanks for your attention. I hope to ear you soon.
Regards
basanet
we have found it!!
simple: delete all tekst of the preloader..!!!
Dear JvV,
is you answer for me? If so, thanks so much, but… what should I delete in the preloader? The text? I’ve put no text in it, but just the preloader. any more hints?
can someone help me i cant get the email to work on flashmo_188_chrome_black ive put my email in the ’send email php file ‘ that says
reciever but it doesnt work once ive uploaded it to the net
Hey guys… Don’t brake your brains with AS3 code!!!
And the problem is neither caused by browsers (or only a little part of it…) the problem is in the web server!!!
Apache is used to compress files before send them to the client and this cause the division by 0 error because flash don’t know whats the file size during the preload activity (so assume that is 0 byte…).
The problem is different in different browsers because they handle gzip compression differently
To correct the error write a .htaccess with:
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI \.avi$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mov$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mp4$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.rm$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.swf$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.flv$ no-gzip dont-vary
This say to apache to not use gunzip for the file extension listed.
I find the solution here (Thanks to Castertroy he saved my night):
http://gardengnomesoftware.com/forum/viewtopic.php?f=14&t=4204
Infinity problem is a pain to correct.
Hope this helps