论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Flash教程
Tag:flash cs,flash 8,鼠绘,as,手绘,工具,文字,loading,入门,初学,mc,影片剪辑,声音,mtv,游戏,引导,遮罩,菜单,补间,广告条,时钟,视频教程

仿屏保的折线 曲线运动效果

文章类别:Flash | 发表日期:2008-9-21 15:52:53

  新建一MC元件,在MC的时间轴上写入下面的代码:
this._x = this._y = 0; 
total = 5; 
myColor = random(0xffffff); 
speed = 5; 
for (i = 0; i < total; i++) { 
 createEmptyMovieClip("mc" + i, i); 
 this["mc" + i]._y = random(Stage.height); 
 this["mc" + i]._x = random(Stage.width); 
 this["mc" + i].xsp = random(speed) + 5; 
 this["mc" + i].ysp = random(speed) + 5; 

onEnterFrame = function () { 
 r = Math.floor(random(5)); 
 g = Math.floor(random(10)); 
 b = Math.floor(random(20)); 
 //myColor += r << 32 + g << 16 + b; 
 //myColor &= 0xffffff; 
 for (i = 0; i < total; i++) { 
  with (this["mc" + i]) { 
   _x = _x + xsp; 
   _y = _y + ysp; 
   if (_x > Stage.width || _x < 0) { 
    xsp = -xsp; 
    myColor += r << 32 + g << 16 + b; 
    myColor &= 0xffffff; 
   } 
   if (_y > Stage.height || _y < 0) { 
    ysp = -ysp; 
    myColor += r << 32 + g << 16 + b; 
    myColor &= 0xffffff; 
   } 
  } 
 } 
 createEmptyMovieClip("xian", 100); 
 with (xian) { 
  lineStyle(2, myColor, 100); 
  start_pt_x = (mc0._x + this["mc" + (total - 1)]._x) / 2; 
  start_pt_y = (mc0._y + this["mc" + (total - 1)]._y) / 2; 
  moveTo(start_pt_x, start_pt_y); 
  for (i = 0; i < total - 1; i++) { 
   ctl_pt_x = this["mc" + i]._x; 
   ctl_pt_y = this["mc" + i]._y; 
   end_pt_x = (this["mc" + (i + 1)]._x + this["mc" + i]._x) / 2; 
   end_pt_y = (this["mc" + (i + 1)]._y + this["mc" + i]._y) / 2; 
   curveTo(ctl_pt_x, ctl_pt_y, end_pt_x, end_pt_y); 
  } 
  ctl_pt_x = this["mc" + (total - 1)]._x; 
  ctl_pt_y = this["mc" + (total - 1)]._y; 
  end_pt_x = (this["mc0"]._x + this["mc" + (total - 1)]._x) / 2; 
  end_pt_y = (this["mc0"]._y + this["mc" + (total - 1)]._y) / 2; 
  curveTo(ctl_pt_x, ctl_pt_y, end_pt_x, end_pt_y); 
 } 
}; 
在主场景中拖入三个该元件,效果如下:
http://blog.5d.cn/user12/dzxz/upload/2006-07/3_131.swf
绘制折线的代码如下:
this._x = this._y = 0; 
total = 6; 
myColor = random(0xffffff); 
speed = 5; 
for (i = 0; i < total; i++) { 
 createEmptyMovieClip("mc" + i, i); 
 this["mc" + i]._y = random(Stage.height); 
 this["mc" + i]._x = random(Stage.width); 
 this["mc" + i].xsp = random(speed) + 5; 
 this["mc" + i].ysp = random(speed) + 5; 

onEnterFrame = function () { 
 r = Math.floor(random(5)); 
 g = Math.floor(random(10)); 
 b = Math.floor(random(20)); 
 //myColor += r << 32 + g << 16 + b; 
 //myColor &= 0xffffff; 
 for (i = 0; i < total; i++) { 
  with (this["mc" + i]) { 
   _x = _x + xsp; 
   _y = _y + ysp; 
   if (_x > Stage.width || _x < 0) { 
    xsp = -xsp; 
    myColor += r << 32 + g << 16 + b; 
    myColor &= 0xffffff; 
   } 
   if (_y > Stage.height || _y < 0) { 
    ysp = -ysp; 
    myColor += r << 32 + g << 16 + b; 
    myColor &= 0xffffff; 
   } 
  } 
 } 
 createEmptyMovieClip("xian", 100); 
 with (xian) { 
  lineStyle(2, myColor, 100); 
  moveTo(mc0._x, mc0._y); 
  for (i = 0; i < total -1 ; i++) { 
   lineTo(this["mc" + i]._x, this["mc" + i]._y); 
  } 
  lineTo(mc0._x, mc0._y); 
 } 
}; 
效果如下:
http://blog.5d.cn/user12/dzxz/upload/2006-07/3_621.swf
欢迎访问我的博客 http://dzxz.blog.5d.cn
视频教程列表
文章教程搜索
 
Flash推荐教程
Flash热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058