-
How to generate movieclips dynamically in a circular fashion
Hello Friends,
I need a small help from you guys.
I want to generate movielclips dynamically using xml nodes in a circular fashion (lets assume 360 degree circle). Suppose if i have 5 nodes in xml, then it has to generate only 5 movieclips in a circular fashion. and if it was 50, it has to generate 50 mc's in a circular fashion again.
how to do this in actionscript 3.0.
any help.suggestions would be appreciated
Rajesh
-
Divide 360 (or 2*Pi, rather, because stuff is usually done in radians) by the number of objects you want to show. That's the angular distance between each. So from a point x,y, they will be placed at x + cos(Θ)*radius, y + sin(Θ)*radius, where Θ is the angle.
Code:
function placeNObjectsInACircle(x:Number, y:Number, n:int, rad:Number):void{
var mc:Thingy; //this is your object type.
var theta:Number = 0; //angle in radians
var anglestep:Number; //angular difference between Thingies.
anglestep = 2*Math.PI/n;
for (var i:int = 0; i < n; i++){
mc = new Thingy();
mc.x = x + Math.cos(theta)*rad;
mc.y = y + Math.sin(theta)*rad;
theta += anglestep;
addChild(mc);
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|