RadioButton

优质
小牛编辑
124浏览
2023-12-01

介绍 (Introduction)

RadioButton控件允许用户在一组互斥选项中做出单一选择。

Class 声明 (Class Declaration)

以下是spark.components.RadioButton类的声明 -

public class RadioButton 
   extends ToggleButtonBase
      implements IFocusManagerGroup

公共属性 (Public Properties)

S.No属性和描述
1

enabled : Boolean

[override]如果启用了RadioButtonGroup并且启用了RadioButton本身,则启用RadioButton组件。

2

group : RadioButtonGroup

RadioButton所属的RadioButtonGroup组件。

3

groupName : String

指定此RadioButton组件所属的组的名称,或者如果此RadioButton是RadioButtonGroup组件定义的组的一部分,则指定RadioButtonGroup组件的id属性的值。

4

value : Object

与RadioButton组件关联的可选用户定义值。

公共方法 (Public Methods)

S.No方法和描述
1

RadioButton()

构造函数。

方法继承 (Methods Inherited)

该类继承以下类中的方法 -

  • spark.components.supportClasses.ToggleButtonBase
  • spark.components.supportClasses.ButtonBase
  • spark.components.supportClasses.SkinnableComponent
  • mx.core.UIComponent
  • mx.core.FlexSprite
  • flash.display.Sprite
  • flash.display.DisplayObjectContainer
  • flash.display.InteractiveObject
  • flash.display.DisplayObject
  • flash.events.EventDispatcher
  • Object

Flex RadioButton控件示例

让我们按照以下步骤通过创建测试应用程序来检查Flex应用程序中RadioButton控件的使用情况 -

描述
1cn.xnip.client包下创建一个名为HelloWorld的项目,如Flex - Create Application一章中所述。
2修改HelloWorld.mxml ,如下所述。 保持其余文件不变。
3编译并运行应用程序以确保业务逻辑按照要求运行。

以下是修改后的mxml文件src/cn.xnip/HelloWorld.mxml

<?xml version = "1.0" encoding = "utf-8"?>
<s:Application xmlns:fx = "http://ns.adobe.com/mxml/2009"
   xmlns:s = "library://ns.adobe.com/flex/spark"
   xmlns:mx = "library://ns.adobe.com/flex/mx"
   width = "100%" height = "100%" minWidth = "500" minHeight = "500">
   <fx:Style source = "/com/xnip/client/Style.css" />
   <fx:Script>
      <![CDATA[
         [Bindable]
         private var selectedOption:String = "";
         protected function option_clickHandler(event:MouseEvent):void {
            var radioButton:RadioButton = event.target as RadioButton;
            switch (radioButton.id) {
               case option1.id:
                  selectedOption = option1.label;
                  break;
               case option2.id:
                  selectedOption = option2.label;
                  break;
               case option3.id:
                  selectedOption = option3.label;
                  break;
               case option4.id:
                  selectedOption = option4.label;
                  break;
            }			
         }
      ]]>
   </fx:Script>
   <s:BorderContainer width = "550" height = "400" id = "mainContainer" 
      styleName = "container">
      <s:VGroup width = "100%" height = "100%" gap = "50" 
         horizontalAlign = "center" verticalAlign = "middle">
         <s:Label id = "lblHeader" text = "Form Controls Demonstration" 
            fontSize = "40" color = "0x777777" styleName = "heading" />
         <s:Panel id = "radioButtonPanel" title = "Using RadioButton" 
            width = "420" height = "200" >
            <s:layout>
               <s:VerticalLayout  gap = "10" verticalAlign = "middle"
                  horizontalAlign = "center" />	
            </s:layout>
            <s:RadioButton groupName = "options" id = "option1" 
               label = "item #1" width="150" 
               click = "option_clickHandler(event)" />
            <s:RadioButton groupName = "options" id = "option2" 
               label = "item #2" width="150" 
               click = "option_clickHandler(event)" />
            <s:RadioButton groupName = "options" id = "option3" 
               label = "item #3" width="150" 
               click = "option_clickHandler(event)" />
            <s:RadioButton groupName = "options" id = "option4" 
               label = "item #4" width = "150" 
               click = "option_clickHandler(event)" />
            <s:Label id = "selectedOptionLabel" fontWeight = "bold" 
               text = "Item selected: {selectedOption}" width = "150" />
         </s:Panel>
      </s:VGroup>	 
   </s:BorderContainer>	
</s:Application>

一旦准备好完成所有更改,让我们像在Flex - Create Application章节中那样在正常模式下编译和运行应用程序

Flex单选按钮控制