Resizing the drop down list of ComboBox when removeItem() is called
When items in a CombBox compnent instance are removed with ComboBox.removeItem() method, its size of drop down list will not be adjusted. I suspect that this behavior might be a bug because ComboBox.removeItemAt() method properly reset its size.
-> 
In order to set size of the drop down list properly call UIComponent.validateNow() method after an item is removed with the method like the following code:
// Frame action
import fl.controls.ComboBox;
var myComboBox:ComboBox = new ComboBox();
addChild(myComboBox);
myComboBox.addEventListener(Event.CHANGE, xSelected);
myComboBox.addItem({label:"Dreamweaver CS4", data:"html"});
myComboBox.addItem({label:"Fireworks CS4", data:"png"});
myComboBox.addItem({label:"Flash CS4 Professional", data:"fla"});
function xSelected(eventObject:Event):void {
var myItem:Object = myComboBox.getItemAt(0);
myComboBox.removeItem(myItem);
myComboBox.validateNow(); // Insert this statement.
}
In the ComboBox class ComboBox.removeItemAt() method calls UIComponent.invalidate() method after deleting an item with List.removeItemAt() method.
public function removeItemAt(index:uint):void {
list.removeItemAt(index);
invalidate(InvalidationType.DATA);
}
However, ComboBox.removeItem() method does not call the method.
public function removeItem(item:Object):Object {
return list.removeItem(item);
}
Therefore, UIComponent.invalidate() method could be used instead of UIComponent.validateNow() method.
// Frame action
import fl.core.InvalidationType;
import fl.controls.ComboBox;
var myComboBox:ComboBox = new ComboBox();
addChild(myComboBox);
myComboBox.addEventListener(Event.CHANGE, xSelected);
myComboBox.addItem({label:"Dreamweaver CS4", data:"html"});
myComboBox.addItem({label:"Fireworks CS4", data:"png"});
myComboBox.addItem({label:"Flash CS4 Professional", data:"fla"});
function xSelected(eventObject:Event):void {
var myItem:Object = myComboBox.getItemAt(0);
myComboBox.removeItem(myItem);
myComboBox.invalidate(InvalidationType.DATA); // Insert this statement.
}
1 Comment
Japanese version of the explanation was posted to FumioNonaka.com.
http://www.fumiononaka.com/TechNotes/Flash/FN0908001.html