2010-07-27 51 views

回答

2
// Draw a simple circle, gray, with a radius of 24 px 

var circleColor:uint = 0xCCCCCC; 
var radius:uint = 24; 
var circle:Shape = new Shape(); 
circle.graphics.beginFill(circleColor); 
circle.graphics.drawCircle(radius, radius, radius); 
circle.graphics.endFill(); 
addChild(circle); 

圆如果你只想要圆的外边缘,你可以用beginLine和endLine代替beginFill和endFill。

+0

错误:ACCES未定义的属性圆的 。我得到这个错误要做 – dpaksp 2010-07-27 17:59:17

+0

对不起,我可能假设你的知识水平过高。正如Adrian指出的那样,您需要扩展UIComponent类并覆盖updateDisplayList。 – Robusto 2010-07-27 19:04:05

+0

谢谢,我知道了...我从两天开始学习新鲜 – dpaksp 2010-07-27 19:07:59

2
  1. 创建从UIComponent衍生
  2. 覆盖的updateDisplayList()方法将组件内的一类,并绘制圆
  3. 添加在面板的组件的一个实例;

Component类:

class MyCircle extends UIComponent 
{ 
    public function MyCircle() 
    { 
     super(); 
    } 

    override protected function updateDisplayList(width:Number, height:Number):void 
    { 
     super.updateDisplaylist(width,height); 

     this.graphics.clear(); 
     this.graphics.beginFill(0xff0000); 
     this.graphics.drawCircle(width/2, height/2, Math.min(width/2,height/2)); 
    }  
} 

面板组件:

<mx:Panel width = "400" height 
= "400"> 

    <local:MyCircle 
    width = "100%" 
    height = "100%"/> 

</mx:Panel> 
+0

如何使用这个例子我在根文件夹中尝试过我有home.mxml和com文件夹中的动作脚本calss,它的地方代码为 panel code here 错误:无法解析到组件实现。 – dpaksp 2010-07-27 17:49:54

+0

当我看到你的命名空间定义..你需要在com中定义MyCircle as3-class。包,使其工作 – 2010-07-28 05:22:01