- Adobe Flex 教程
- Flex - 首頁
- Flex - 概述
- Flex - 環境
- Flex - 應用程式
- Flex - 建立應用程式
- Flex - 部署應用程式
- Flex - 生命週期階段
- Flex - 使用 CSS 樣式化
- Flex - 使用皮膚樣式化
- Flex - 資料繫結
- Flex - 基本控制元件
- Flex - 表單控制元件
- Flex - 複雜控制元件
- Flex - 佈局面板
- Flex - 視覺效果
- Flex - 事件處理
- Flex - 自定義控制元件
- Flex - RPC 服務
- Flex - FlexUnit 整合
- Flex - 除錯應用程式
- Flex - 國際化
- Flex - 列印支援
- Adobe Flex 資源
- Flex - 快速指南
- Flex - 有用資源
- Flex - 討論
Flex - 單選按鈕控制元件
簡介
單選按鈕控制元件允許使用者在一組互斥的選擇中做出單一選擇。
類宣告
以下是spark.components.RadioButton類的宣告:
public class RadioButton
extends ToggleButtonBase
implements IFocusManagerGroup
公共屬性
| 序號 | 屬性和描述 |
|---|---|
| 1 | enabled : Boolean [覆蓋] 如果RadioButtonGroup已啟用並且RadioButton本身已啟用,則RadioButton元件已啟用。 |
| 2 | group : RadioButtonGroup 此RadioButton所屬的RadioButtonGroup元件。 |
| 3 | groupName : String 指定此RadioButton元件所屬組的名稱,或者如果此RadioButton是RadioButtonGroup元件定義的組的一部分,則指定RadioButtonGroup元件的id屬性的值。 |
| 4 | value : Object 與RadioButton元件關聯的可選使用者定義值。 |
公共方法
| 序號 | 方法和描述 |
|---|---|
| 1 | RadioButton() 建構函式。 |
繼承的方法
此類繼承自以下類的方法:
- 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 單選按鈕控制元件示例
讓我們按照以下步驟,透過建立一個測試應用程式來檢查在 Flex 應用程式中使用RadioButton控制元件:
| 步驟 | 描述 |
|---|---|
| 1 | 按照Flex - 建立應用程式章節中說明的那樣,在一個名為HelloWorld的專案中建立一個名為com.tutorialspoint.client的包。 |
| 2 | 修改HelloWorld.mxml,如下所述。保持其餘檔案不變。 |
| 3 | 編譯並執行應用程式,以確保業務邏輯按要求工作。 |
以下是修改後的 mxml 檔案src/com.tutorialspoint/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/tutorialspoint/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 - 建立應用程式章節中一樣,在普通模式下編譯並執行應用程式。如果您的應用程式一切正常,它將產生以下結果:[ 線上嘗試 ]
flex_form_controls.htm
廣告