< Day Day Up > |
We've now created two classes ( A and B ) and a Flash document that will use them ( AppName.fla ). Let's see exactly how AppName.fla loads the classes and invokes the class method A.main( ) , which starts our application. In Chapter 2, we learned that the fundamental metaphor of a Flash document is the timeline, which can be used to create animations like a filmstrip. When used for animation, the frames in the timeline are displayed in rapid linear succession by the Flash Player. However, the timeline can also be used to create a series of application states, in which specific frames correspond to specific states and frames are displayed according to the application's logic, not linearly (according to the passing of time). In our example application framework, we'll use the timeline of AppName.fla to create two basic application states: loading and main . Each state is implemented by pausing the playhead in a corresponding labeled frame. On the frame labeled loading , we display a loading message while our application's classes load. On the frame labeled main , we invoke A.main( ) , which starts the application.
To load our A and B classes, we'll follow these general steps:
The specific procedures for those three steps are listed next . If you've already read Chapter 5 you'll have seen some of these procedures before. To specify the export frame for classes in the movie, follow these steps:
To add the labeled state frames loading and main to AppName.fla 's timeline, follow these steps:
Next, follow these steps to add code that displays a loading message while the movie loads:
loadmsg_txt.removeTextField( ); We've now provided the basic timeline structure that loads our application's classes. All that's left is to start the application by invoking A.main( ) . We do that on the frame labeled main in AppName.fla . Add the following code to the end of the script on frame 15 (i.e., just below loadmsg_txt.removeTextField( ); ): import com.somedomain.A; A.main( ); In theory, that will be the last change we ever make to AppName.fla , unless we want to include components , sounds, or custom graphics. Any code in our application will reside in a class that's referenced either directly by A.main( ) or indirectly by a class referenced in A.main( ) . We won't place any more code in AppName.fla . Our application is complete. We now need to test that everything works. To do that, we need to export a .swf file and run it in the Flash Player. |
< Day Day Up > |