flash as3求翻译

来源:百度知道 编辑:UC知道 时间:2024/06/07 03:02:27
stage.addEventListener(MouseEvent.CLICK,onclick);
function onclick(e:MouseEvent):void {
var mc :MovieClip=new MovieClip();
mc.graphics.beginFill(0xffffff* Math.random());
mc.graphics.drawCircle(0,0,10+20* Math.random());
//mc.alpha(0.5* Math.random());
mc.graphics.endFill();
//trace(mc);
addChild(mc);
mc.x=mouseX;
mc.y=mouseY;
mc.vx=10*Math.random()-5;
mc.vy=10*Math.random()-5;
mc.addEventListener(Event.ENTER_FRAME,frame);
}
function frame(e:Event):void {
var mc:MovieClip=e.target as MovieClip;
mc.x+=mc.vx;
mc.y+=mc.vy;
if (mc.x>=550-mc.width/2) {
mc.x=550-mc.width/2;
mc.vx=- mc.vx;//
}
if (mc.x<=mc.width/2) {
mc.x=mc.width/2;
mc.vx=- mc.vx;
}
if (mc.y>=400-mc.height/2) {
mc.y=400-mc.height/2;
mc.vy=- mc.vy;
}
if (mc.y<=mc.height/2) {
mc.y=mc.height/2;
mc.vy=- mc.vy;
}

stage.addEventListener(MouseEvent.CLICK,onclick);//给舞台加一个鼠标点击事件
function onclick(e:MouseEvent):void {
var mc :MovieClip=new MovieClip();//定义一个影片剪辑
mc.graphics.beginFill(0xffffff* Math.random());//影片剪辑的颜色
mc.graphics.drawCircle(0,0,10+20* Math.random());//绘制随机大小的圆
//mc.alpha(0.5* Math.random());
mc.graphics.endFill();
//trace(mc);
addChild(mc);//将影片剪辑放到舞台上
mc.x=mouseX;//它的坐标为鼠标点击的坐标
mc.y=mouseY;
mc.vx=10*Math.random()-5;//影片剪辑的移动速度
mc.vy=10*Math.random()-5;
mc.addEventListener(Event.ENTER_FRAME,frame);//给影片剪辑加帧事件
}
function frame(e:Event):void {
var mc:MovieClip=e.target as MovieClip;
mc.x+=mc.vx;
mc.y+=mc.vy;
//后面的代码是检测影片剪辑是否到达舞台边缘,如果是,刚方向相反,继续运动
if (mc.x>=550-mc.width/2) {
mc.x=550-mc.width/2;
mc.vx=- mc.vx;//
}
if (mc.x<=mc.width/2) {
mc.x=mc.width/2;
mc.vx=- mc.vx;
}
if (mc.y>=400-mc.height/2) {
mc