2个回答
展开全部
先在工作区中绘制方块,转为剪辑元件,实例命名为my_mc,在主时间轴第1帧处添加代码如下:
var myListener:Object = new Object();
var speed:Number = 10;
//移动速度
myListener.onKeyDown = function() {
//方向键控制移动
if (Key.getCode() == Key.RIGHT) {
my_mc._x += speed;
}
if (Key.getCode() == Key.LEFT) {
my_mc._x -= speed;
}
if (Key.getCode() == Key.UP) {
my_mc._y -= speed;
}
if (Key.getCode() == Key.DOWN) {
my_mc._y += speed;
}
};
Key.addListener(myListener);
var myListener:Object = new Object();
var speed:Number = 10;
//移动速度
myListener.onKeyDown = function() {
//方向键控制移动
if (Key.getCode() == Key.RIGHT) {
my_mc._x += speed;
}
if (Key.getCode() == Key.LEFT) {
my_mc._x -= speed;
}
if (Key.getCode() == Key.UP) {
my_mc._y -= speed;
}
if (Key.getCode() == Key.DOWN) {
my_mc._y += speed;
}
};
Key.addListener(myListener);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询