我们可以使用相同的事件处理程序来监听鼠标单击事件和按下回车键时调度的事件吗?
谢谢。
下面的代码可以帮助你: -
<?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>