31
Jan
08

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.


2 Responses to “Setting the vertical gap between a Flex PopUpButton control and its pop up menu”


  1. 1 abhi Jan 31st, 2008 at 2:06 am

    good

  2. 2 Prashanth Samanth Jun 28th, 2008 at 4:21 am

    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

Leave a Reply

This blog is terrible at eating HTML tags. If you plan on posting code/XML, please escape your "<" characters as "&lt;" and your ">" characters as "&gt;".