PDA

View Full Version : How to update ArrayCollection at runtime??


Pratap
05-21-2008, 07:15 AM
Am facing some problem with arraycollection..
am having an arraycolelction like this...
var dpHierarchy:ArrayCollection = new ArrayCollection([
{Region:"Demand1"},
{Region:"Demand2"},
{Region:"Demand3"},
{Region:"Demand4"}]

now what am looking for is.. how to update this arraycollection at runtime using actions script?
i need to update this array colelction something like this...

var dpHierarchy:ArrayCollection = new ArrayCollection([
{Region:"Demand1", Year:"2008"},
{Region:"Demand2", Year:"2008"},
{Region:"Demand3", Year:"2008"},
{Region:"Demand4", Year:"2008"}]

How to add Year field in to existing arraycollection like shown in about example..

thanks in advance
Pratap

drkstr
05-21-2008, 06:16 PM
You can loop through and assign the property to each object.

for each( var item:Object in dpHierarchy ) {
trace(item.Year); // null
item.Year = 2008;
trace(item.Year); // 2008
}

Dynamic objects can have properties assigned at runtime.

Best Regards,
~Aaron

Pratap
05-22-2008, 06:35 AM
hi Aaron,

its workign.
Thanks...:)

Pratap
05-22-2008, 10:49 AM
hi.. s this works fine..

Any idea how to make item name dynamic..
something like..

private function updateDP():void {
for(var i:int=0;i<10;i++)
{
arr[0].Year = "2008"; /// How to add that 'i' value over here?
}
}

i wanna add Year1, Year2, Year3 --------- like this...
is its possible??

thanks in Advance
PRatap

Pratap
05-22-2008, 12:52 PM
hey got it...

just i need to give

dpHierarchy[0]["Year"] = "2008";

:-)

drkstr
05-22-2008, 03:35 PM
Just a kindly word of advice...

I'm not sure of your exact purposes, but it seems like you are trying to turn a property into a variable. Why the extra number at the end? It seems like this would needlessly complicate things.

Best Regards,
~Aaron

Pratap
05-23-2008, 10:31 AM
hi thanks for advice..

In my current project content in array get generated dynamically at runtime.
so i need to add content to arraycolelction at runtime.

And i am not going to use "Year" over there. just for example am using that word.

Regards
Pratap