views:

13

answers:

1

I'm trying to read xml fields (with actionscript 3), but the problem is that I choose which field to read dynamically. For example, I may need to read test19 or test39 or test12 or anything else.

var value:Number = event.result.test19;
var value:Number = event.result.test39;
var value:Number = event.result.test12;

Is there a way to construct that event.result.test19 part dynamically? Something like the code idea below

var fieldname:String = "test19";
var value:Number = ("event.result." + fieldname) as Number;

I also tried casting as XMLNode ("event.result." + fieldname) as XMLNode but it didn't work.

Anyone knows how this can be done?

+2  A: 
var value:Number = event.result["test19"];
//or 
var t:String = "test19";
var value:Number = event.result[t];

obj.something is same as obj["something"] and obj[a_var] where a_var contains "something."

Amarghosh
Perfect answer Amarghosh. Thank you.
cooper