Question

lets say i have a

var rdGroup:RadioButtonGroup = new RadioButtonGroup();

how can i assign the id

rdGroup.id = "id_RdGroup";

and how can i add this group inside a VBox say

var vbBox:VBox = new VBox();
 vbBox.addElement(rdGroup);

this thing gives error. that property id not found... any solution ?

Was it helpful?

Solution

id is an mxml property which lets you define the name of the object you're creating. So, more or less,

<mx:Button id="myButton" />

is the same as this pseudocode:

public var myButton:Button = new Button();
this.addChild(myButton);

The MXML defined objects are a shortcut. If you don't define the id property (because you will not need to reference a given object in your code) it will be created by the compiler, which chooses an unique name.

That's why there's no id property of the objects and you can't assign it. The id in MXML is the name of your variable in actionscript.

If you're trying to keep handles to more than one variable by String you will need to keep a list of them in some form, one possible solution would be:

var myGroups:Object = new Object();
var rdGroup:RadioButtonGroup = new RadioButtonGroup();
myGroups["id_RdGroup"] = rdGroup;
[...]
vbBox.addElement( myGroups["id_RdGroup"]);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top