I'm developing a flex application and I want to access a component by using it's id. I know I must use .property of the component. The problem is I have the component Id in a String var and now I don't know how to access to it's properties. Does anybody know what I have to do?
A:
In actionscript you can do something like this[$var].property i believe
seventy6
2009-09-07 16:09:46
obj["property"].subProperty.
Glenn
2009-09-07 21:01:31
I have already tried that but it doesn't work.
Kezern
2009-09-08 09:55:22
+1
A:
If you set the string variable to equal the component ID, you cannot access any properties, because it is now a string and not an object. How are you setting the string variable? You need to access the component itself and setting the ID to a string will not accomplish this. You must set the property using the object itself, and not a string representation of it's ID. Paste your code if you would like me to take a look.
To set the component property itself the syntax would be myComponent.myProperty = myValue
To retrieve the value myValue = myComponent.myProperty
Jeff Pinkston
2009-09-08 21:55:03
So the only possibility is to access throw the component itself? Lets suppose I have a label and it's id is "label1". I can change the text with label1.text="hello world". But If I have the id of the label in a string, There is no way to access to text property?
Kezern
2009-09-09 09:04:22
Correct - if you have the id in a string, it doesn't actually know that it is an id of anything, it just treats it like any other string and not as an identifier. The only way to access the label's text property is by accessing the label object itself.
Jeff Pinkston
2009-09-09 13:36:44