我个人的做法,希望贴贴你的做法,大家可以相互学习下...
上下左右键实现人物移动
代码:
var mclsA:Object = new Object();
var sp = 3;
mclsA.onKeyDown = function() {
if (Key.isDown(Key.LEFT)) {
mc.gotoAndStop(2);
mc._x = Math.max(0, mc._x-sp);
} else if (Key.isDown(Key.RIGHT)) {
mc.gotoAndStop(3);
mc._x = Math.min(Stage.width-mc._width, mc._x+sp);
} else if (Key.isDown(Key.DOWN)) {
mc.gotoAndStop(4);
mc._y = Math.min(Stage.height-mc._height, mc._y+sp);
} else if (Key.isDown(Key.UP)) {
mc.gotoAndStop(5);
mc._y = Math.max(0, mc._y-sp);
}
};
mclsA.onKeyUp = function() {
for (k=0; k<4; k++) {
mc["mc"+k].stop();
}
};
Key.addListener(mclsA);
进入论坛和作者讨论学习:
http://space.flash8.net/bbs/thread-359721-1-2.html