4 Replies Latest reply on Jun 24, 2011 9:27 AM by nikos101

    Problems with ClassFactory

    nikos101 Level 2

      Why would the loop    for (var p:String in properties) skip the inner parts for the class User

       

      public function newInstance():*
          {
              var instance:Object = new generator();

       

              if (properties != null)
              {
                  for (var p:String in properties)
                  {
                      instance[p] = properties[p];
                  }
                 }

       

                 return instance;
          }

       

       

      package model.vo
      {
        
          [Bindable]
          public class User
          {
             
         
              public var reportingDivision:String;
              public var jobTitle:String;
              public var lineManagerName:String;

       


              public function User() {
                 
              }
          }
      }

        • 1. Re: Problems with ClassFactory
          UbuntuPenguin Level 4

          What are you trying to do ?  Loop over the properties of a user defined class ?  Too bad...

           

          http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9 b90204-7fcf.html

           

          What you cannot do is iterate through the properties of an object if it is an instance of a user-defined class, unless the class is a dynamic class. Even with instances of dynamic classes, you will be able to iterate only through properties that are added dynamically.

           

          I assume you would have to use something from the flash.utils library ( describeType ) and get your information that way.

          1 person found this helpful
          • 2. Re: Problems with ClassFactory
            nikos101 Level 2

            Ah I see, what a pain that is, wonder why they made it like this?

            • 3. Re: Problems with ClassFactory
              nikos101 Level 2

              the properties object is the data in a renderer  factory.properties=data;

               

              I thought data was an object and it is so when I debug, so strange pengiun  Bro

               

              <s:MXAdvancedDataGridItemRenderer>   
                                              <fx:Script>
                                                  <![CDATA[
                                                      import model.vo.User;
                                                  ]]>
                                              </fx:Script>
                                              <s:Button x="5" label="Edit">
                                                  <s:click>
                                                      <![CDATA[
                                                     
                                                      var factory:ClassFactory=new ClassFactory(User);
                                                      factory.properties=data;
                                                      var user:User = factory.newInstance();
                                                     
                                                      outerDocument.singleUserEditRequest.dispatch(user);
                                                  
                                                      ]]>
                                                  </s:click>
                                              </s:Button>                                       
                                             
                                          </s:MXAdvancedDataGridItemRenderer>

              • 4. Re: Problems with ClassFactory
                nikos101 Level 2

                ah, its a typed object, rats