您可以轻松地做到这一点,同时将您的类扩展到 Shape 或 Sprite
这是你的代码
public class ballShape extends Sprite {
public function ballShape() {
// define shape properties. The graphics object is already added to your Sprite, no need to manually addChild() this object.
graphics.beginFill(color, alpha); // you can begin a fill with this method, there are also methods to start a bitmap fill, gradient fill.
graphics.drawRect( x, y, width, height ); // draw a shape
graphics.endFill();
}
}
虽然 Shape 可以具有绘制形状和线条的相同功能,但我选择了 Sprite,因为:
- 您将具有交互性并能够从该类调度事件
- 您将拥有一组 Sprite 具有的有用属性。
有关 Graphics 类的更多信息,请参阅http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Graphics.html