|
5.返回主场景,将默认图层更名为“iron filing”,从库在将影片剪辑“mental”拖放到工作区中创建实例“m”,并为该实例添加如下脚本:
onClipEvent (load) { n = substring(_name, 2, 1); mindis = 200; k = .002; decay = .97; } onClipEvent (enterFrame) { mouse_x = int(_root._xmouse-this._x); mouse_y = int(_root._ymouse-this._y); if (mouse_x>0 && mouse_y>0) { quad = Number(4); } if (mouse_x<0 && mouse_y>0) { quad = Number(1); } if (mouse_x<0 && mouse_y<0) { quad = Number(2); } if (mouse_x>0 && mouse_y<0) { quad = Number(3); } abs_x = Math.abs(mouse_x); abs_y = Math.abs(mouse_y); tg = abs_y/abs_x; _root.leo = Math.atan(tg)*Number(180)/Math.PI; if (quad == 1) { angle = Number(90)-Number(_root.leo); } if (quad == 2) { angle = Number(90)+Number(_root.leo); } if (quad == 3) { angle = Number(270)-Number(_root.leo); } if (quad == 4) { angle = Number(270)+Number(_root.leo); } setProperty (_this, _rotation, angle); x = this._x; y = this._y; mx = _root._xmouse; my = _root._ymouse; disx = math.abs(x-mx); disy = math.abs(y-my); if (math.sqrt(disx*disx+disy*disy)<=mindis and stick eq "") { if (this.hitTest(_root.magnet)) { stick = "yes"; xspace = x-mx; yspace = y-my; } xmov = k*(mx-x)+decay*xmov; ymov = k*(my-y)+decay*ymov; setProperty (this, _x, xmov+x); setProperty (this, _y, ymov+y); } } onClipEvent (mouseMove) { if (stick eq "yes") { setProperty (this, _x, _root._xmouse+xspace); setProperty (this, _y, _root._ymouse+yspace); } }
onClipEvent (enterFrame) 6.新建图层“magnet”,将影片剪辑“magnet”拖放到工作区中创建实例,其实例命为“magnet”,并为其添加如下脚本: onClipEvent (load) { startDrag(this, true); }
7.新建一图层“spreadbutton”,将按钮元件“reset”拖放到工作区的适当位置,并为按键添加如下脚本:
on (press) { _root.m.stick = ""; setProperty(_root.m, _x, Random(550)); setProperty(_root.m, _y, Random(400)); for (i=1; i<=25; ++i) { _root["m"+i].stick = ""; setProperty(_root["m"+i], _x, Random(550)); setProperty(_root["m"+i], _y, Random(400)); } }
8.新建一图层“actions”,该图层主要用来存放脚本以控制影片的动作,其脚本如下所示:
num = 25; n = 1; while (n<=num) { duplicateMovieClip("m", "m" add n, n); setProperty("m" add n, _x, Random(550)); setProperty("m" add n, _y, Random(400)); n = n+1; } 9. 这样整个鼠标中键模拟效果就制作完成,保存作品,按“ctrl Enter”预览最终效果 |