The complied SWF is not showing the preloader until the whole SWF completely loaded. Any hepl would be really appreciated, I googled the whole night couldnt find anything on this, at least for me.
问题:
回答1:
You can not embed the ByteArray
into your main document class, because classes that are referenced from the document class will automatically be included on frame 1.
The best way to preload assets is to have a separate Preloader class and Main class. You want your Preloader class to export on frame 1, and your Main class and assets on frame 2.
Unfortunately, this is trickier than it should be, but here's how you can do it: Set your document class to Preloader
. This class contains your loaderInfo
code. However, when you finish loading, do not instantiate Main directly, i.e. do not do var main:Main = new Main()
. This will automatically cause Main to be compiled onto frame 1 regardless of what you do. Instead, instantiate it indirectly, like this:
nextFrame(); // you sometimes need to do this for the player to register classes exported on frame 2
var mainClass:Class = flash.utils.getDefinitionByName("Main") as Class;
var main:Sprite = new mainClass();
addChild(main);
This will stop the compiler from automatically yanking Main onto frame 1.
Next, if you are using the Flash CS3+ IDE, go to File->Publish Settings->Flash->ActionScript 3.0 settings and change the "Export classes on frame" setting to frame 2. Then, on frame 2 of your movie, place an empty MovieClip. Inside this MovieClip, place a reference to your Main class by putting this code: var dummy:Main;
. The reason you have to do this is so that the compiler will still know you are using Main, so it will actually compile it into the movie, otherwise it would not compile it at all. You also don't want to put this on the main timeline, because any code references on the main timeline automatically get yanked onto frame 1.
In the IDE, a helpful trick to check that things have exported in their proper place is to check "Generate size report" in Publish Properties->Flash. You can examine the report and will easily notice if junk has exported onto frame 1.
If you are using Flash Builder, FlashDevelop, or FDT, the process is basically the same--create separate Preloader and Main classes, and instantiate Main indirectly from Preloader. But to signal the compiler to compile Main on a frame after Preloader, put this metatag above public class Main
in Main.as
:
[Frame(factoryClass="Preloader")]
FlashDevelop can also introspect SWF files by click on the + beside it in the Project tab. It will show you what assets have been exported onto which frames. Ideally, you only want the bare minimum of Preloader on frame 1.
回答2:
I've tested Mike's method in CS4. Apparently the dummy movie clip that references Main doesn't need to be on frame 2, or anywhere on the timeline for that matter. As long as the dummy movie clip is set to export on frame 2, Main will export on frame 2 because its referenced in the dummy clip's code.