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

by Peter deHaan on January 31, 2008

in PopUpButton

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 comments… read them below or add one }

1 abhi January 31, 2008 at 2:06 am

good

Reply

2 Prashanth Samanth June 28, 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

Reply

3 ciacob May 5, 2009 at 10:45 am

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

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree

Previous post:

Next post: