PDA

View Full Version : preloader not appearing until late



ryrocks
May 30th, 2009, 06:51 PM
I have a Flash game which holds all of its content in a single keyframe on the stage. I have one keyframe before this which contains the preloader using the following script:



stop();

this.loaderInfo.addEventListener(ProgressEvent.PRO GRESS, onProgress);
this.loaderInfo.addEventListener(Event.COMPLETE, onComplete);

function onProgress(e:ProgressEvent):void
{
var loaded:Number = e.target.bytesLoaded;
var total:Number = e.target.bytesTotal;
var pct:Number = loaded/total;
loader_mc.scaleX = pct;
loaded_txt.text = "Loading... " + (Math.round(pct * 100)) + "%";
}

function onComplete(e:Event):void
{
nextFrame();
}


The preloader seems to be coded correctly. The problem is that when I upload the file to the web there is a long delay before even the preloader appears. It eventually does appear at about 90%. It continues to load up to 100% then the game starts as required.

I obviously want the preloader to start playing from 1%, its like the swf is trying to load all of the graphic before the preloader loads. I have multiple classes, would this cause the problem?

GarFonz
May 31st, 2009, 12:31 AM
I'm not positive here, but another way to to this; have a preloader.swf that loads another main.swf, I think that the ProgressEvent.PROGESS will be more accurate.

from this post http://www.kirupa.com/forum/showthread.php?t=299008&highlight=swf+progressive+download :


I have a swf with just a jpg as the background and a simple animation. I simply want the swf to start playing and do a progressive download and continue to play. With the jpg it won't start playing until the jpg is finish downloading.

that may help, I thought that a .swf with multiple frames will be displayed when the first frame is completely downloaded, not sure though. How does the server.apache||IIS organize the datagrams? whats the delimeter that invokes the screen render?

BenBart
May 31st, 2009, 01:41 AM
The reason it does that is because of all of the Classes that you have exported to the first frame of the movie. (When you click export for actionscript.)

icekomo
May 31st, 2009, 11:18 AM
The reason it does that is because of all of the Classes that you have exported to the first frame of the movie. (When you click export for actionscript.)

BenBart,
What would be a way around this then? Export the classes to frame 2?

ryrocks
May 31st, 2009, 08:34 PM
The reason it does that is because of all of the Classes that you have exported to the first frame of the movie. (When you click export for actionscript.)

This sounds like a valid reason.

I'd love to find a solution for this. As icekomo says, can I export the class linkage during the second frame?

glosrfc
May 31st, 2009, 08:38 PM
http://www.senocular.com/flash/tutorials/preloading/

Read the section on Loading Complications

icekomo
May 31st, 2009, 11:56 PM
Thanks Glosrfc! That was some super helpful info! Ryrocks you get yours working? I found my problems were solved if I just exported my actions to frame 2 instead of frame 1.

ryrocks
June 1st, 2009, 10:24 PM
Thanks Glosrfc, this is a great resource!

It certainly did help. My preloader now starts around 55% rather than 90%.

I have successfully moved my movieclip linkage to frame 2. I'm still having some delay because I THINK that all the code in the constructor method of all external classes must load before the swf plays.

I have a lot of classes with a fair bit of code in the constructors, declaring movieclip, boolean variables etc.

Am I right in saying this? Would this be the reason why I'm still getting some delay before the preloader is visible? If so, is there a possibility of relocating such code out of the constructor?

marspark
June 2nd, 2009, 06:09 AM
try bulkloader, the learning curve worthes the time, trust me:

http://www.hexosearch.com/se/external.aspx?zqz=preloader&zlvz=2&zvtz=1&zurlz=http://code.google.com/p/bulk-loader/wiki/GettingStarted&ztz=GettingStarted+-+bulk-loader+-+quick+and+dirty+how+to+-+Google+Code