Flash - Loading AS code *after* frame 1

4 posts

Flag Post

Hi all,

I’ve been scouring the internet for a couple of days trying to get the data loaded in frame 1 down to an absolute minimum to shorten the time the dreaded “blank screen” appears before the preloader starts. I’ve gone through the process where there is an “asset loader” frame that gets passed over, and put everything there, and made sure nothing is set to export in Frame 1.. it all works fine for the 2.5MB of stuff in there. However, there’s still about 350K or so of stuff that I just can’t shake.. and as far as I can tell from the Size Report, it’s for the 353118 bytes of “ActionScript Bytes” in Frame 1.

Is there a way to easily get the AS classes to load in a frame other than 1 in the sort of one-SWF files that portals require? It seems like as long as the Document class is doing its job as the central class, all the code has to be loaded in Frame 1. I haven’t been able to find an elegant solution for this anywhere.. everything else recommends a two-SWF solution. One place recommended dropping all the game code in a MovieClip and having a blank document class, but that seems like it would take an awful lot of rewriting to make everything sync back up again..

 
Flag Post

If you’re using FlashDevelop, just create a project with a preloader and see what it does.

The essential points are:
- in frame 1 you have a ‘main document’ class which is a preloader, and monitors load progress
- in frame 2 you link the actual main class (Main.as or whatever); you can do this with a -frame argument to the compiler or by using the [Factory(PreloaderClass)] metadata on it.
- the preloader loads the main class by reflection (i.e. getDefinitionByName) so that the main class (and all its dependencies) aren’t statically linked into frame 1.

 
Flag Post

Been picking at that, and it certainly seems to reduce the loadtime.. although I found the majority of it was removed by choosing not to to embed the TLF library in Publish Settings (Default Linkage: “Merged into code”), which I did earlier to avoid an error. However, I can’t seem to get around the fact that any code that before would reference objects in a frame set up in the timeline in Flash is now unable to find those objects.. I’m assuming because it’s looking in the old Document class, which now isn’t referenced to that stuff. Could be a lot of work unless there was a way to dynamically tell Flash that the Document class now should be my Main class instead of the Preloader class.. but AFAIK that’s not possible.

Dropping 250K or so by not merging the TLF library into the code is pretty good though.. might be able to get by with a blank screen for the first 60K. Is there a way to not merge that library in, and not have Flash error, while maintaining one file? As far as I know, I’m not using any TLF text.. is there a way to check?

 
Flag Post

Found out how to strip out all the hidden TLF.. save to Flash Player 9 (which doesn’t support it) and then re-open the file and save as Flash Player 10. Now the TLF library is unneeded, and I get about 150K back.

Other than that, is there an easy way to dynamically replace a document class that I’m missing, or am I just stuck with the decision of rewriting a bunch of stuff or accepting a blank screen for the first 150K of the loading process?