2 Replies Latest reply on Oct 7, 2007 7:11 AM by clbeech

    Flash 8 scope question

    caseymanx Level 1
      In the following class can someone tell me how I would call the doSomething() function from within myObject.onMouseDown=function()?



      class Practice extends MovieClip {
      var myObject:Object;
      //
      public function Practice() {
      myObject = new Object();
      myObject.onMouseDown = function() {
      // call doSomething here
      doSomething();
      };
      Mouse.addListener(myObject);
      }
      //
      public function doSomething() {
      trace("did something");
      }
      }
        • 1. Re: Flash 8 scope question
          caseymanx Level 1
          Figured it out.

          class Practice extends MovieClip {
          var myObject:Object;
          //
          public function Practice() {
          myObject = new Object();
          //
          var me:Practice = this;
          //
          myObject.onMouseDown = function() {
          // call doSomething here
          me.doSomething();
          };
          Mouse.addListener(myObject);
          }
          //
          public function doSomething() {
          trace("did something");
          }
          }
          • 2. Re: Flash 8 scope question
            clbeech Level 3
            there you that's it, you just need to define 'this' outside the onMouseDown method to refer to the class scope. However there are a acouple of things you could do to streamline this a little.