1 Reply Latest reply on Apr 21, 2010 6:01 AM by JockMahon

    PopUpButton problems!

    JockMahon Level 1

      i want to separate the actions of selecting an item from the popup  to the click event of the actual popupButton, how is this done,

      i have tried itemClick but this also fires the click event, this code is taken from  Peter deHaan exampls at http://blog.flexexamples.com

       

      <?xml version="1.0" encoding="utf-8"?>
      <!-- http://blog.flexexamples.com/2008/02/04/detecting-when-the-main-button-on-the-flex-popupbu tton-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;
                  import mx.events.DropdownEvent;
                  import mx.events.MenuEvent;
                 
                  [Bindable]
                  private var menu:Menu;
                 
                  private function popUpButton_initialize():void {
                     
                      menu = new Menu();
                      var dp:Object = [
                          {label: "New Folder"},
                          {label: "Sent Items"},
                          {label: "Inbox"}
                      ]; 
                     
                      menu.addEventListener("itemClick", a);
                      menu.addEventListener("click"    , b);
                      menu.dataProvider = dp;
                  }
                 
                 
                 
                 
                  private function a(event:MenuEvent):void
                  {
                      Alert.show("AAAAAAAAAAAAAAAAAAAA");
                  }
                 
                  private function b(event:MouseEvent):void
                  {
                      Alert.show("BBBBBBBBBBBBBBBBBBBBB");
                  }

       

                     
                  private function popUpButton_click():void {
                      Alert.show("You clicked me, now what?");
                  }

       

                  protected function popUpButton_changeHandler(event:Event):void
                  {
                      Alert.show("asdasdasdadasdsadasdsa");
                  }

       

              ]]>
          </mx:Script>

       

         
          <mx:PopUpButton id="popUpButton"
                          label="Please select an item"
                          popUp="{menu}"
                          initialize="popUpButton_initialize();"
                          change="popUpButton_changeHandler(event)"
                          click="popUpButton_click();"
                          />
         
      </mx:Application>

        • 1. Re: PopUpButton problems!
          JockMahon Level 1

          think i have this one sorted, the

           

          i have an extra click event on the menu

            menu.addEventListener("click"    , b);

           

          stupid

           

          I hate working with PopUpButton / PopUpMenuButton  find them very awkward and hard to use makes me a bit tick in the head