Game Development Reference
In-Depth Information
2. Save the I]ej*]o file and test the program. Play through the game. When it's finished, the
Guess button will be dimmed, and you can't click it. Figure 5-22 shows an example.
Figure 5-22. Disable and dim the Guess button
at the end of the game.
All the new code was added inside the aj`C]ia method's function definition because its directives run
only when the game is finished.
The first new directive removes the event listener from the cqaoo>qppkj object:
cqaoo>qppkj*naikraArajpHeopajan$IkqoaArajp*?HE?G( ±
Nothing happens when the Guess button is clicked, but all the button states still work. To prevent this,
you need to specifically disable the button using this line of code:
Buttons have a special property called aj]^ha` that determines whether or not they're clickable. The
aj]^ha` property accepts >kkha]j values (the default value is pnqa). To disable the button, simply
assign its aj]^ha` property a value of b]hoa.
The last new directive dims the button on the stage. Use the button's ]hld] property and set it to ,*1,
which makes it semitransparent:
To help you keep things a bit more modular, you could actually move all these directives related to
disabling buttons into their own method, perhaps called `eo]^ha>qppkjo. In such a small program as
the number guessing game, however, it would probably be more trouble than it's worth. Modularize
your code wherever you can, but also use your judgment about when it's appropriate or practical.
Playing again?
You've solved a bug, so let's add a feature! A Play Again button!
1. Create a new button symbol called Lh]u=c]ej>qppkj.
2. Drag an instance of the Lh]u=c]ej>qppkj onto the stage next to the Guess button. Give it the
instance name playAgainButton .
Search Nedrilad ::

Custom Search