0
votes

Can we use the same event handler which would listen to the mouse click event and the event dispatched when enter key is pressed?

Thanks.

1
Do you mean FlexEvent.ENTER or KeyboardEvent? - RIAstar

1 Answers

0
votes

Below code may Help You: -

    <?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;

            private function callHandler(event:*):void
            {
                if ( event.type == KeyboardEvent.KEY_DOWN || event.type == MouseEvent.CLICK)
                { 
                    if (event.type == MouseEvent.CLICK || (event as KeyboardEvent).charCode == 32 )
                    {
                        Alert.show("Clicked", "Alert"); 
                    }

                }
            }

        ]]>
    </fx:Script>

    <s:Button label="Click" x="100" y="100" click="{callHandler(event)}" keyDown="{callHandler(event)}"/>
</s:Application>