Game Development Reference
In-Depth Information
An example of how class properties may be used is illustrated in the following class:
package {
import flash.display.Sprite;
public class HelloWorld extends Sprite
{
private const DELTA:int = 10;
private var m_posX:Number;
private var m_posY:Number;
public function HelloWorld()
{
}
public function moveRight():void {
m_posX += DELTA;
}
public function moveLeft():void {
m_posX -= DELTA;
}
public function moveDown():void {
m_posY += DELTA;
}
public function moveUp():void {
m_posY -= DELTA;
}
}
}
Magic numbers and constants
You also observe a declaration statement for DELTA. As opposed to a variable, a
constant may not change its value after being declared with an initial value. The use
of constants is a great programming habit that cuts down on the magic numbers
all over the code. This also helps if you want to fine-tune the value from 10 (in the
sample) to something elseā€”one change results in changes everywhere.
 
Search WWH ::




Custom Search