Game Development Reference
In-Depth Information
Figure 3-10 illustrates how to write a simple program that uses this method. If you want to take
a closer look or experiment with it a bit on your own, you'll find this sample program in the Iapdk`
sepdkqpl]n]iapano folder in the chapter source files.
eilknpbh]od*`eolh]u*Ikrea?hel 7
This is the method call. When the
program encounters a method call
it checks the method's function
definition to find out what it
should do.
lq^he__h]oo I]ej atpaj`oIkrea?hel
lq^he_bqj_pekj I]ej$%
bqj_pekj `eolh]uPatp$%6 rke`
pn]_a$ Pdeoeopatpbnkipdabqj_pekj`abejepekj %7
This is the method's function definition.
Whatever directives it contains are
run when the method is called.
Function definitions can contain calls
to other methods that help them perform
their tasks. This method uses AS3.0's
built-in trace method to display text in
the Output panel.
When the program runs, the displayText method
is called by the Main class's constructor.
This is the result in the Output panel.
Figure 3-10. An example of a simple method in action
To use the source files in this topic, do the following:
1. Make sure the Project panel is open. If it isn't, select Window ° Other Panels ° Project .
2. In the Project panel, select Open Project from the drop-down menu.
3. Find the folder that contains the source files and select it.
4. Click the Choose button.
5. All the files required for the project will be loaded into the Project panel.
6. You now need to assign an FLA file as the default document. The default document is the
file that Flash uses to create the SWF file. If the project's default document has already been
assigned, this will be indicated by a yellow star on the FLA file's icon. If the default document
hasn't been assigned, you need to assign it manually. To do this, right-click on the FLA file and
select “Make default document” from the context menu. (Sometimes this option won't appear
the first time you select the file. If it doesn't, try selecting the FLA again.)
7. Once the default document has been assigned, you can click the Test Project button to see the
result of the program. Double-click any of the files to open them to make changes.
Keep in mind that methods are a two-part system: you have to create a function definition to define
the method and then you need a method call to use it.
Search Nedrilad ::

Custom Search