flex 单选框,复选框 下拉框,及颜色选择框。
现在的版本已经升级到flex4 了,我在网上找的部分代码还是flex 3 的,因为代码升级的原因,大部分的flex3代码是可以运行的,还有一部分内容不能运行了,还要做一些改动或升级。最主要的区别是flex 3 默认主题是halo,而flex4 已经升级为spark,相应的标记也由mx升级为s.详细的区别还要再查找资料。
本系列的源码主要来自于网上,同时,还有来自于《自学flex》一书中。
<?xml version="1.0" encoding="utf-8"?>
<!--转:http://blog.sina.com.cn/s/blog_6dd3fe2e0100pa6v.html-->
<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" minWidth="955" minHeight="600">
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<!--flex3 中的script 要用mx flex4中要用到fx-->
<fx:Script>
<![CDATA[
protected function button1_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
var s :String;
s="";
if(cbVideoGames.selected)
{
s = s + cbVideoGames.label;
}
if(cbFishing.selected)
{
s = s + cbFishing.label;
}
mx.controls.Alert.show(s);
}
public function showMsg(msg:String):void
{
mx.controls.Alert.show(msg);
}
]]>
</fx:Script>
<mx:Panel width="400" height="150" title="Profile">
<!-- *** CHECKBOX EXAMPLE *** -->
<mx:HBox>
<mx:Label text="Your hobbies:"/>
<mx:CheckBox id="cbVideoGames" label="Video Games"
click="showMsg('Video Games is ' + cbVideoGames.selected)"/>
<mx:CheckBox id="cbFishing" label="Fishing"
click="showMsg('Fishing is ' + cbFishing.selected)"/>
</mx:HBox>
<!-- *** RADIO BUTTON EXAMPLE *** -->
<mx:HBox>
<mx:Label text="Do you like spam:"/>
<!-- This is going to cause two popups occur. -->
<!-- The click event on the radiobutton will fire -->
<!-- And then the itemClick on the radio button group will fire -->
<!-- The RadioButtonGroup is optional. -->
<!-- Use it when you need to call a single function regardless -->
<!-- of radio button -->
<mx:RadioButtonGroup id="Spam"
itemClick="showMsg('User picked ' + event.currentTarget.selectedValue)"/>
<mx:RadioButton id="rbYes" value="Yes" groupName="Spam"
click="showMsg('Yes')" label="Yes"/>
<mx:RadioButton id="rbNo" value="No" groupName="Spam"
click="showMsg('No')" label="No"/>
</mx:HBox>
<!-- *** COMBOBOX AND COLORPICKER EXAMPLE *** -->
<mx:HBox>
<mx:Label text="Favorite car maker:"/>
<mx:ComboBox id="combo"
change="showMsg('Favorite car is ' + event.currentTarget.selectedItem)">
<!--flex3 中的array 要用mx flex4中要用到fx-->
<fx:Array>
<fx:String>Ferrari</fx:String>
<fx:String>Porsche</fx:String>
<fx:String>Hyundai</fx:String>
</fx:Array>
</mx:ComboBox>
<mx:Label text="With the color of:"/>
<mx:ColorPicker id="clr"
change="showMsg('Color ' + event.currentTarget.selectedColor)"/>
</mx:HBox>
<s:Button label="按钮" click="button1_clickHandler(event)"/>
</mx:Panel>
</s:Application>