views:

124

answers:

2

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

A: 
// Draw a simple circle, gray, with a diameter 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.

Robusto
Error: Accesof undefined property circle. am getting this error wht to do
dpaksp
Sorry, I may have assumed too much about your level of knowledge. As Adrian points out, you need to be extending a UIComponent class and overriding updateDisplayList.
Robusto
thanks i got it...am fresher from two days am learning
dpaksp
A: 
  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>
Adrian Pirvulescu
how to use this example i tried in root folder i have home.mxml and the action script calss in com folder in that have place code as <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:local="com.*" >panel code here</mx:Application> Error: Could not resolve <local:MyCircle> to a component implementation.
dpaksp
As I see your namespace definition.. you need to define the MyCircle as3-class inside the com. package, to make it work
Adrian Pirvulescu