views:

1428

answers:

5

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...

A: 

I doubt it - you'd need to subclass the control (which isn't that big a deal.)

Maybe you could mess with the real estate so it's placed in such a fashion (e.g. crowded into the lower right corner) that up is naturally coerced?

le dorfier
A: 

I would recommend checking out this post. Yes, you do have to grab the ComboBox code and modify it, but at least now you have an idea where the modifications need to go.

Dave DuPlantis
+2  A: 

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.

Mitch Haile
You are the man - that component actually fits my needs a lot better. I just never have used it!
onekidney
A: 

You could set the MaxDropDownHeight, if you set it big enough Windows will automatically set the direction upwards.

A: 

This irritated me no end. I have uploaded a solution, its a simple Class that extends the PopUpButton and removes the logic of stage bounds detection as it failed 50% of the time anyway. My code just allows you to simply specify whether you want to open the menu up or down:

http://gist.github.com/505255

newtriks