I'm not sure what obj1, obj2, etc. are in your example. But if they're
instance variables in your class, then
obj1.foo
this.obj1.foo
this.obj1["foo"]
this["obj1"].foo
this["obj1"]["foo"]
are all equivalent. So you can look up a property by name on an object
by name as
this[object_name][property_name]
Keep in mind that when you write a class in MXML, the id's of MXML tags
become instance variables of the class. For example, if you have
<mx:Button id="b" label="OK"/>
then
this["b"]["label"]
will be "OK".
- Gordon
________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of tedgies
Sent: Friday, May 25, 2007 9:35 PM
To: [email protected]
Subject: [flexcoders] Re: Treat a string as a reference to an object?
Thanks Gordon,
Following your example, can you create the name of the root object
dynamically and have it be treated as a valid property reference at
runtime?
example: If i wanted obj1.foo, obj2.foo, or objsome_string.foo
thanks,
Ted
--- In [email protected] <mailto:flexcoders%40yahoogroups.com>
, "Gordon Smith" <[EMAIL PROTECTED]> wrote:
>
> > I was wondering if Flex/Actionscript allows you to create
references
> > to object properties on the fly with a dynamically created
string.
>
> Yes. If obj is an object and s is the String "foo", then obj[s] is
> obj.foo.
>
> - Gordon
>
> ________________________________
>
> From: [email protected] <mailto:flexcoders%40yahoogroups.com>
[mailto:[email protected] <mailto:flexcoders%40yahoogroups.com>
] On
> Behalf Of tedgies
> Sent: Friday, May 25, 2007 10:43 AM
> To: [email protected] <mailto:flexcoders%40yahoogroups.com>
> Subject: [flexcoders] Treat a string as a reference to an object?
>
>
>
> Hi,
>
> I was wondering if Flex/Actionscript allows you to create
references
> to object properties on the fly with a dynamically created string.
> For example i would like to add a new series to a chart series at
> runtime and dynamically create the reference to dataprovider (an
> httpservice) with a string.
>
> var numJournals:String = new String;
> numJournals = 3;
> var series = chartC.series;
> var dataXMLStr:String = new String;
> var newSeries:LineSeries = new LineSeries;
> dataXMLStr = "series" + numJournals + ".lastResult.item";
> newSeries.dataProvider = dataXMLStr
> ....
> series.push(newSeries)
> chartC.series = series;
>
> The problem is that on the 7th line above newSeries does not
> recognize dataXMLStr as a reference to my httpservice dataprovider.
> So is there a function i can use to make dataXMLStr appear as a
> reference to my dataprovider, e.g. so flex will read:
>
> newSeries.dataProvider = series3.lastResult.item
>
> thanks,
> Ted
>