liyuqing112 发表于 2009-3-1 14:27:17

用Flash制作神奇的弹性导航菜单(3)

10、接下来将用简单的脚本来实现h1、h2 、h3的" 痉挛抽动"效果,点选主场景第一帧,添加如下代码:

  _root.onEnterFrame = function() {
    clear();
    _root.lineStyle(1.5, 0xcecece);
    _root.moveTo(_root.h1._x, _root.h1._y);
    _root.lineTo(_root.h2._x, _root.h2._y);
    _root.lineTo(_root.h3._x, _root.h3._y);
    _root.lineTo(_root.h1._x, _root.h1._y);
    _root.endFill();
  }

  后面加上如下脚本:

  setInterval(myball1, 6000);
  function myball1() {
    if (_root.h1.hitTest(_root._xmouse, _root._ymouse, false)) {
      _root.h1._x = _root._xmouse;
      _root.h1._y = _root._ymouse;
    } else {
      _root.h1._x= 70-random(150);  ||设置MC的随机坐标
      _root.h1._y= 50-random(150);
    }
  }
  setInterval(myball2, 5000);
  function myball2() {
    if (_root.h2.hitTest(_root._xmouse, _root._ymouse, false)) {
      _root.h2._x = _root._xmouse;
      _root.h2._y = _root._ymouse;
    } else {
      _root.h2._x= 70-random(140);
      _root.h2._y= 60-random(150);
    }
  }
  setInterval(myball3, 4000);
  function myball3() {
    if (_root.h3.hitTest(_root._xmouse, _root._ymouse, false)) {
      _root.h3._x = _root._xmouse;
      _root.h3._y= _root._ymouse;
    } else {
      _root.h3._x= 70-random(80);
      _root.h3._y= 50-random(90);
    }
  }

  其中if (……)这个判断是为了消除鼠标drag的时候由于自定义函数的反复调用,MC坐标发生变化后出现的一个问题。至此,就实现了利用setInterval隔一段时间就反复调用自定义函数使MC的坐标随机发生变化,偏离原来的坐标, 从而实现MC的" 痉挛抽动 "效果。

  赶快把这个神奇的导航菜单加到你的网站吧,一定可以使你的主页在浩瀚的网络中脱颖而出!
fla源文件下载
页: [1]
查看完整版本: 用Flash制作神奇的弹性导航菜单(3)