展开全部
<?xml version="1.0" encoding="utf-8"?> <mx:Application creationComplete="init()" xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" fontSize="12"> <mx:Script> <![CDATA[ import mx.controls.Alert; private function init():void{ this.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown); } private function onKeyDown(event:KeyboardEvent):void{ if(event.keyCode == Keyboard.SPACE){//这里约定键盘哪个键,以 空格键 为例 btn.dispatchEvent(new MouseEvent(MouseEvent.CLICK)); } } ]]> </mx:Script> <mx:Button id="btn" label="Button" click="Alert.show('您单击了按钮!')" /> </mx:Application>
展开全部
应该是 this.stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown); 一定要在应用程序初始完了才能添加。否则 stage = null (<mx:Application applicationInit……记不住单词了="init()" xmlns:mx=" http://www.adobe.com/2006/mxml" ) function onKeyDown(e:KeyboardEvent):void{ trace(e.keyCode);自己去看。 }
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<?xml
version="1.0"
encoding="utf-8"?>
<mx:Application
creationComplete="init()"
xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute"
fontSize="12">
<mx:Script>
<![CDATA[
import
mx.controls.Alert;
private
function
init():void{
this.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown);
}
private
function
onKeyDown(event:KeyboardEvent):void{
if(event.keyCode
==
Keyboard.SPACE){//这里约定键盘哪个键,以
空格键
为例
btn.dispatchEvent(new
MouseEvent(MouseEvent.CLICK));
}
}
]]>
</mx:Script>
<mx:Button
id="btn"
label="Button"
click="Alert.show('您单击了按钮!')"
/>
</mx:Application>
version="1.0"
encoding="utf-8"?>
<mx:Application
creationComplete="init()"
xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute"
fontSize="12">
<mx:Script>
<![CDATA[
import
mx.controls.Alert;
private
function
init():void{
this.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown);
}
private
function
onKeyDown(event:KeyboardEvent):void{
if(event.keyCode
==
Keyboard.SPACE){//这里约定键盘哪个键,以
空格键
为例
btn.dispatchEvent(new
MouseEvent(MouseEvent.CLICK));
}
}
]]>
</mx:Script>
<mx:Button
id="btn"
label="Button"
click="Alert.show('您单击了按钮!')"
/>
</mx:Application>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询