2010-01-15 34 views

回答

3

当我尝试使用RadioButton做同样的事情时,我最终不得不创建自己的组件。这是我做过什么:

IconRadioButton.mxml

<?xml version="1.0" encoding="utf-8"?> 
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"> 
    <mx:Script> 
    <![CDATA[ 
     import mx.controls.RadioButtonGroup; 

     [Bindable] 
     public var imgLabel:Class; 

     [Bindable] 
     public var groupName:RadioButtonGroup; 

     [Bindable] 
     public var selected:Boolean; 

     [Bindable] 
     public var value:String; 

     ]]> 
    </mx:Script> 
    <mx:RadioButton 
     id="radioBtn" 
     group="{groupName}" 
     groupName="{groupName}" 
     selected="{selected}" 
     label="" 
     value="{value}" 
     visible="{visible}" 
     includeInLayout="{includeInLayout}" /> 
    <mx:Image source="{imgLabel}" click="{radioBtn.selected = true}" /> 
</mx:HBox> 

然后,你可以使用这样的:

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application 
    xmlns:mx="http://www.adobe.com/2006/mxml" 
    xmlns:controls="com.example.controls.*"> 
<controls:IconRadioButton 
    groupName="{group}" 
    imgLabel="{AssetsFactory.getInstance().iconCCVisa}" 
    value="{CreditCardTypes.VISA}" /> 
... 

希望,也许让你开始或给你一些想法。

1

要使用图像作为标签,请使用以下代码。

<mx:HBox width="100%"> 
     <mx:RadioButton groupName="Yield"/> 
     <mx:Image source="@Embed('/scripts/btn_highest.png')"/> 
    </mx:HBox>