3 Replies Latest reply on Jun 20, 2011 3:34 AM by Claudiu Ursica

    Can't get variables when using describeType

    daphna_dev

      Hi

       

      I'm using as3.0 (yes, i know, should upgrade)

       

      I can't seem to get the variables of my class when i use describeType(), so i created a very simple dummy class:

      package testpackage.test
      {
          public class TestClass
          {
              var a:String;
              var b:Array;
             
              public function TestClass()
              {
              }
             
          }
      }

      and created an instance:

       

      var someObj:TestClass = new TestClass();
      someObj.a = "text";
      someObj.b = new Array();
      someObj.b.push("array_obj_1");
      someObj.b.push("array_obj_2");

      but when i try to get the classInfo:
      var classInfo:XML = describeType(someObj);

       

      I get this:

      <type name="testpackage.test::TestClass" base="Object" isDynamic="false" isFinal="false" isStatic="false">
        <extendsClass type="Object"/>
      </type>

       

      With no variables....

       

      Can someone please help?

      (btw in the more complex class i had i got the accessors and the methods, just not the variables)

       

      Thanks

        • 1. Re: Can't get variables when using describeType
          Claudiu Ursica Level 4

          Since you are not supplying any access modifier, your variable will be defaulted to protected. Unlike Java action script reflection is not able to perform on private vars. You need to have them public.

           

          Or expose at least a public accessor to show up in describeType().

           

           

          C

          1 person found this helpful
          • 2. Re: Can't get variables when using describeType
            daphna_dev Level 1

            ok. i've changed it and now my class has accessors and the result is:

             

            <type name="testproject.test::TestClass" base="Object" isDynamic="false" isFinal="false" isStatic="false">
              <extendsClass type="Object"/>
              <accessor name="a" access="readwrite" type="String" declaredBy="testproject.test::TestClass"/>
              <accessor name="b" access="readwrite" type="Array" declaredBy="testproject.test::TestClass"/>
            </type>

             

            i see the accessors but not the variables.


            is this how it should work? can i only see variables if they are public? is there another way to see the private ones?

             

            i was trying to perform deep copy...

            (i know about ObjectUtil.copy, i wanted something general in which i don't have to register all related classes)

            • 3. Re: Can't get variables when using describeType
              Claudiu Ursica Level 4

              Depending on how you declare them they will show up or not on different sections of the xml generated by describeType. I looking at an xml is not your final goal here. Can you share some more details so I have a better picture?

               

              C