Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can not embed the <code>ByteArray</code> into your main document class, because classes that are referenced from the document class will automatically be included on frame 1.</p> <p>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.</p> <p>Unfortunately, this is trickier than it should be, but here's how you can do it: Set your document class to <code>Preloader</code>. This class contains your <code>loaderInfo</code> code. However, when you finish loading, <strong>do not instantiate Main directly</strong>, i.e. do not do <code>var main:Main = new Main()</code>. This will automatically cause Main to be compiled onto frame 1 regardless of what you do. Instead, instantiate it indirectly, like this:</p> <pre><code>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); </code></pre> <p>This will stop the compiler from automatically yanking Main onto frame 1.</p> <p>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: <code>var dummy:Main;</code>. 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.</p> <p>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.</p> <p>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 <code>public class Main</code> in <code>Main.as</code>:</p> <pre><code>[Frame(factoryClass="Preloader")] </code></pre> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload