I've also encountered this bug (event dispatched twice).
 
Here is a workaround :
private function itemClickHandler(event:MenuEvent):void {
    if (event.index != -1) { // Workaround to ignore the second event
        ...
    }
}
 
Benoit Hediard


De : flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] De la part de sinatosk
Envoyé : dimanche 2 juillet 2006 21:41
À : flexcoders@yahoogroups.com
Objet : [flexcoders] F2.0 final - Possbile bug with PopUpButton and PopUpMenuButton

4 days after the release I come to update my Flex Application from Beta 3 to Final and the 2 main components I used seem to be bugged. not very good at explaining things to bare with me please :p

PopUpButton    

    - Every time I select an item... the "itemClick" event gets dispatched twice. it just pops with with 2 Alert dialogs every time I select an item

PopUpMenButton

    - When I put my mouse over an item for the first time.... works fine... but soon as I hover over another menu item in the main level... the menu closes automatically and also if I Hover over an item that is a sub menu.... I can keep going in and in until there are no more children... or I could just go in once... and then soon as I hover over another item... again the menu just closes. Both times this is without click on any items in the menu

I've posted the code below

Flex code being:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml " layout="absolute">
    <mx:Script>
        <![CDATA[

            import mx.controls.*;
            import mx.events.*;

            private var myMenu:Menu;
           
            private var i:uint = 0;

            // Initialize the Menu control, and specify it as the pop up object
            // of the PopUpButton control.
            private function initMenu():void {
                myMenu = new Menu();
                var dp:Object = [{label: "New Folder"}, {label: "Sent Items"}, {label: "Inbox"}];       
                myMenu.dataProvider = dp;
                myMenu.selectedIndex = 0;      
                myMenu.addEventListener("itemClick", itemClickHandler);
                popB.popUp = myMenu;
                popB.label = "Put in: " + myMenu.dataProvider[myMenu.selectedIndex].label;
            }

            // Define the event listener for the Menu control's itemClick event.
            private function itemClickHandler(event:MenuEvent):void {
                var label:String = event.item.label;       
                popTypeB.text=String("Moved to " + label);
                popB.label = "Put in: " + label;
                popB.close ();
                myMenu.selectedIndex = event.index;
               
                Alert.show('menu popup number ' + ++i);
            }

        ]]>
    </mx:Script>

    <mx:Panel title="PopUpButton Control Example"
        paddingTop="10" paddingBottom="10" paddingRight="10" paddingLeft="10" x="10" y="10" height="187" width="411">

        <mx:Label width="100%" color="blue"
            text="Button label contains the name of the last selected menu item." />
        <mx:PopUpButton id="popB" label="Edit" creationComplete="initMenu();" width="135" />
       
        <mx:Spacer height="50" />
        <mx:TextInput id="popTypeB" />
       
    </mx:Panel>
   
    <mx:Script>
        <![CDATA[
            import mx.events.*;
            import mx.controls.*;
           
            //Event handler, invoked when you select from the menu.
            public function itemClickHandler2(event:MenuEvent):void {
                Alert.show("Menu label: " + event.label
                    + "  \n menu item index within parent menu: " + event.index);
            }
        ]]>
    </mx:Script>
   
    <!-- A an data provider in E4X format. -->
    <mx:XMLList id="treeDP2">
        <node label="Inbox">
            <node label="Personal">
                <node label="Family"/>
                <node label="Friends"/>
            </node>
            <node label="Marketing"/>
            <node label="To Do"/>
        </node>
        <node label="Calendar">
            <node label="Appointments" data=""/>
            <node label="Meetings"/>
        </node>
        <node label="Deleted Items"/>
    </mx:XMLList>

    <mx:Panel title="PopUpMenuButton Control Example"
        paddingTop="10" paddingLeft="10" paddingRight="10" x="10" y="205" height="143" width="271">

        <mx:Label width="100%" color="blue"
            text="Click the down arrow to open the menu."/>

        <mx:PopUpMenuButton id="p2"
            dataProvider="{treeDP2}"
            labelField="@label"
            itemClick="itemClickHandler2(event);"/>

    </mx:Panel>
</mx:Application>

Flex code end;

Is it possible these are bugs? I've tested this with flash player 9.0.15.0 ( with debug ) and 9.0.16.0 ( without debug )
__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




__,_._,___

Reply via email to