views:

30

answers:

2

I have a string which is ultimately the id of a CheckBox.

What I need to be able to do is to access the CheckBox's properties from the string

var myCheckBox:Object; var myString:String;

myString = "checkbox_1"

myCheckBox = Object(myString); ?!?!

... and then I'd need to get to myCheckBox.selected, and myCheckBox.label etc

A: 

If you know what DisplayObjectContainer (e.g. Sprite, MovieClip) the CheckBox is inside you can use getChildByName.

Unfortunately if you are using Flex containers (like Group) there is no function getElementByName(). There is getElementAt so you could write a loop that iterates over all of a Groups elements until it encounters one that matches the name you have.

James Fassett
+2  A: 

easier answer:

if(this.hasOwnProperty(myString) && this[myString] is CheckBox) {
    myCheckBox = this[myString] as CheckBox
}

It's a bit of overcoding (since the as keyword will return a null if it's not a checkbox and you could better handle it that way with potentially less code), but that should do ya. Best of luck.

jeremy.mooer
Doesn't need "this.hasOwnProperty()", as "this[myString]" will just return undefined if it's not available, but this is the right answer :)
Sophistifunk
Amarghosh