Game Development Reference
In-Depth Information
Preloading in the Flex SDK
Preloading using the Flex SDK and Flash develop is a relatively painless process, but it
requires a fundamental change to the application structure. A Flex SDK application doesn't
have a normal Flash timeline, so every asset and all code is always loaded before the
application starts to run. This is in contrast to the Flash IDE applications, where the timeline
gives us the advantage of moving assets off of the first frame to allow a very smooth and
straightforward loading process.
With the Flex SDK, we will need to create a new class called Preloader.as that will sit in our
project folder alongside Main.as and other game-specific classes. We have designed our
preloader using the basic model for preloading that is created by Flash Develop if you choose
the New Project AS3 Project With Preloader option. For this example though, we have made the
changes manually to demonstrate exactly what is going on rather than simply use the
preexisting Flash Develop code in its entirety.
Adding the compiler directive
To preload the Flex SDK version of our Tunnel Panic Main.as properly, we will have to make a
change to how the compiler treats the Main.as class. First off, it will no longer be the document
class (or the always-compile class in Flash Develop). The new Preloader class will now be the
document or always-compile class. We do this because we want to be able to load the Main class
in with our Preloader . The only way to do this is to trick the compiler into thinking that Main.as
actually starts on frame 2 of our Flash SWF even though there really isn't a frame 2. How do we
do this?
In Flash Develop you must have your project open and go to the Project
Properties
Compiler
Options menu item.
In the Compiler Options, you must add in a new Additional Compiler Option as follows:
-frame start com.efg.games.tunnelpanic.Main
This tells the compiler that a class called Main will begin on frame 2; see Figure 12-1 for an
illustration of this example.
Search WWH ::




Custom Search