Flash AS实例:随机移动动画特效
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);
}
源文件下载:http://www.itjxue.com/files/soft/1_090118121730.rar