2 Replies Latest reply on Apr 14, 2011 4:21 PM by new2oop

    How do I store String data to efficiently convert it to an ArrayCollection

    new2oop Level 1

      I've posted another question earlier but this is closer to the real problem:

       

      I have data to go into a Line Chart. It's an attribute in XML, so is available as a String (or as XML). What's the best way to format that data so it easily goes into the ArrayCollection for the Line Chart?

       

      eg.

      This works to add an item to an ArrayCollection:

      expensesAC2.addItem({Month: "May", Profit: 2400, Expenses: 575, Amount: 4567 });

       

      But this doesn't work:

      var settings:String = "Month: 400, Profit: 3400, Expenses: 575, Amount: 4567";

       

      expensesAC2.addItem({settings});

       

       

      The attributes will be defined in the String so I need to define the attributes for the ArrayCollection dynamically, as well as the values.

       

      I've seen an ArrayCollection ToString function, but how do you get a string converted into an ArrayCollection object?

        • 1. Re: How do I store String data to efficiently convert it to an ArrayCollection
          Flex harUI Adobe Employee

          ArrayCollections are faster than XMLListCollections once you take the time

          to convert the data from XML to Object, but often folks just use XML because

          their app runs fast enough.  Then the XML node would look like:

           

              <Item month="May" profit="2400" ... /

          1 person found this helpful
          • 2. Re: How do I store String data to efficiently convert it to an ArrayCollection
            new2oop Level 1

            The XML answer above was very useful and I'll use it in the future, I didn't realise it could be that easy to do, but in this case I need more flexibility so I put the following code in a loop. Heres the code to process one node:

             

            settingsArray = resultXML.game[a].@settings.split(",");

            temp = new Object();

            str = "";

            temp["gameNum"] = String(a);

            for(var b:int = 0; b < settingsArray.length; b++) {

            var attrVal:Array = settingsArray[b].split(":");

            // add game names to temp array

            str = String(attrVal[0]);

            temp[str] = attrVal[1];

            }

            arrayCollection.addItem(temp);

             

             

             

            the data in the 'settings' attribute is stored as:

            settings="lines:4,rows:3"