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
2010-07-27 17:29:42
Error: Accesof undefined property circle. am getting this error wht to do
dpaksp
2010-07-27 17:59:17
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
2010-07-27 19:04:05
thanks i got it...am fresher from two days am learning
dpaksp
2010-07-27 19:07:59
A:
- Create a class derived from UIComponent
- Override the updateDisplayList() method inside your component and draw the circle
- 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
2010-07-27 17:36:50
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
2010-07-27 17:49:54
As I see your namespace definition.. you need to define the MyCircle as3-class inside the com. package, to make it work
Adrian Pirvulescu
2010-07-28 05:22:01