2 Replies Latest reply on Nov 27, 2008 1:58 AM by Bilbo1984

    Create object in runtime phase

    Bilbo1984
      Hi all,

      i would create a data grid and pass it an array...

      for example th array looks like this:

      <mx:Array id="planets">
      <mx:Object planet="Mercury" kind="Terrestrial"
      year_duration="0.24" moons="0" cost="1250" />
      <mx:Object planet="Venus" kind="Terrestrial"
      year_duration="0.62" moons="0" cost="2400" />
      <mx:Object planet="Jupiter" kind="Gas giant"
      year_duration="11.86" moons="63" cost="500" />
      <mx:Object planet="Eris" kind="Ice dwarf"
      year_duration="557" moons="1" cost="3000" />
      </mx:Array>

      and datagrid takes dataprovider property equal to "planets".
      ok it'all ok but how can i create an object with those properties (planet, kind,...) and values dinamically?

      for example i would create a method that returns a value and inserts it in a properties in the object array

      <mx:Object planet = method1() kind = method2() />

      maybe i have to create MyClass that extends Objects...infact i see that the dataprovider propertiy is an OBject class...i dont't know...

      i appreciate any help..thanks a lot



        • 1. Re: Create object in runtime phase
          atta707 Level 2
          Sure you can. Especially when Object class is Dyanmic. That is, you can add properties to it dynamically.

          In a script tag do something like:

          var mercury:Object = new Object();
          mercury.kind = "Terrestrial";
          mercury.year_duration = "0.24";
          ....
          myarray.push(mercury);

          var eris:Object = new Object();
          eris.
          ...

          Of course, if you create your own class called something like Planet would make your code more readable and easier to maintain.

          ATTA
          • 2. Re: Create object in runtime phase
            Bilbo1984 Level 1
            Thanks for the reply...

            an other question

            i'have an xml file like this:

            > <root>
            > <week id="1">
            > <production day="monday">
            > <book>23</book>
            > <cds>49</cds>
            > </production>
            > <production day="tuesday">
            > <book>56</book>
            > <cds>68</cds>
            > </production>
            > ...other weeks production...
            > </week>
            > </root>

            i would create objects for every products: book and cds

            for example for book

            <mx:Object monday="23" tuesday="56" />

            and for cds

            <mx:Object monday="56" tuesday="68" />

            can you suggest a procedure to rich this result?

            thanks in advance

            Regards

            Bilbo