弹性矩形条的类原码 |
| 作者:佚名 来源:闪吧 作者: ycccc8202 更新:2007-1-13 20:48:59 错误报告 我要投稿 |
//////////////////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(); } }
//终于搞定了,呼~~~~~
//以下是效果:
点击浏览该文件
|
|
| 文章录入:skyuu 责任编辑:skyuu |
|
| 【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |