• 14th January 2009 - By Bill Nunney
    Flash CS3 Professional

    Quick Code:

    // Given that you have 2 movieclips named "marker01" & "marker02"
    var dist = Math.sqrt((marker01.y-marker02.y)*(marker01.y-marker02.y) + (marker01.x-marker02.x)*(marker01.x-marker02.x));

    Hi All, A little bit of a maths update, i have some code that will allow you to figure out the distance between two coords or movieclips. Woo!

    Download the source below!

    Peace Out
    Bill

  • 4 Comments to “AS3 Math Advanced: Find the Distance Between Two Movieclips or Coordiates with Actionscript 3”

    • Richard Davey on 15 January, 2009

      This is a very common approach to coordinate distances (and of course works with any x/y value, not just movieclips). I have always been concerned about the use of the square root though – due to them being traditionally very expensive calls to make. Modern CPUs of course optimise around them, but as we know not all Flash games are run on the latest Core i7 boxes :)

    • Bill Nunney on 15 January, 2009

      Thanks for your comment. Yeah i’m still experimenting with faster, less resource hungry, ways to accomplish these calcs. I think there’s another approach that uses the Point class (though i’ve heard its worse). Btw nice blog, i think i’ll give it a read :P

    • joyce on 21 July, 2010

      HI the page with the source fla moved
      Where can I find it:?
      Thanks

      • Bill Nunney on 3 August, 2010

        Hi, yeah we had a bit of a messup and my account got deleted and all my files aswell, we restored my tutorials but the files were lost :(
        I’ll have a check for the file when i get home, i’ll msg back if i can find it :P

    Leave a Reply