我做到了這一點,它運作良好。你確定selectedIndex不起作用嗎?
<?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" minWidth="955" minHeight="600">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:ButtonBar
selectedIndex="2" width="400" height="300">
<s:dataProvider>
<s:ArrayCollection>
<fx:String>1</fx:String>
<fx:String>2</fx:String>
<fx:String>3</fx:String>
</s:ArrayCollection>
</s:dataProvider>
</s:ButtonBar>
</s:Application>
編輯:
這可以幫助您?
<?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" minWidth="955" minHeight="600" creationComplete="init()">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.CollectionEvent;
[Bindable]
private var dataSource:ArrayCollection = new ArrayCollection();
private function init():void
{
dataSource = new ArrayCollection(new Array("1","2","3"));
dataSource.addEventListener(CollectionEvent.COLLECTION_CHANGE, collectionEventChange);
dataSource.dispatchEvent(new CollectionEvent(CollectionEvent.COLLECTION_CHANGE));
}
private function collectionEventChange(event:CollectionEvent):void
{
this.btnBar.selectedIndex = 2;
}
]]>
</fx:Script>
<s:ButtonBar id="btnBar" dataProvider="{dataSource}"
width="400" height="300" >
</s:ButtonBar>
</s:Application>
以前沒有用過,但按鈕欄沒有selectedIndex?它有,如果我記得在框架3.0與flex建設者3 –
我試過了,但沒有第一個ButtonBar按鈕保持選中,無論我爲所選的索引放置的值。奇怪的! – Titus
呵呵,試着把它分配給它的數據提供者後,或者可能在creationcomplete事件中,只是爲了避免技術問題..你嘗試點擊一個按鈕,並在那一刻改變selectedIndex像myButtonBar.selectedIndex = 1 ;如果它的工作..是selectedIndex正在分配之前,你的數據提供者被分配.. ..你需要分配它之後,不knwo如果它有dataproviderChanged事件..或類似的東西 –