Game Development Reference
In-Depth Information
labelTextFormat is the TextFormat of the label .
labelWidth is the width in pixels for the label .
contentText is the initialization text for the context .
contentTextFormat is the TextFormat for the content .
The constructor sets the label TextField instance and the content TextField instance to the
appropriate passed in values. The content.x is set to the width of the label field plus the
bufferWidth value. This will act as a way to make sure that the label and content elements float
together nicely on the screen. Other than that, all of the other attribute assignments are pretty
straightforward.
The final thing we do is add the content and label TextField instances to the display list of the
SideBySideScoreElement instance.
The setLabelText and setContentText definition functions
These two functions are public, and they allow the label and content text to be changed
externally by the ScoreBoard class. We described the label text as static previously, but since
there is no real way to create a static text field from a dynamically created TextField instance, we
decided to allow the label to be changed just in case there was a need for it down the road.
public function setLabelText(str:String):void {
label.text = str;
}
public function setContentText(str:String):void {
content.text = str;
}
The Game class
The Game.as framework class is the parent class for all games we will make that use the
framework. It contains the bare minimum information needed to communicate with the
GameFrameWork.as sub-class Main that we will create for our game.
Create the Game.as file in the framework package structure we created earlier:
/source/classes/com/efg/framework]Game.as
Here is entire code listing for this class:
package com.efg.framework
{
// Import necessary classes from the flash libraries
import flash.display.MovieClip;
import com.efg.framework.CustomEventScoreBoardUpdate;
import com.efg.framework.CustomEventLevelScreenUpdate;
/**
* ...
* @author Jeff Fulton
*/
public class Game extends MovieClip {
//Create constants for simple custom events
public static const GAME_OVER:String = "game over";
Search WWH ::




Custom Search