R – Flex – Is there a way to specify what direction a ComboBox will open


Maybe I should further qualify this – Is there a way to specify which direction a ComboBox will open without copying and pasting the entire ComboBox class and ripping out the code where it determines which direction it will open in…

I'm my specific case – I need it to open upwards – always.

UPDATE: You can't fix this by subclassing it because the function that handles the direction of the opening is:

private function displayDropdown(show:Boolean, trigger:Event = null):void

And that bad boy uses a fair amount of private variables which my subclass wouldn't have access to…

Best Solution

If you build up the Menu object yourself, you can place the menu anywhere you want by simply setting the x,y coordinates of the menu object. You'll need to calculate those coordinates, but you might be able to do this easily without subclassing ComboBox.

I am doing something similar with PopUpButton; you might find it easier to work with PopUpButton. This is based on real code from my current project:

private function initMenu(): void {
    var m:Menu = new Menu();
    m.dataProvider = theMenuData;
    m.addEventListener(MenuEvent.ITEM_CLICK, menuClick);
    m.showRoot = false;
    // m.x = ... <-- probably don't need to tweak this.
    // m.y = ... <-- this is really the interesting one :-)
    theMenu.popUp = m;
<mx:PopUpButton id="theMenu" creationComplete="initMenu()" ... />

BTW, to get the PopUpButton to act more like I wanted it (always popup, no matter where the click), setting openAlways=true in the MXML works like a charm.

Related Question