how to draw a circle using ActionScript

社会主义新天地 提交于 2020-01-14 04:08:08

问题


how to draw a circle using action script (as a component) i tried some xample did not work....i need to add this circle in a panel


回答1:


  1. Create a class derived from UIComponent
  2. Override the updateDisplayList() method inside your component and draw the circle
  3. Add an instance of your component in the panel;

Component class:

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));
   }     
}

Panel component:

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

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

</mx:Panel>



回答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);

You can substitute beginLine and endLine instead of beginFill and endFill if you just want the circle's outer edge.



来源:https://stackoverflow.com/questions/3346137/how-to-draw-a-circle-using-actionscript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!