Thanks you guys.
Finally, I have both Josh's code and script from http://flassari.is/2009/11/pie-mask-in-as3/
I have used the code from flassari to draw and update the circle (edited to do it in revert mode, from 100% to 0%), and the way to do of Josh to make a hole at the center of the circle.
Here is the main code I used:
private function init():void
{
// Store sprites
var container:UIComponent = new UIComponent();
gr.addElementAt(container, 0);
// Draw the full circle with colors
circleToMask.graphics.beginGradientFill(GradientType.RADIAL, [0x000000, 0x000000], [0, 1], [80, 130]);
circleToMask.graphics.drawCircle(0, 0, 50);
circleToMask.graphics.endFill();
// Add the circle
container.addChildAt(circleToMask, 0);
// Add the mask
container.addChild(circleMask);
Set the position of the circle
circleToMask.x = (circleMask.x = 14);
circleToMask.y = (circleMask.y = 14);
circleToMask.mask = circleMask;
// Draw the circle at 100%
renderChart(1);
}
private function renderChart(percentage:Number):void
{
circleMask.graphics.clear();
circleMask.graphics.beginFill(0);
// Draw the circle at the given percentage /------ set the begin at the middle top
drawPieMask(circleMask.graphics, percentage, 100, -1.57, 8);
circleMask.graphics.endFill();
}
// Function from flassari (a little simplified)
private function drawPieMask(graphics:Graphics, percentage:Number, radius:Number = 50, rotation:Number = 0, sides:int = 6):void {
radius /= Math.cos(1/sides * Math.PI);
var lineToRadians:Function = function(rads:Number):void {
graphics.lineTo(Math.cos(rads) * radius + x, Math.sin(rads) * radius + y);
};
var sidesToDraw:int = Math.floor(percentage * sides);
for (var i:int = 0; i <= sidesToDraw; i++)
lineToRadians((i / sides) * (Math.PI * 2) + rotation);
if (percentage * sides != sidesToDraw)
lineToRadians(percentage * (Math.PI * 2) + rotation);
}
And here, the mxml:
<s:Group verticalCenter="0" horizontalCenter="0">
<s:Rect width="100%" height="100%">
<s:fill>
<s:SolidColor color="0xcccccc"/>
</s:fill>
</s:Rect>
<s:Label id="lab" verticalCenter="0" horizontalCenter="0" text="test"/>
<s:Group id="gr" cacheAsBitmap="true" blendMode="layer" verticalCenter="0" horizontalCenter="0">
<s:Group verticalCenter="0" horizontalCenter="0" blendMode="erase" cacheAsBitmap="true">
<s:Ellipse width="30" height="30">
<s:fill>
<s:SolidColor color="0"/>
</s:fill>
</s:Ellipse>
</s:Group>
</s:Group>
</s:Group>
Thanks you guys for your help