Example: Sprite Factory | 87
Creator Classes: Shape Creators
TheShapeCreatorclass shown in Example 2-26 defines the abstract interface for the
creator classes. The publicly accessibledraw( )method is the real workhorse of this
class. It calls thecreateShape( ) factory method, and operates on the returned
ShapeWidgetobject. The parameterized factory methodcreateShape( )should behave
as an abstract method, and must be overridden by the concrete creator classes.
Example 2-23. CircleWidget.as
package shapecreators {
internal class CircleWidget extends ShapeWidget {
override internal function drawWidget( ):void
{
graphics.lineStyle(3, 0xFFFF00);
graphics.drawCircle(0, 0, 10);
}
}
}
Example 2-24. FilledSquareWidget.as
package shapecreators {
internal class FilledSquareWidget extends ShapeWidget {
override internal function drawWidget( ):void
{
graphics.beginFill(0xFF00FF);
graphics.drawRect(-10, -10, 20, 20);
graphics.endFill( );
}
}
}
Example 2-25. FilledCircleWidget.as
package shapecreators {
internal class FilledCircleWidget extends ShapeWidget {
override internal function drawWidget( ):void
{
graphics.beginFill(0xFFFF00);
graphics.drawCircle(0, 0, 10);
graphics.endFill( );
}
}
}