2 Replies Latest reply on May 10, 2006 8:13 AM by TimSymons

    about class problem?

    tyrande1982
      class xmlLoad {
      private var xmlName:String;
      public var booleanLoad:Boolean;
      private var xml:XML;

      public function xmlLoad(newXmlName:String) {
      xmlName = newXmlName;
      booleanLoad = false;
      xml = new XML();
      xml.load(xmlName);
      xml.onLoad = function(success:Boolean) {
      if(success){
      booleanLoad=true;
      trace(success);
      }else{
      trace(success);
      }
      };
      }
      public function get booleanL():Boolean {
      return booleanLoad;
      }
      }
      in the code,the sameness name booleanLoad is not one variable;
        • 1. Re: about class problem?
          Peter Lorent Level 2
          Mind the scope.

          public function xmlLoad(newXmlName:String) {
          var thisObj:xmlLoad=this;
          xmlName = newXmlName;
          booleanLoad = false;
          xml = new XML();
          xml.load(xmlName);
          xml.onLoad = function(success:Boolean) {
          if(success){
          thisObj.booleanLoad=true;
          trace(success);
          }else{
          trace(success);
          }
          };
          }
          • 2. Re: about class problem?
            TimSymons Level 1
            This is a scoping issue. You will have to do one of the following:

            Method 1:

            Replace this

            xml.onLoad = function(success:Boolean) {
            if(success){
            booleanLoad=true;
            trace(success);
            }else{
            trace(success);
            }
            };

            with
            var thisClass:xmlLoad = this; // this helps with the scoping by leeting you refer back to this class for inline functions.
            xml.onLoad = function(success:Boolean) {
            if(success){
            thisClass.booleanLoad=true;
            trace(success);
            }else{
            trace(success);
            }
            };

            Method 2 (I prefer this method): see attached code.

            Hope this helps you out.