PDA

View Full Version : Dynamic retrieval of array-nested object attributes?


metahipster
10-18-2005, 10:59 PM
Here's the basic setup:
array contains multiple objects
each object has the same properties, though different values stored in their various properties.

Thus array[0].color could return something like "blue".
array[0].radius might return 50.

Now, I want to vary how I'm asking for the property... sometimes I might want radius, sometimes color.

I thought it would be something like
attrib="color";
trace(array[0][attrib]);

That doesn't seem to work. What am I doing wrong? If my logic is sound, I'll post some code to follow up... It's mighty convoluted so hopefuly you can answer me purely on a conceptual level using the above example to guide the syntax.

Thanks!

metahipster
10-18-2005, 11:04 PM
hrm - I've confirmed that my logic is sound via this code:

arr = new Array();
arr[0] = new Object();
arr[0].color = "blue";
arr[0].radius = 50;
trace("array[0] color="+arr[0].color);
dynamicProp="color";
trace("array[0] dynamic color="+arr[0][dynamicProp]);


I will look at my stuff a bit closer to see what's up. Maybe I'm spelling the property wrong or something.

durie
12-01-2005, 03:38 AM
Can any one tell me if can have a array equal a date and when the date is checked it goes to the corrisponding array named with that date and dynamicly pulls a .html file

like
if date == 011205
then goto arry 011205

in that arry it has the value of fact1.html


any ideas would be great
Durie