Game Development Reference
In-Depth Information
Defining the constructor and init function for Circle.as
The constructor takes a single integer parameter representing either the CIRCLE_GOOD or
CIRCLE_BAD static constant integers of the Circle class. Once, the init function is called to create
the look of the circle.
public function Circle(typeval:int) {
buttonMode = true;
useHandCursor = true;
init(typeval);
}
public function init(typeval:int):void {
var shapeColor:Number;
switch (typeval) {
case CIRCLE_GOOD:
//good circle
shapeColor = 0x0000FF;
type = typeval;
break;
case CIRCLE_BAD:
//bad circle
shapeColor = 0xFF0000;
type = typeval;
break;
}
graphics.clear();
graphics.lineStyle(2, 0xffffff);
graphics.beginFill(shapeColor);
graphics.drawCircle(5, 5, 8);
graphics.endFill();
x = int(Math.random() * 399);
y = int(Math.random() * 399);
scaleX = .5;
scaleY = .5;
nextScale = scaleX;
addEventListener(MouseEvent.MOUSE_DOWN, clickedListener,
false, 0, true);
}
The real meat of the Circle class is in the init function. Before we get to that, notice that we set
the buttonMode and userHandCursor to true for the Circle class. We have access to these
properties because we extended the Sprite class.
The init function must first do a switch:case on the typeval passed in to set the properties of
either a CIRCLE_BAD or a CIRCLE_GOOD circle. We use a switch:case statement here, because we
might want to create more than just two circle types in the future if we ever consider expanding
this game into a more elaborate creation.
Search WWH ::




Custom Search