1 Reply Latest reply on Oct 9, 2007 8:18 AM by Chunick

    basic Math

    Aquilonian Level 1
      Im doing my best to understand Director
      My question is, in flash, we have an object Math for things like sqrt, atan2, whatever
      Whats the equivalent of those in Director?For example, if i have two points, how is the code to calculate their distance?
        • 1. Re: basic Math
          Chunick Level 3
          there's no Math object in Lingo, but MX2004 supports ECMAScript (essentially Javascript). You could use it's syntax for your math calculations by switching from 'Lingo' to 'Javascript' from the dropdown in the top-left of the script window.

          From the help here's the two syntaxes:

          -- Lingo syntax
          atan (number)

          // JavaScript syntax

          specifically, for distance you would have to roll your own code or get tricky and use the built-in vector method, .distanceTo() in lingo, ie:

          -- in message window try this:
          pt1 = point(12, 53)
          pt2 = point(21, 176)

          put vector(pt1.locH, pt1.locV, 0).distanceTo(vector(pt2.locH, pt2.locV, 0))

          from this you can create a custom handler (function) that will allow you to pass vectors and points interchangeably:

          on mDistance v1, v2
          if ilk(v1) = #point then
          v1 = vector(v1.locH, v1.locV, 0)
          else if ilk(v1) <> #vector then
          return VOID
          end if
          if ilk(v2) = #point then
          v2 = vector(v2.locH, v2.locV, 0)
          else if ilk(v2) <> #vector then
          return VOID
          end if
          return v1.distanceTo(v2)