Actionscript 3 如何在默认选中的按钮栏中创建按钮?
我有一个火花按钮杆,我把它和一个ViewStack正确地连接起来了。当前,当我运行应用程序(AIR)时,默认情况下会选择ButtonBar中的第一个按钮。如何在默认情况下选择第二个按钮Actionscript 3 如何在默认选中的按钮栏中创建按钮?,actionscript-3,apache-flex,Actionscript 3,Apache Flex,我有一个火花按钮杆,我把它和一个ViewStack正确地连接起来了。当前,当我运行应用程序(AIR)时,默认情况下会选择ButtonBar中的第一个按钮。如何在默认情况下选择第二个按钮 <mx:ViewStack id="viewStack"> <s:NavigatorContent id="Page 1"> <!-- Other stuff in here --> </s:NavigatorContent>
<mx:ViewStack id="viewStack">
<s:NavigatorContent id="Page 1">
<!-- Other stuff in here -->
</s:NavigatorContent>
<s:NavigatorContent id="Page 2">
<!-- Other stuff in here -->
</s:NavigatorContent>
</mx:ViewStack>
<s:ButtonBar dataProvider="{viewStack}" selectedIndex="1"></s:ButtonBar>
我这样做了,效果很好。您确定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>
1.
2.
3.
编辑:
这对你有帮助吗
<?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>
在初始化组件和填充按钮栏后,需要设置所选索引。buttonbar仅在检测到其数据提供程序中的更改时创建按钮(在绑定后将changewatcher附加到该按钮) 这就是为什么Mr.的修订答案中包含了在CollectionEvent侦听器中设置所选索引的内容
更健壮的解决方案是将buttonbar子类化并对其进行调整,添加defaultSelectedIndex成员,或者创建一个mixin,将此功能添加到listbase的任何子类中。defaultSelectedIndex在其数据提供程序更改时会将所选索引设置为指定值。以前没有使用过它,但按钮栏没有selectedIndex?如果我记得在Framework3.0中使用flex builder 3I时很清楚的话,它就是这样。我试过了,但是不管我为所选索引输入了什么值,ButtonBar中的第一个按钮都不会被选中。奇怪的呵呵,试着在为其指定数据提供程序之后,或者在creationcomplete事件中放置它,只是为了避免技术问题。。您是否尝试单击某个按钮并在该时刻更改selectedIndex,如myButtonBar.selectedIndex=1;如果行得通。。是指在将数据提供程序分配给之前已调度selectedIndex。。您需要在之后分配它,不知道它是否有dataproviderChanged事件。。谢谢你的回答。这就是我所做的:
,我也尝试了:
,但是选择的索引似乎仍然不起作用。你什么时候登录数据源?我正在使用一个
,里面有
(我更新了我的问题以反映这一点)。再次感谢你的帮助!