Game Development Reference
In-Depth Information
Aligning code
You might have noticed an interesting pattern developing in the format of the code. Like a set of hol-
low wooden Russian dolls, the I]ej constructor method is inside the I]ej class, which is inside the
l]_g]ca block statement. Each item sits inside the outer item's pair of curly braces, and you now have
three levels of block statements. The only way that you can tell where one ends and the other begins
is by whether the block statement's curly brace is open or closed.
As you can see, this could easily result in a confusing tangle of curly braces. If you weren't absolutely
sure which pair of braces belonged to which block statement, you could start adding new code in the
wrong place, and you'd get all sorts of errors when you tried to run the program.
The code format that you set in Flash's Preferences, and that I recommend you use for the projects
in this topic, helps solve this potential confusion somewhat. Figure 1-6 shows that you can draw an
imaginary line between a block statement's opening brace and its closing brace. It very clearly shows
you at which indentation level you should be adding code.
Figure 1-6. You can make sure that you're adding code in
the right place by keeping each block statement's opening
and closing braces aligned along an imaginary line.
A frequent confusion when writing code is not being certain where one block statement ends and
another begins. If you use this suggested format and can see these imaginary divisions while you write,
it will really help to prevent accidentally adding a line of code in the wrong place.
The ActionScript editing window toolbar also has a special button called Auto Format that will auto-
matically format all your code according to the options you set in Flash's Preferences. If you get a bit
lazy about keeping things neatly aligned, just click it and it will figure out all the indentation and spac-
ing for you.
Search Nedrilad ::

Custom Search