OK, I was using the wrong event! I'm such a Flex novice.
Here's the new class that works:
package com.plasticbrain.controls {
import mx.controls.ComboBox;
import mx.events.FlexEvent;
public class ComboBoxOpen extends ComboBox {
// Constructor.
public function ComboBoxOpen() {
super();
this.addEventListener(FlexEvent.CREATION_COMPLETE,
onComboBoxOpenCreationComplete);
}
private function
onComboBoxOpenCreationComplete(evt:FlexEvent):void {
trace("ComboBoxOpen CREATION_COMPLETE
"+evt.currentTarget);
this.open();
this.removeEventListener(FlexEvent.CREATION_COMPLETE,
onComboBoxOpenCreationComplete);
}
}
}
On 2007-11-12, at 1:49 PM, Stephen Downs wrote:
I'm trying to create a simple ComboBox subclass that defaults to
the open position, automatically displaying it's dropdown list. I'm
trying to implement this as an itemRenderer for a DataGrid.
Each time I call the open() function on the ComboBox subclass, it
refuses to open. The dropdown list returns null at these key
initialization events, so perhaps the open() call is rejected as
the dropdown list hasn't been instantiated yet. I thought that was
the point of the open() call?
Setup: Mac OS X 10.4.10, Flex Builder 3.
Anyhow, here's my hacky attempt at this subclass. Any input would
be appreciated:
pa ckage com.plasticbrain.controls {
import flash.events.Event;
import mx.controls.ComboBox;
import mx.events.FlexEvent;
public class ComboBoxOpen extends ComboBox {
// Constructor.
public function ComboBoxOpen() {
super();
this.addEventListener(Event.ADDED_TO_STAGE,
this.onAddedToStage);
}
private function onAddedToStage(evt:Event):void {
// Try to open the ComboBox (doesn't work).
this.open();
this.removeEventListener(Event.ADDED_TO_STAGE,
this.onAddedToStage);
this.addEventListener(FlexEvent.DATA_CHANGE,
this.onDataChange); }
private function onDataChange(evt:FlexEvent):void {
// Try again to open the ComboBox (still doesn't work).
this.open();
this.removeEventListener(FlexEvent.DATA_CHANGE,
this.onDataChange);
}
}
}