我需要在几个mx PopUpMenuButton
组件中设置一些初始值。基于this Adobe info我将组件投射为Menu
并设置selectedIndex
- 但它不起作用。
任何提示?该函数被调用,似乎selectedIndex
已设置,但PopUpMenuButton
仍显示其数据提供者中的第一项。
private function initFontSizeData():void {
Menu(fontSizePopUp.popUp).selectedIndex = 3; // 48 pt
trace("index", Menu(fontSizePopUp.popUp).selectedIndex);
}
<mx:PopUpMenuButton id="fontSizePopUp"
name="fontSizePopUp"
width="50" height="20"
labelField="label"
paddingLeft="-8"
itemClick="toolChangeHandler(event)"
open="canvasEnabled(false)"
close="canvasEnabled(true)"
chromeColor="#cccccc"
toolTip="Font Size"
styleName="toolPopUpStyle"
creationComplete="initFontSizeData()"
popUpStyleName="toolPopUpStyle">
<mx:dataProvider>
<fx:Array>
<fx:Object fontPointSize = "18" label="18 pt"/>
<fx:Object fontPointSize = "24" label="24 pt" />
<fx:Object fontPointSize = "36" label="36 pt" />
<fx:Object fontPointSize = "48" label="48 pt" />
<fx:Object fontPointSize = "60" label="60 pt" />
<fx:Object fontPointSize = "72" label="72 pt"/>
<fx:Object fontPointSize = "96" label="96 pt" />
</fx:Array>
</mx:dataProvider>
</mx:PopUpMenuButton>
答案 0 :(得分:1)
出于某种原因我忽略了(可能只是一个bug),PopUpMenuButton
控件的标签没有更新,这就是为什么你必须强制它使用以下方法之一来做到这一点:
mx.core.mx_internal
提交所选索引:Menu(fontSizePopUp.popUp).selectedIndex = 3; Menu(fontSizePopUp.popUp).mx_internal::commitSelectedIndex(3);
mx.events.MenuEvent
事件:var menu_event:MenuEvent = new MenuEvent(MenuEvent.ITEM_CLICK); menu_event.index = 3; Menu(fontSizePopUp.popUp).dispatchEvent(menu_event);
mx.events.FlexEvent
事件:Menu(fontSizePopUp.popUp).selectedIndex = 3; Menu(fontSizePopUp.popUp).dispatchEvent(new FlexEvent(FlexEvent.VALUE_COMMIT));
希望可以提供帮助。