Game Development Reference
Square brackets are called an array access operator , which has a few different uses. One use is to
refer to instance or property names dynamically, as in the previous code. It also refers to elements in
an array. You haven't seen this second use yet, but will very soon. Stay tuned!
Finding the global x and y position of a subobject
The Bug Catcher game includes a frog character that sits on the platform in the bottom-left corner
of the stage. If you look at the frog closely while you're playing the game, you'll notice that its eyes
follow the cat wherever it goes.
To implement this little trick, you need to know the exact t and u position of the frog's habpAua and
necdpAua subobjects, and then rotate the eyes so that they point in the correct direction.
There's one big problem, however. Flash and AS3.0 interpret the t and u positions of subobjects
according to the subobject's local coordinates . It doesn't know what the t and u coordinates are that
they occupy on the stage. The stage's coordinates are known as the global coordinates . Before you
can make the frog's eyes rotate correctly, you need to know what their global t and u positions are.
Let's first take a closer look at the problem, and then how you can solve it. The Bnkc symbol has two
Movie Clip subobjects: habpAua and necdpAua. If you double-click the Bnkc symbol in the Library and
then click the necdpAua instance, you'll notice that the Properties panel says it has an t position of
18.8. Figure 9-16 illustrates this. This is the eye's local coordinate. Keep this in mind!
Figure 9-16. The frog's rightEye subobject has a local x coordinate of 18.8.