2 Replies Latest reply on Jul 9, 2007 3:56 AM by ShanthiFlash

    variable scope

    ShanthiFlash
      Hi,

      I am new to oops concept.I have one problem....

      // this is my code .....

      class KnightsMove {
      public var currI:Number = 9;

      .
      .
      .
      .
      eventOnRelease(obj)
      .
      .
      .

      private function eventOnRelease() {

      objName.onRelease = function() {

      trace(currI);

      }
      }


      I have one public variable(currI) if i try to trace it in other private function(eventOnRelease)
      it traces "undefined"


      Thank you,
      shanthi.
        • 1. Re: variable scope
          Pop_Clingwrap Level 1
          the problem is that when you use 'onRelease' the susequent code excecutes from within the object of the onRelease. I have got round this in the past by giving the object a reference to the class beforehand:

          class MyClass{
          public var myVar:Number = 10;

          myClip.classScope = this;
          myClip.onRelease = function(){
          trace(this.classScope.myVar);
          }
          }

          This may not be the best or only way to solve this problem but I am fairly new to the OOP thing as well.
          • 2. variable scope
            ShanthiFlash Level 1
            Hi Pop Clingwrap,

            Thank you for the solution..... it works well.....but still i am not clear whats happening....
            any way thanks again........


            Shanthi.