我做到了这一点,它运作良好。你确定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事件..或类似的东西 –