2
我需要在幾個mx PopUpMenuButton
組件中設置一些初始值。基於this Adobe info我將該組件轉換爲Menu
並設置selectedIndex
- 但它不起作用。以編程方式設置PopUpMenuButton的值?
任何提示?該函數被調用,看起來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>
只是一個猜測:如果你在'initFontSizeData()'中分配了一個不同的,可區分的數據提供者呢?也許該方法在評估子標籤的值之前執行? – null
最後一個想法:如果你在mxml中創建了dp,但是在fx中:你的問題中的鏈接中的示例代碼中的聲明是否有效? – null