效果演示:
点击这里下载Flash源文件
//-------必须将下代码保存为.as文件,与本文件放在同一目录,输出SWF时才能实现效果----//
class moveClass {
//--------------------缓冲挪动类--------------------//
var tmp1:Number;
var tmp2:Number;
var tmp3:Number;
var tmp4:Number;
var JuLi:Number;
function moveClass() {
//结构函数
tmp1 = 0;
tmp2 = 0;
tmp3 = 0;
tmp4 = 0;
JuLi = 0;
//存储距离的变量;
}
function moveXYR(mc:Object, X:Number, Y:Number, n:Number, m:Number):Number {
n = n == undefined ? (Math.random()*2+4)*.1 : n;
m = m == undefined ? (Math.random()*2+4)*.1 : m;
tmp1 = (X-mc._x)*n;
tmp2 = (tmp2+tmp1)*n;
mc._x += tmp2;
tmp3 = (Y-mc._y)*m;
tmp4 = (tmp4+tmp3)*m;
mc._y += tmp4;
return distance(X, mc._x, Y, mc._y);
}
function distance(X1:Number, X2:Number, Y1:Number, Y2:Number):Number {
JuLi = (X1-X2)*(X1-X2)+(Y1-Y2)*(Y1-Y2);
JuLi = Math.sqrt(JuLi);
return JuLi;
}
}