Game Development Reference
In-Depth Information
symbol (right-click and choose Properties), you will see that it is set
to export with the same name as the class we
ve just created. Now
when a new CrosswordTile is constructed, this library asset will be
used as the object to display.
'
The CrosswordClue Class
Before we delve into building the puzzle itself, let
'
sconsiderthe
clue component. It is a relatively simple class
all it needs to do is
display the clue for the selected word. With no need for multiple
frames, Sprite is a better candidate than MovieClip.
package {
import flash.display.Sprite;
import flash.text.TextField;
public class CrosswordClue extends Sprite {
static public const DEFAULT_VALUE:String =
"
Clue
"
;
public var clueText:TextField;
public function CrosswordClue(){
}
public function get text():String {
return clueText.text;
}
public function set text(value:String):void {
clueText.text = value;
}
}
}
The class uses a TextField object and a getter/setter combina-
tion to assign text to it. You might wonder why we didn
tsimply
use a standard text field instead of a custom class. You very well
could for an example as straightforward as this, but there are a
couple of reasons to encapsulate it as its own class. First is the abil-
ity to define constants, such as what the default value of the text
field should be when there is no clue shown. Another reason is
expandability and flexibility
'
by already having a class setup to
handle the clue, it will be easier to add animation and other fea-
tureswithoutaddingalotofcodetothepuzzleclass.Oneother
reason you might not expect is that it is easier to set up a text field
inside Flash rather than a code. Custom fonts (basically, anything
Search Nedrilad ::




Custom Search