运行以下代码
<?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"
minWidth="955" minHeight="600">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import spark.events.IndexChangeEvent;
private function changeHandler(event:IndexChangeEvent):void {
myTA.text="Selected button index: " +
String(event.newIndex) + "\n" +
"Selected button label: " +
event.target.selectedItem;
}
]]>
</fx:Script>
<s:ButtonBar change="changeHandler(event)">
<s:ArrayList>
<fx:String>test1</fx:String>
<fx:String>test2</fx:String>
<fx:String>test3</fx:String>
</s:ArrayList>
</s:ButtonBar>
<s:TextArea id="myTA" width="250" height="100"/>
</s:Application>
会发现点击一个按钮,该按钮成为选中状态,如果再点击这个按钮,按钮选中状态消失,下面显示为
Selected button index: -1
Selected button label: undefined
可是这个缺德组件的文档里,根本就没说选中按钮再次点击会取消选中状态.
解决方案是
1 用 TabBar
<s:TabBar change="changeHandler(event)">
<s:ArrayList>
<fx:String>bar1</fx:String>
<fx:String>bar2</fx:String>
<fx:String>bar3</fx:String>
</s:ArrayList>
</s:TabBar>
2 修改requireSelection属性,保证至少有一个选中.
<s:ButtonBar change="changeHandler(event)" requireSelection="true">
<s:ArrayList>
<fx:String>test1</fx:String>
<fx:String>test2</fx:String>
<fx:String>test3</fx:String>
</s:ArrayList>
</s:ButtonBar>
adobe文档里这么重要的事情根本不提,反而全是无关紧要,鸡毛蒜皮的事儿,对adobe公司的能力越来越感到怀疑.事实上,用了flash builder就很惊讶,eclipse那么好用的IDE,怎么flash builder在eclipse基础上开发,反而eclipse的一些好用的功能丢失的干干净净.