开发者

how to assign an "id" to a RadioButtonGroup using actionscript?

lets say i have a

var rdGroup:RadioButtonGroup = new RadioButtonGro开发者_运维知识库up();

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 ?


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"]);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜