Game Development Reference
The next thing that happens is that the text from the op]npIaoo]ca variable is copied into the output
text field's special patp variable:
kqplqp, of course, is the instance name of the dynamic text field on the stage. It's followed by a dot,
and then the word patp. All text field objects have this special built-in variable called patp. Whatever
you assign to the patp variable is displayed on the stage by the text field.
You could have easily written this same line of code like this, and the result would have been
Why did you go to all that extra trouble of creating the extra op]npIaoo]ca variable when you could
have assigned the text directly?
First, you got some practice in creating Opnejc variables—that's not such a bad reason, is it? Second,
it's sometimes useful to store all the text you'll be using in your program in variables that you can
access in one spot. If you know that all the text in your program is assigned to variables in your ejep$%
method, you don't need to go hunting through your code to find it if you need to make changes to
it. This isn't an important issue in small programs such as the number guessing game, but it could
become a real chore in bigger programs.
Finally, you want to make sure that the input text field is completely blank so players are free to type what-
ever they want into it. To clear a text field of any characters, assign it a pair of empty quotation marks:
Empty quotation marks are to string variables what 0 is to number variables: it just means that there's
no text there yet.
Making it more obvious
The GUI is fine at the moment, but it's actually hard for the player to know that the input text field is
not just a black rectangle sitting on the stage. You could add a static text field just above it with the
words Please enter your guess , but let's see if you can do it by providing some visual cues. You can
improve the usability of the input field in a number of ways:
Add a blinking cursor so that players know they can type numbers into it.
Add a gray background color to differentiate it from the surrounding white of the stage.
Restrict the player to entering only numbers. If the player is asked to guess a number from 1 to
100, it wouldn't make sense if he or she entered something like green car , would it?
All these things are really easy to do with a few more lines of AS3.0 code:
1. Modify the ejep method by adding the following code: