Emadpres
Emadpres

Reputation: 3747

how to draw a 'circle' with 'dynamic angle' using action script 2?

I want to have a circle (maybe a movieclip ) to show a timer which change like this picture :

my goal

And also I need to access its angle in run-time. for example:

function setAngle(degree:Number)

Any suggest ?

Upvotes: 2

Views: 824

Answers (2)

Marty
Marty

Reputation: 39466

Give this a try:

var circle:Number = Math.PI * 2;
var degree:Number = Math.PI / 180;

var radius:Number = 30;
var shape:MovieClip = _root.createEmptyMovieClip("shape", _root.getNextHighestDepth());

shape._x = 100;
shape._y = 100;
shape._rotation = -90;


function render(chunkAngle:Number):Void
{
    chunkAngle *= degree;

    shape.clear();
    shape.lineStyle(1);
    shape.beginFill(0x6BB0FF);

    shape.lineTo(radius, 0);

    for(var i:Number = circle; i > chunkAngle; i -= degree)
    {
        shape.lineTo(Math.cos(i) * radius, Math.sin(i) * radius);
    }

    shape.lineTo(0, 0);
    shape.endFill();
}


render(45);

Upvotes: 2

Fabrice Bacquart
Fabrice Bacquart

Reputation: 129

Well you could have a movieclip with enough frames to cover the angles and use gotoAndStop in your setAngle. Not pretty, though I'm not sure how else you could handle that.

Upvotes: 0

Related Questions