A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: How to generate movieclips dynamically in a circular fashion

  1. #1
    Senior Member
    Join Date
    Jun 2009
    Posts
    101

    Thumbs up 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

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center