Game Development Reference
In-Depth Information
the hierarchy for all display objects (all objects you can see on the stage). When the SWF file runs the
program, an instance of the Op]ca class is automatically created (called, conveniently enough, op]ca).
To assign focus to a text field, all you need to do is assign the name of the text field object to the
op]ca*bk_qo property, as you did here.
If you need to remove focus from a text field, you can give it a jqhh value, such as the following:
op]ca*bk_qo9jqhh7
The GUI for the game is, of course, extremely simple, but all the important elements you'll need to get
you thinking about GUIs are contained in this little example.
Making decisions
So far, the program doesn't do anything useful. Enter a number, click the button, and wow . . . noth-
ing happens! What you need to do now is build the brains of the game so the program can figure out
what number the player has entered and whether it's too high, too low, or correct.
You can do this by using an eb+ahoa block statement. eb+ahoa statements are very similar to the sim-
ple eb statements that you looked at in Chapter 3, except that they provide an extra course of action
if the condition being checked turns out to be b]hoa.
Here's an example of the basic kind of eb statement that you looked at in the previous chapter:
eb$pdeo_kj`epekjknr]ne]^haeopnqa%
w
Lanbknipdeo`ena_pera***
y
But what if the condition is not pnqa? Obviously, the directive inside the eb statement won't run. But
what if you what something else to happen instead? That's where the addition of the keyword ahoa
comes in. Here's an example of a simple eb+ahoa statement:
eb$pdeo_kj`epekjknr]ne]^haeopnqa%
w
Lanbknipdeo`ena_pera***
y
ahoa
w
Lanbknipdeo`ena_peraebpda_kj`epekjknr]ne]^haeoj#ppnqa***
y
If the condition turns out to be b]hoa, the program will jump straight to the second directive enclosed
inside the braces of the ahoa block statement. This allows the program to make a choice between two
alternatives, and at least one of them will be chosen.
 
Search Nedrilad ::




Custom Search