图4 9、最后使用Flash MX的画线指令把它们用线一一连接起来,在主场景中新建一层,命名为AS ,在第一帧加如下代码:
_root.onEnterFrame = function() {
clear(); ||清除以前的填充设置
_root.lineStyle(1.5, 0xcecece); ||定义画线的样式
_root.moveTo(_root.h1._x, _root.h1._y); ||把线的始端定在h1坐标处
_root.lineTo(_root.h2._x, _root.h2._y); ||从h1画一条线到h2
_root.lineTo(_root.h3._x, _root.h3._y); ||从h2画一条线到h3
_root.lineTo(_root.h1._x, _root.h1._y); ||从h3画一条线到h1
_root.endFill(); || 结束 Fill
}
接着来设置h1、h2 、h3 的鼠标吸引及缓冲效果,点选主场景中的h1,给其加上如下代码:
onClipEvent (load) { ||初始化变量
x = this._x;
y = this._y;
}
onClipEvent (enterFrame) { ||实现鼠标的吸引效果以及MC(h1)的缓冲效果
dis_x = _root._xmouse - x;
dis_y = _root._ymouse - y;
if(!drag){
if ((dis_x * dis_x) (dis_y * dis_y) < 1500) { ||判断鼠标和MC的距离
newvar_x = _root._xmouse; ||把_root._xmouse 、_root._ymouse赋给
newvar_y = _root._ymouse; ||两个新变量newvar_x 、newvar_y ,此时还没有
} else { ||与MC相联系。
target_x = x;
target_y = y;
}
||设置缓冲效果,可以更改一下具体的参数,体会体会缓冲的效果
xspeed = ((target_x - this._x)*.8) (xspeed*.65);
this._x = xspeed;
yspeed = ((target_y - this._y)*.8) (yspeed*.65);
this._y = yspeed;
}
}
然后复制上面的代码,分别给 h2 、h3设置。以上鼠标吸引及缓冲效果的代码还隐藏这样的一个效果,即MC只要偏离原来的坐标就会自动回位。这样,只要隔一段时间就改变MC的位置,则可以实现MC 的" 痉挛抽动 "的效果。
| 欢迎光临 江西广告网 (http://bbs.jxadw.com/) | Powered by Discuz! X3.2 |