飞机游戏FLASH as3.0求高手帮忙注释代码(最好每句都有注释)谢谢了

packageclasses{importflash.display.MovieClip;importflash.events.Event;importflash.eve... package classes
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
/**
* ...
* @author
*/
public class Keycode extends MovieClip
{
var left:Boolean = false;
var right:Boolean = false;
var up:Boolean = false;
var down:Boolean = false;
var fair:Boolean=false;
var skill:Boolean=false;
public function Keycode()
{
this.addEventListener(Event.ADDED_TO_STAGE, addEvt)
this.addEventListener(Event.REMOVED_FROM_STAGE, offEvt)
}
function addEvt(e:Event)
{
stage.addEventListener(KeyboardEvent.KEY_DOWN, downEvt);
stage.addEventListener(KeyboardEvent.KEY_UP, upEvt);
}
function offEvt(e:Event)
{
stage.removeEventListener(KeyboardEvent.KEY_DOWN, downEvt);
stage.removeEventListener(KeyboardEvent.KEY_UP, upEvt);
}
function downEvt(event:KeyboardEvent):void
{
switch(event.keyCode)
{
case 65:
left = true;
break;
case 87:
up = true;
break;
case 68:
right = true;
break;
case 83:
down = true;
break;
}
}
function upEvt(event:KeyboardEvent):void
{
switch(event.keyCode)
{
case 65:
left = false;
break;
case 87:
up = false;
break
case 68:
right = false;
break
case 83:
down = false;
break;
}
}
}
}
展开
 我来答
dcpromowang
2012-05-16 · TA获得超过907个赞
知道小有建树答主
回答量:734
采纳率:100%
帮助的人:462万
展开全部
///变量名:上、下、左、右、开火、技能
var left:Boolean = false;
var right:Boolean = false;
var up:Boolean = false;
var down:Boolean = false;
var fair:Boolean=false;
var skill:Boolean=false;
///构造函数监听 添加/移除舞台事件
public function Keycode()
{
this.addEventListener(Event.ADDED_TO_STAGE, addEvt)
this.addEventListener(Event.REMOVED_FROM_STAGE, offEvt)
}
///初始化后监听 键盘 按下 & 松开事件
function addEvt(e:Event)
{
stage.addEventListener(KeyboardEvent.KEY_DOWN, downEvt);
stage.addEventListener(KeyboardEvent.KEY_UP, upEvt);
}
///移除舞台事件 删除键盘监听
function offEvt(e:Event)
{
stage.removeEventListener(KeyboardEvent.KEY_DOWN, downEvt);
stage.removeEventListener(KeyboardEvent.KEY_UP, upEvt);
}
///触发键盘按下
function downEvt(event:KeyboardEvent):void
{
switch(event.keyCode) ///键盘按下后对应的Ascii码
{
case 65:/// 键盘 "A"的话
left = true;
break;
case 87::/// 键盘 "W"的话
up = true;
break;
case 68::/// 键盘 "D"的话
right = true;
break;
case 83::/// 键盘 "S"的话
down = true;
break;
}
}
///触发松开按键事件
function upEvt(event:KeyboardEvent):void
{
switch(event.keyCode)///键盘松开所对应的Ascii码

{
case 65::/// 键盘 "A"的话
left = false;
break;
case 87:/// 键盘 "W"的话
up = false;
break
case 68:::/// 键盘 "D"的话
right = false;
break
case 83:::/// 键盘 "S"的话
down = false;
break;
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式