A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: dynamically place movie clips around a circle

  1. #1
    Senior Member
    Join Date
    Feb 2000
    Posts
    119

    dynamically place movie clips around a circle

    I need some help here please, I pretty much a math-tard in general that why I am posting here, hoping someone more mathematically inclined than I can help out.

    I want to create a sort of circular menu, that dynamically places MC's to form a circle or on a curved path. I could easily do it the non programmers way, but I would like to be able to easily update it in the future. Anyone got a .fla siiting around like this they are willing to share?

    My vision is that I can define a variable like num_menus = 16 for example, and the function(makeMenu) or whatever will place them in the correct x, y coordinates..... thats about as far as i can get before my head starts hurting.

    see attached gif for a visual
    Attached Images Attached Images

  2. #2
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Hi,

    You could try something like this,

    code:

    var origin = {x: 250, y: 200}; // object representing the centre of the circle
    var radius = 100; // pixels radius
    var numItems = 16; // how many items round the circle
    var spacing = 2 * Math.PI / numItems; // how far to space them apart
    var depth = 0;
    for (var i = 0; i < 2 * Math.PI; i += spacing) {
    var mc = this.attachMovie("obj", "obj" + ++depth, depth); // attach a clip from the library, with linkage name obj
    mc._x = origin.x + Math.cos(i) * radius; // position the new clip
    mc._y = origin.y + Math.sin(i) * radius;
    }


  3. #3
    Senior Member
    Join Date
    Feb 2000
    Posts
    119
    thanks for that. I tried it using an onClipEvent(load) and it worked fine...next question I have is...how do I show 16 different graphics in the duplicated clip?

    Should i build an array with the dup names and assign each a graphic?

  4. #4
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Hi,

    You could either create separate movie clips for each menu item or have a single movie clip containing multiple frames with the different images in different frames.

    for example you could create 16 clips and give each a different linkage identifier, then store each linkage id in an array,

    code:

    ids = ["someClip", "anotherClip", "andSoOn"];



    then when you run the loop you could use the depth counter to pick the next clip to be displayed,

    code:

    var mc = this.attachMovie(ids[depth], "obj" + depth, depth);
    depth++;



    or you could have all the different images in the same clip and when the clip is attached send it to the desired frame (if the images each occupied a single frame you could use,

    code:

    var mc = this.attachMovie("obj", "obj" + depth, depth);
    mc.gotoAndStop(++depth);


  5. #5
    Senior Member
    Join Date
    Feb 2000
    Posts
    119
    excellent, thank you very much...now i get it. That makes me quite happy. thanks for sharing your brain

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