Game Development Reference
In-Depth Information
package com.efg.games.superclick
{
import flash.text.TextField;
import flash.text.TextFormat;
import flash.display.Sprite;
/**
* ...
* @author Jeff Fulton
*/
public class ScoreTextField extends Sprite{
private var textField:TextField = new TextField();
private var life:int;
private var lifeCount:int;
public function ScoreTextField(text:String,
textFormat:TextFormat,x:Number,y:Number,life:int) {
this.x = x;
this.y = y;
this.life = life;
this.lifeCount = 0;
textField.defaultTextFormat = textFormat;
textField.selectable = false;
textField.text = text;
addChild(textField);
}
public function update():Boolean {
trace("scoreText update");
lifeCount++;
if (lifeCount > life) {
return true;
}else {
return false;
}
}
public function dispose():void {
removeChild(textField);
textField = null;
}
}
}
You have seen most of the code needed for this class in previous classes we have created. The
private attributes (textField, life, and lifeCount) and constructor parameters (text, textFormat, x, y,
and life) have been discussed previously. Aside from accepting parameters and assigning them
to the private attributes, the constructor also creates the textField with the passed in text value
and calls the addChild method to place it on the stage display list.
Search WWH ::




Custom Search