7 Replies Latest reply on Jun 1, 2009 12:14 AM by Prasanta Saha

    Prevent PopUpMenuButton itemClick Event

    Miggl Level 1

      Hi Guys,

       

      I have a PopUpMenuButton where I would like to prevent the itemClick event from being triggered if the button itself is clicked (not the drop-down with the list of menu items). According to Adobe Live Docs clicking the button fires off the click event, and then also triggers the itemClick event.

       

      How can I prevent the itemClick event from firing?

       

      My reasoning is this: I only want the popupmenubutton to display the dropdown list when the button portion is clicked, not do any other processing. It should behave just as if the drop-down button to the right was clicked, exposing the drop-down list of menu items.

       

      Instead, what happens now if I click the button section is that it shows the drop-down list, but then also fires off the itemClick event, acting as if I selected the first item in the drop-down list (since that is highlighted by default when the list is exposed).

       

      Thanks!

        • 1. Re: Prevent PopUpMenuButton itemClick Event
          Gregory Lafrance Level 6

          Maybe have an itemClick event handler that does this:

           

          event.preventDefault();

          event.stopImmediatePropagation();

          1 person found this helpful
          • 2. Re: Prevent PopUpMenuButton itemClick Event
            Miggl Level 1

            Thanks for the quick reply, Greg!

             

            Now, I do want itemClicks to propogate if they originate from clicking on the list. The only itemClicks I don't want to propogate are those originating from the button itself.

             

            Is that doable?

             

            Thanks!

            • 3. Re: Prevent PopUpMenuButton itemClick Event
              Miggl Level 1

              The thought occurred to me that I may be mis-using this control, and should be using another instead?

              • 4. Re: Prevent PopUpMenuButton itemClick Event
                Michael Borbor Level 4

                Just add an if to your even handler, something like this

                 

                if(event.label!="myDefaultPopUpButton"){
                        //do something
                }else{//do nothing}
                
                1 person found this helpful
                • 5. Re: Prevent PopUpMenuButton itemClick Event
                  Miggl Level 1

                  That is what I have right now:

                       <mx:Script>
                            <![CDATA[
                                          //[...]
                                 private function toolClickHandler(event:MenuEvent):void
                                 {
                                      switch(event.label)
                                      {
                                           case "Password Generator":
                                                var window:PasswordGenerator = PopUpManager.createPopUp(this, PasswordGenerator, true) as PasswordGenerator;
                                           
                                                PopUpManager.centerPopUp(window);
                                                break;
                                      }
                                 }
                            ]]>
                       </mx:Script>
                       <mx:XMLList
                            id="xl_tool_menu">
                            <node
                                 label="Tools"
                            />
                            <node
                                 label="Calculator"
                            />
                       </mx:XMLList>
                       <mx:PopUpMenuButton
                            id="pmb_tools"
                                  label="Tools"
                            labelField="@label"
                            dataProvider="{xl_tool_menu}"
                                  click="this.pmb_tools.open();"
                            itemClick="toolClickHandler(event);"
                       />
                  
                  

                   

                  However, since Password Generator is the only item in the list, it appears to handle it as always selected, meaning that event.label will always result in "Calculator".

                  • 6. Re: Prevent PopUpMenuButton itemClick Event
                    Miggl Level 1

                    My original goal was to get the functionality of the menubar with the look of the popupmenubuttons.

                    For the time being I reverted back to the menubar, as it is exactly the functionality I need. I guess I can skin it later too look like a popupmenubutton.

                    • 7. Re: Prevent PopUpMenuButton itemClick Event
                      Prasanta Saha

                      HI,

                       

                      Recenly I also had the same issue with PopUpMenuButton. But I could resolve it by adding "itemClick" event lister to PopUpMenuButton.popup but not for PopUpMenuButton.

                       

                       

                      for example:

                       

                      optionsMenuButton.popUp.addEventListener(MenuEvent.ITEM_CLICK, optionSelectionHandler, false, 0, true);

                       

                       

                      By doing that the callback function will never be called on main button click.