04
Feb
08

Detecting when the main button on the Flex PopUpButton control has been clicked

The following example shows how you can detect when the main button on the PopUpButton control has been clicked by listening for the click event.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/02/04/detecting-when-the-main-button-on-the-flex-popupbutton-control-has-been-clicked/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="top"
        backgroundColor="white">

    <mx:Style>
        PopUpButton {
            pop-up-style-name: myCustomPopUpStyleName;
        }

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

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

            [Bindable]
            private var menu:Menu;

            private function popUpButton_initialize():void {
                menu = new Menu();
                menu.dataProvider = arr;
            }

            private function popUpButton_click():void {
                Alert.show("You clicked me, now what?");
            }
        ]]>
    </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:PopUpButton id="popUpButton"
            label="Please select an item"
            popUp="{menu}"
            initialize="popUpButton_initialize();"
            click="popUpButton_click();" />

</mx:Application>

View source is enabled in the following example.


4 Responses to “Detecting when the main button on the Flex PopUpButton control has been clicked”


  1. 1 keith Feb 4th, 2008 at 11:12 am

    Hey peter,

    Thanks for the demonstration. It looks like some of the source code may have been cut off however. The last line of code shown is .

    Take care :)
    Keith

  2. 2 peterd Feb 8th, 2008 at 11:08 pm

    keith,

    Oops! Fixed, thanks for the heads up!

    Peter

  3. 3 Mike Nov 8th, 2008 at 7:59 pm

    Great example. How do you pass the value of the item selected in the dropdown with the main button click?

  4. 4 Mike Nov 8th, 2008 at 8:24 pm

    I cant seem to edit my previous comment. Anyway, I think I have it worked out… illumination doesn’t seem to strike until after one posts for help, lol. anyway, thanks for the great example, it really helped.

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




February 2008
M T W T F S S
« Jan   Mar »
 123
45678910
11121314151617
18192021222324
2526272829  

Badge Farm

  • Firefox 2
  • Powered by Redoable 1.2
  • Feeds burnt by Feedburner
  • Feed