当前位置: 首页 > 图文教程 > Flash动画 > ActionScript > Flash AS实例:随机移动动画特效

ActionScript
Flash as入门(4):AS常用语句
Flash as入门(5):学习AS数组
Flash as入门(6):文本与字符串⒒
Flash AS3鼠标事件使用详解
网页中flash的trace方法输出数据
Flash as入门(11):拖动与碰撞检测
AS教程:随机显示数字
Flash AS文本字段的透明度alpha变换
AS教程:对场景和MC添加鼠标监听
AIR设置:transparent和systemChrome
Flash AS3教程:flash.text.TextField
AS教程:理解变量作用域修饰符(modifier)
ActionScript3.0中类间传值问题解决
ActionScript3.0中类的定义以及类属性
Flash AS3教程:类属性的属性
ActionScript3.0教程:变量
ActionScript3.0教程:方法
ActionScript3.0教程:类的枚举
简单认识Flash as面向对象编程
Flash AS2教程:影片剪辑

ActionScript 中的 Flash AS实例:随机移动动画特效


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

Flash AS实例:随机移动动画特效。

效果:

AS代码:

  package {

  import flash.display.MovieClip;

  import flash.events.Event;

  public class main extends MovieClip {

  public function main() {

  }

  public function hs(_mc:MovieClip) {

  var dx:int=10;

  var dy:int=10;

  var jiaodu:Number=Math.random()*(2*Math.PI);

  _mc.addEventListener(flash.events.Event.ENTER_FRAME,enter_f);

  function enter_f(e:Event) {

  e.target.x+=Math.cos(jiaodu)*dx;

  e.target.y+=Math.sin(jiaodu)*dy;

  if (e.target.x+e.target.width>stage.stageWidth) {

  dx*=-1;

  e.target.x-=10;

  }

  if (e.target.x<0) {

  dx*=-1;

  e.target.x+=10;

  }

  if (e.target.y+e.target.height>stage.stageHeight) {

  dy*=-1;

  e.target.y-=10;

  }

  if (e.target.y<0) {

  dy*=-1;

  e.target.y+=10;

  }

  }

  }

  }

  }

  //

  var _mc:mc;

  for(var i:uint;i<10;i++){

  _mc=new mc();

  _mc.x=stage.stageWidth*Math.random();

  _mc.y=stage.stageHeight*Math.random();

  addChild(_mc);

  hs(_mc);

  }

源文件下载:/upload/tech/20091001/20091001053814_6766aa2750c19aad2fa1b32f36ed4aee.rar