设置ComboBox控件中可见项的个数.
ComboBox控件的rowCount属性学习。
示例:
通过AS的方法来实现:
来自:http://blog.flexexamples.com/2008/06/11/setting-the-number-of-visible-items-in-a-combobox-controls-dropdown-menu-in-flex/
示例:
代码:
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/06/11/setting-the-number-of-visible-items-in-a-combobox-controls-dropdown-menu-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="top"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.events.NumericStepperEvent;
private function numericStepper_change(evt:NumericStepperEvent):void {
callLater(comboBoxOpen);
}
private function comboBoxOpen():void {
comboBox.open();
}
]]>
</mx:Script>
<mx:Array id="arr">
<mx:Object label="One" />
<mx:Object label="Two" />
<mx:Object label="Three" />
<mx:Object label="Four" />
<mx:Object label="Five" />
<mx:Object label="Six" />
<mx:Object label="Seven" />
<mx:Object label="Eight" />
<mx:Object label="Nine" />
</mx:Array>
<mx:ApplicationControlBar dock="true">
<mx:NumericStepper id="numericStepper"
minimum="0"
maximum="10"
change="numericStepper_change(event);" />
</mx:ApplicationControlBar>
<mx:ComboBox id="comboBox"
dataProvider="{arr}"
rowCount="{numericStepper.value}"
openDuration="0"
closeDuration="0"
width="100" />
</mx:Application>
<!-- http://blog.flexexamples.com/2008/06/11/setting-the-number-of-visible-items-in-a-combobox-controls-dropdown-menu-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="top"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.events.NumericStepperEvent;
private function numericStepper_change(evt:NumericStepperEvent):void {
callLater(comboBoxOpen);
}
private function comboBoxOpen():void {
comboBox.open();
}
]]>
</mx:Script>
<mx:Array id="arr">
<mx:Object label="One" />
<mx:Object label="Two" />
<mx:Object label="Three" />
<mx:Object label="Four" />
<mx:Object label="Five" />
<mx:Object label="Six" />
<mx:Object label="Seven" />
<mx:Object label="Eight" />
<mx:Object label="Nine" />
</mx:Array>
<mx:ApplicationControlBar dock="true">
<mx:NumericStepper id="numericStepper"
minimum="0"
maximum="10"
change="numericStepper_change(event);" />
</mx:ApplicationControlBar>
<mx:ComboBox id="comboBox"
dataProvider="{arr}"
rowCount="{numericStepper.value}"
openDuration="0"
closeDuration="0"
width="100" />
</mx:Application>
通过AS的方法来实现:
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/06/11/setting-the-number-of-visible-items-in-a-combobox-controls-dropdown-menu-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="top"
backgroundColor="white"
initialize="init();">
<mx:Script>
<![CDATA[
import mx.controls.ComboBox;
import mx.controls.NumericStepper;
import mx.containers.ApplicationControlBar;
import mx.events.NumericStepperEvent;
private var arr:Array;
private var appControlBar:ApplicationControlBar;
private var numericStepper:NumericStepper;
private var comboBox:ComboBox;
private function init():void {
arr = [];
arr.push({label:"One"});
arr.push({label:"Two"});
arr.push({label:"Three"});
arr.push({label:"Four"});
arr.push({label:"Five"});
arr.push({label:"Six"});
arr.push({label:"Seven"});
arr.push({label:"Eight"});
arr.push({label:"Nine"});
numericStepper = new NumericStepper();
numericStepper.minimum = 0;
numericStepper.maximum = 10;
numericStepper.addEventListener(NumericStepperEvent.CHANGE, numericStepper_change);
appControlBar = new ApplicationControlBar();
appControlBar.dock = true;
appControlBar.addChild(numericStepper);
Application.application.addChildAt(appControlBar, 0);
comboBox = new ComboBox();
comboBox.dataProvider = arr;
comboBox.rowCount = 5;
comboBox.width = 100;
comboBox.setStyle("openDuration", 0);
comboBox.setStyle("closeDuration", 0);
addChild(comboBox);
}
private function numericStepper_change(evt:NumericStepperEvent):void {
comboBox.rowCount = evt.value;
callLater(comboBoxOpen);
}
private function comboBoxOpen():void {
comboBox.open();
}
]]>
</mx:Script>
</mx:Application>
<!-- http://blog.flexexamples.com/2008/06/11/setting-the-number-of-visible-items-in-a-combobox-controls-dropdown-menu-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="top"
backgroundColor="white"
initialize="init();">
<mx:Script>
<![CDATA[
import mx.controls.ComboBox;
import mx.controls.NumericStepper;
import mx.containers.ApplicationControlBar;
import mx.events.NumericStepperEvent;
private var arr:Array;
private var appControlBar:ApplicationControlBar;
private var numericStepper:NumericStepper;
private var comboBox:ComboBox;
private function init():void {
arr = [];
arr.push({label:"One"});
arr.push({label:"Two"});
arr.push({label:"Three"});
arr.push({label:"Four"});
arr.push({label:"Five"});
arr.push({label:"Six"});
arr.push({label:"Seven"});
arr.push({label:"Eight"});
arr.push({label:"Nine"});
numericStepper = new NumericStepper();
numericStepper.minimum = 0;
numericStepper.maximum = 10;
numericStepper.addEventListener(NumericStepperEvent.CHANGE, numericStepper_change);
appControlBar = new ApplicationControlBar();
appControlBar.dock = true;
appControlBar.addChild(numericStepper);
Application.application.addChildAt(appControlBar, 0);
comboBox = new ComboBox();
comboBox.dataProvider = arr;
comboBox.rowCount = 5;
comboBox.width = 100;
comboBox.setStyle("openDuration", 0);
comboBox.setStyle("closeDuration", 0);
addChild(comboBox);
}
private function numericStepper_change(evt:NumericStepperEvent):void {
comboBox.rowCount = evt.value;
callLater(comboBoxOpen);
}
private function comboBoxOpen():void {
comboBox.open();
}
]]>
</mx:Script>
</mx:Application>
来自:http://blog.flexexamples.com/2008/06/11/setting-the-number-of-visible-items-in-a-combobox-controls-dropdown-menu-in-flex/