arcanus

So, you want to make a flash game in ActionScript 3.0, you want to deliver it in one .swf file with no dynamic loading, and you want to show a preloader as the file is loading. You will be using the flash authoring tool, not the Flex environment. You know this is possible.

Here are the steps you need to take.*

First, every class that you want to export from the .Fla needs to be linked for exporting, but uncheck the "Export in first frame" box.




Now however, your assets will not be exported at all unless they are included in the timeline somewhere, so make 3 frames in your timeline, like so:



The first frame is for your preloader class, which you export normally. The second frame needs to contain one instance of each class in your library that you wish to export. The third frame should probably be blank, or can contain your game.

Your preloader should stop the main timeline on frame one, and once the whole movie is loaded, advance to frame 3 and start the game. Make sure you don't reference the game class from the preloader code however, since this will cause that action script to be linked in. Instead, you can use the getDefinitionByName() function to find the class once it's loaded.

  public function start_game()
{
var game_type:Class = getDefinitionByName("SolitaireJam") as Class;
m_main_timeline.addChild(new game_type);
}
Depending on your implementation you may have to create a blank movie clip class for what used to be your document class, and place this in frame 2 with the other assets, to insure that your document class will be loaded, since it will no longer be linked in automatically.

This should get everything working, but you will notice that all of your script is still being loaded before the first frame, even though the assets are loaded later. To change that, go to the publish settings dialog, the flash tab, the action script 3.0 settings button, and change the "Export classes in frame" field to "2", thusly:


Now your preloader will display as soon as all the preloader assets are in, and you can start the game from there. Hooray. All this information is scattered around the web here and there, but it took me a while to find, and it is not really documented by Adobe.

EDIT: also beware of this bug.

*When working on this, I found it extremely helpful to have flash generate a size report (option in publish settings) and to look at the download profile (press ctrl-D in the test movie box to show, press ctrl-enter again to test download).

No comments:

Post a Comment