As如下:
//闪虾小排写于公元2007年4月22日
var c1 = (bt_1._width/2+bt_1._x);
var c2 = (bt_2._width/2+bt_2._x);
var c3 = (bt_3._width/2+bt_3._x);
var c4 = (bt_4._width/2+bt_4._x);
var c5 = (bt_5._width/2+bt_5._x);
//定义五个中心点,c1为起点
var b = 1;
//定义B变量,保存当前[mc]所在按钮序数
//trace(c1+" "+c2+" "+c3+" "+c4+" "+c5);
mc._x = c1;
mc._y = bt_1._y
//定义小人[mc]的X坐标为第一个按钮的中心,Y坐标为按钮y坐标
bt_1.onRelease = function() {
move_x(1);
};
bt_2.onRelease = function() {
move_x(2);
};
bt_3.onRelease = function() {
move_x(3);
};
bt_4.onRelease = function() {
move_x(4);
};
bt_5.onRelease = function() {
move_x(5);
};
//定义按钮响应
function move_x(x) {
arr_mc = new Array();
m = this["c"+x]-this["c"+b];
h = Math.abs(m);
//m代表两个按钮间的距离,h代表[mc]跳起的高度(为距离的一半,以45度角起跳)
for (j=1; j<=5; j++) {
this["bt_"+j].enabled = 0;
}
//这个FOR循环是为了让按钮点击以后,所有按钮处于停用状态
for (ii=0; ii<5; ii++) {
arr_mc[ii] = Math.round(h/2);
h -= h/2;
arr_mc[9-ii] = -arr_mc[ii];
}
i = 0;
onEnterFrame = function () {
mc._x += m/10;
mc._y -= arr_mc;
i++;
if (i == 10) {
//仅需运行10次,so 在这里加一个delete
delete onEnterFrame;
for (j=1; j<=5; j++) {
this["bt_"+j].enabled = 1;
}
i = 0;
p = 1;
//这个FOR循环是为了让小人[mc]移动完以后,所有按钮恢复启用状态
}
};
//判断原x坐标与目标x坐标的距离
b = x;
}
//自定义x方向移动
//主场景里五个按钮的实例名为 bt_1、bt_2……
//主场景里mc的实例名为 mc