Tuesday, March 3, 2009

ComboBox direction

This blog has moved.

I needed to force the Flex ComboBox to open in a specific direction. (I'm using a HTML Component FCKEditor, which has to be on top, so I need to aim the ComboBox away from it, so it doesn't animate underneath it)


It seems as though the only way to do this in Flex is to edit the mx.controls.ComboBox class itself. With some help from typeoneerror, I went ahead and did just that:


i added two booleans to the class to use to force the comboBox's direction:


public var forceDirectionDown:Boolean = false;
public var forceDirectionUp:Boolean = false;



now in the displayDropdown method, inside the 'opening the dropdown' section, i just changed the if statement:


if (forceDirectionUp || (!forceDirectionDown &&
point.y + _dropdown.height > screen.height &&
point.y > _dropdown.height))



There is still a problem, however - when I set the Combo to 'forceDirectionDown' and there isn't enough room at the bottom of the screen, when the dropdown closes, it assumes to animate the dropdown down, away from the combo. To resolve this, I added to the 'closing the dropdown' section, where it sets endY. I changed the condition line to:


endY = (forceDirectionUp || (!forceDirectionDown &&
(point.y + _dropdown.height > screen.height || tweenUp))