当前位置: 首页 > 图文教程 > Flash动画 > ActionScript > Flash AS教程:蝌蚪摆尾动画

ActionScript
将FlashVars写在JS函数中,实现变量更新与后台同步
Flash与Flex3结合学习心得体会
Flash AS简单制作画线条动画
Flash教程:如何把库中的元件加载到场景中
Flash AS3运行错误参考文档
Flash AS3制作自由落体运动代码解析
多层级加载相对路径遇到的问题解决方法
加载PNG后其透明区域不响应事件
AS3教程:按顺序播放多个FLV视频
Flash AS与JS的互动
Flash AS实例:智力过河小游戏源代码
Flash as教程:图片模糊运动
Flash AS3实例教程:物体运动速度向量(velocity)
Flash AS3.0教程:学习帧循环的运用
Flash AS3动态改变影片剪辑元件颜色
Flash AS 制作创意的鼠标经过的网页导航
Flash AS实例教程 会眨眼的美女
Flash AS2实例 跳动的小球动画效果
Flash AS3实例:制作好看的七彩小球动画
AS2.0高级滤镜效果如何用在JPG图片上

ActionScript 中的 Flash AS教程:蝌蚪摆尾动画


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-16   浏览: 173 ::
收藏到网摘: n/a

本例介绍使用Flash的AS编写蝌蚪摆尾动画效果,希望朋友们喜欢~~
  先看最终效果

  


  场景里代码

  Object.environment = this;

  Math.prototype.degrees = function (r)

  {

  return (r * 180 / 3.141593E 000);

  };

  maxtents = 3;

  this.onEnterFrame = function ()

  {

  if (!random(30) && tents < maxtents)

  {

  var nombre = "tent"   String(depth  );

  var neo = this.attachMovie("tentacle", nombre, depth);

  neo._x = random(600);

  neo._y = 370;

  neo.theta = 270;

    tents;

  } // end if

  };

  stop ()



  #initclip 1

  function TentacleClass()

  {

  this.numNodes = 27;

  this.head = 2   random(4);

  this.girth = 8   random(12);

  this.speedCoefficient = 9.000000E-002   random(10) / 50;

  this.friction = 9.000000E-001   random(10) / 100;

  this.muscleRange = 20   random(50);

  this.muscleFreq = 1.000000E-001   random(100) / 250;

  this.generateNodes();

  this.onEnterFrame = this.move;

  } // End of the function

  TentacleClass.prototype = new MovieClip();

  TentacleClass.prototype.generateNodes = function ()

  {

  this.node = new Array();

  var n = 0;

  while (n < this.numNodes)

  {

 
  var point = {x: 0, y: 0};

  this.node.push(point);

    n;

  } // end while

  };

  TentacleClass.prototype.move = function ()

  {

  this.tv = this.tv   5.000000E-001 * (Math.random() - Math.random());

  this.theta = this.theta   this.tv;

  this.tv = this.tv * this.friction;

  this.node[0].x = this.head * Math.cos(1.745329E-002 * this.theta);

  this.node[0].y = this.head * Math.sin(1.745329E-002 * this.theta);

  this.count = this.count   this.muscleFreq;

  this.thetaMuscle = this.muscleRange * Math.sin(this.count);

  this.node[1].x = -this.head * Math.cos(1.745329E-002 * (this.theta   this.thetaMuscle));

  this.node[1].y = -this.head * Math.sin(1.745329E-002 * (this.theta   this.thetaMuscle));

  var i = 2;

  while (i < this.numNodes)

  {

  var dx = this.node.x - this.node[i - 2].x;

  var dy = this.node.y - this.node[i - 2].y;

  var d = Math.sqrt(dx * dx   dy * dy);

  this.node.x = this.node[i - 1].x   dx * this.girth / d;

  this.node.y = this.node[i - 1].y   dy * this.girth / d;

  if (i == 2)

  {

  this._x = this._x - dx * this.speedCoefficient;

  this._y = this._y - dy * this.speedCoefficient;

  if (this._x   this._width < 0    this._x - this._width > 600    this._y   this._height < 0    this._y - this._height > 400)

  {

  --Object.environment.tents;

  this.removeMovieClip();

  } // end if

  } // end if

    i;

  } // end while

  this.clear();

  this.moveTo(this.node[1].x, this.node[1].y);

  var i = 2;

  while (i < this.numNodes)

  {

  this.lineStyle(int(this.numNodes - i) * (this.numNodes - i) / 20, 16777215, 100);

  this.lineTo(this.node.x, this.node.y);

    i;

  } // end while

  };

  Object.registerClass("tentacle", TentacleClass);

  #endinitclip