1 Reply Latest reply on Jun 23, 2014 4:32 PM by jbowden

    Scope Issues.


      One of the first "help" items on Adobe (Adobe Edge Animate JavaScript API v0.1.7) is


      function handleClick(){


      window.handleClick = function (){}


      howver I see all kinds of discussions dealing with functions using this syntax...


      sym.handleClick = function(){


      which seems to be exactly what you are told NOT to do (assuming window and sym are at least similar concepts)....Can someone clarify?

        • 1. Re: Scope Issues.
          jbowden Adobe Employee

          Hi there,


          Great question. Using the examples above:


          • function handleClick(){}  - is scoped to the element event on which it exists. You can only call this from the same element event - anywhere else is out of scope.
          • window.handleClick = function (){}  - is scoped to Javascript's browser window object (global). Best practices are to not attach variables or functions to a global object. This would also include declaring a variable without the var keyword (not recommended).
          • sym.handleClick = function(){}  - is scoped to the symbol. Any element/handler within the same symbol can call it. Outside of the symbol, you can get to it using getSymbol. This is the safest "global" variable to use.


          If anything's unclear, feel free to ask.




          1 person found this helpful