开发者

How do I set the properties or fields of the object dynamically in flex

开发者 https://www.devze.com 2023-03-19 16:22 出处:网络
I have an array containing names lets say, var myArray:Array=new Array(\"name1\",\"name2\",\"name3\");

I have an array containing names lets say,

var myArray:Array=new Array("name1","name2","name3");

Now I want to use the array values as the object properties by iterating through the arr开发者_如何学运维ay I meant I want the object to have name1,name2,name3 as the properties,

var myObject:Object=new object();
for(var i:int=0; i<myArray.length; i++){
myObject[myArray[i]]="something";
}

but this does not give me the required result, it sets the object property as myArray[i] i.e, whatever I give inside the square braces is taken as a string in this case.I want the output to be,

myObject[name1]="something"
myObject[name2]="something" 
myObject[name3]="something" 

but instead it gives the output as

myObject[myArray[i]]="something"

Any ideas how to do this?


Not sure I fully understand, but I think you've accomplished your goal.

In the debugger, I see:

How do I set the properties or fields of the object dynamically in flex

Was this not what you want?

I believe what you've stated is equivalent.

0

精彩评论

暂无评论...
验证码 换一张
取 消