//////////////////class/////////////////////
class Rect {
private var container_mc:MovieClip;
private var x1:Number;
private var y1:Number;
private var mc_height:Number;
private var mc_width:Number;
private var startx:Number;
private var starty:Number;
private var xspeed:Number = 0;
private var yspeed:Number = 0;
private var xmouse:Number;
private var ymouse:Number;
public function Rect(x:Number, y:Number, h:Number, w:Number, target:MovieClip, depth:Number) {
container_mc = target.createEmptyMovieClip("mc", depth);
setX(x);
setY(y);
setHeight(h);
setWidth(w);
drawRect();
}
public function setX(x:Number):Void {
x1 = x;
}
public function setY(y:Number):Void {
y1 = y;
}
public function setHeight(h:Number):Void {
mc_height = h;
}
public function setWidth(w:Number):Void {
mc_width = w;
}
public function drawRect(){
container_mc.lineStyle(0, 0, 0);
container_mc.beginFill(0xff0000);
container_mc.moveTo(x1, y1);
container_mc.lineTo(x1+mc_width, y1);
container_mc.lineTo(x1+mc_width, y1+mc_height);
container_mc.lineTo(x1, y1+mc_height);
container_mc.endFill();
}
public function drawRectRun() {
container_mc.clear();
container_mc.lineStyle(0, 0, 0);
container_mc.beginFill(16711680);
container_mc.moveTo(x1, y1);
container_mc.curveTo(xmouse, ymouse-mc_height, x1+mc_width, y1);
container_mc.lineTo(x1+mc_width, y1+mc_height);
container_mc.curveTo(xmouse, ymouse, x1, y1+mc_height);
container_mc.endFill();
}
public function mouseRound() {
if (_xmouse<x1) {
xmouse = x1;
} else if (_xmouse>x1+mc_width) {
xmouse = x1+mc_width;
} else {
xmouse = _xmouse;
ymouse = _ymouse;
}
}
public function rectRun() {
startx = x1+mc_width/2;
starty = y1+mc_height;
xspeed = ((startx-xmouse)*0.4)+(xspeed*0.9);
yspeed = ((starty-ymouse)*0.4)+(yspeed*0.9);
xmouse = xmouse+xspeed;
ymouse = ymouse+yspeed;
drawRectRun(container_mc);
}
}
//////////////////////fla///////////////////////////////
var rect:Rect = new Rect(100, 150, 30, 350, _root, 1);
var down:Boolean;
_root.onMouseDown = function() {
down = true;
_root.onMouseMove = function() {
if (down) {
rect.mouseRound();
rect.drawRectRun();
}
};
};
_root.onMouseUp = function() {
down = false;
};
function onEnterFrame() {
if (down == false) {
rect.rectRun();
}
}
//终于搞定了,呼~~~~~
//以下是效果:
点这里下载演示效果文件