views:

47

answers:

1

In ActionScript I have string as

str="subject,r1,r2:a,b:1,2:3,4";

dynamically i have split this string and build array collection as given below

arraycoll.addItem({subject:a ,r1:1,r2:3});

this example of one set

the arraycollection should be built dynamic i have tried but not successful

+2  A: 
var str:String ="subject,r1,r2:a,b:1,2:3,4";
var parts:Array = str.split(":");
var props:Array = parts[0].split(",");
var count:Number = parts[1].split(",").length;
var items:Array = [];
var values:Array = [];
var i:Number, j:Number;
for(i = 0; i < props.length; i++)
  values.push(parts[i + 1].split(",")); 
for(i = 0; i < count; i++)
{
  items.push({});
  for(var j = 0; j < props.length; j++)
  {
    items[i][props[j]] = values[j][i];
  }
}
var arCol:ArrayCollection = new ArrayCollection(items);
Amarghosh
really good one
dpaksp