使用 ActionScript 3.0 组件 |
|
|
|
| 使用 UI 组件 > 使用 RadioButton > 创建具有 RadioButton 的应用程序 | |||
以下过程解释了如何在创作时将 RadioButton 组件添加到应用程序。在此示例中,使用 RadioButton 表示是非问题。RadioButton 的数据显示在 TextArea 中。
创建具有 RadioButton 组件的应用程序:
yesRb.label = "Yes";
yesRb.value = "For";
noRb.label = "No";
noRb.value = "Against";
yesRb.move(50, 100);
noRb.move(100, 100);
aTa.move(50, 30);
noRb.addEventListener(MouseEvent.CLICK, clickHandler);
yesRb.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void {
aTa.text = event.target.value;
}
下面的示例使用 ActionScript 创建三个 RadioButton,分别表示红色、蓝色和绿色,并绘制一个灰色的框。每个 RadioButton 的 value 属性指定与此按钮关联的颜色的十六进制值。当用户单击其中一个 RadioButton 时,clickHandler() 函数将调用 drawBox(),同时传递此 RadioButton 的 value 属性中的颜色值来为此框着色。
使用 ActionScript 创建 RadioButton:import fl.controls.RadioButton;import fl.controls.RadioButtonGroup;var redRb:RadioButton = new RadioButton();var blueRb:RadioButton = new RadioButton();var greenRb:RadioButton = new RadioButton();var rbGrp:RadioButtonGroup = new RadioButtonGroup("colorGrp");var aBox:MovieClip = new MovieClip();drawBox(aBox, 0xCCCCCC);addChild(redRb);addChild(blueRb);addChild(greenRb);addChild(aBox);redRb.label = "Red";redRb.value = 0xFF0000;blueRb.label = "Blue";blueRb.value = 0x0000FF;greenRb.label = "Green";greenRb.value = 0x00FF00;redRb.group = blueRb.group = greenRb.group = rbGrp;redRb.move(100, 260);blueRb.move(150, 260);greenRb.move(200, 260);rbGrp.addEventListener(MouseEvent.CLICK, clickHandler);function clickHandler(event:MouseEvent):void {drawBox(aBox, event.target.selection.value);}function drawBox(box:MovieClip,color:uint):void {box.graphics.beginFill(color, 1.0);box.graphics.drawRect(125, 150, 100, 100);box.graphics.endFill();}
有关详细信息,请参阅《ActionScript 3.0 语言和组件参考》中的 RadioButton 类。
|
|
|
|