Setting the vertical gap between a Flex PopUpButton control and its pop up menu

The following example shows how you can set the gap between a PopUpButton control and its pop up menu in Flex by setting the popUpGap style.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/01/31/setting-the-vertical-gap-between-a-flex-popupbutton-control-and-its-pop-up-menu/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="top"
        backgroundColor="white">

    <mx:Style>
        PopUpButton {
            popUpStyleName: myCustomPopUpStyleName;
        }

        .myCustomPopUpStyleName {
            fontWeight: normal;
            textAlign: left;
        }
    </mx:Style>

    <mx:Script>
        <![CDATA[
            import mx.controls.Menu;

            private function init():void {
                var menu:Menu = new Menu();
                menu.dataProvider = arr;
                popUpButton.popUp = menu;
            }

            private function slider_change():void {
                popUpButton.close();
                popUpButton.open();
            }
        ]]>
    </mx:Script>

    <mx:Array id="arr">
        <mx:Object label="Alert" />
        <mx:Object label="Button" />
        <mx:Object label="ButtonBar" />
        <mx:Object label="CheckBox" />
        <mx:Object label="ColorPicker" />
        <mx:Object label="ComboBox" />
    </mx:Array>

    <mx:ApplicationControlBar dock="true">
        <mx:Form styleName="plain">
            <mx:FormItem label="popUpGap:">
                <mx:HSlider id="slider"
                        minimum="-5"
                        maximum="10"
                        value="0"
                        liveDragging="true"
                        snapInterval="1"
                        tickInterval="1"
                        change="slider_change();" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>

    <mx:PopUpButton id="popUpButton"
            label="Please select an item..."
            openAlways="true"
            popUpGap="{slider.value}"
            closeDuration="0"
            openDuration="0"
            initialize="init();" />

</mx:Application>

View source is enabled in the following example.

3 thoughts on “Setting the vertical gap between a Flex PopUpButton control and its pop up menu

  1. Hi,

    Is it possible to filp the popUpButton option to Horizontal, I mean according to my requirement, there should be a option of showing a Saved data, which will be on left of the page.

    which has to open by clicking on the button, we need to show a Datagrid Data. Just as same as the popUpButton will show the hidden data unless it is clicked (But popUpButton shows in Vertical)

    Please help me regarding this

    Thanks a lot
    Psamanth

  2. Hi Peter,

    Is there a way to achieve the same, but *horizontally*? I mean, the menu that pops up will not align itself to the left edge of the pop-up button, but leave a horizontal gap instead.

    I’m currently making a Flex skin which has rounded buttons, and having a menu popping up to the very left edge of the rounded button isn’t going to look too nice.

    Thanks for any help whatsoever
    C

Comments are closed.