A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Checking distance between movieclips within other movieclips

  1. #1
    Buck Fush
    Join Date
    Mar 2002
    Posts
    38

    Checking distance between movieclips within other movieclips

    I'm not sure if there is a really quick & dirty way to do this, but I have some movieclips, which are nested within another movieclip, and I'd like to write some code that will return which one is closest to a movieclip on the main timeline. Since there _x's are entirely different because they're not in the same movieclip - is there any way I can make this work?

    Thanks!
    "Litter is my most treacherous foe. I would like to eat its children."
    -Drederick Tatum

  2. #2
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    Code:
    function getclosest(parent){
    var a=0;var b;
    for(var i in parent){
    var c=parent[i].getBounds(theclipyoureferencedonthemaintimeline);
    var d=a.xMin+a.yMin;
    if(d>a){
    a=d;
    b=parent[i];
    }}
    return b;
    }

  3. #3
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    oops... that's return the farthest one away...
    change var a=0 to a=Stage.width+Stage.height and if(d>a) to if(d<a)
    sorry

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