

| var n:Number = 0; onMouseMove = function () { p = _root.attachMovie("Star", "Star"+n, n); p._x = _xmouse; p._y = _ymouse; p.onEnterFrame = function() { this._rotation += 5; this._xscale += 5; this._yscale += 5; this._alpha -= 5; if (this._alpha<0) { this.removeMovieClip(); delete this.onEnterFrame; } }; n++; }; |
思路:1、使用setInterval计时器,不断调用复制星星的函数;
2、每颗星星被创建后,不断减小其自身的_alpha直至0。
步骤1:
绘制星形,保存为影片剪辑,连接—>导出—>标志符"star"。
步骤2:加入AS代码:
| var n:Number = 0; //初始化,复制影片的记数器n setInterval(CreateStar, 200); //每200毫秒,调用一次函数CreateStar() function CreateStar() { p = _root.attachMovie("Star", "Star"+n, n); //用指针p指向,复制出的影片"Star"+n,此时p就等于"Star"+n p._x = random(400); p._y = random(200); //随机设置当前p所指的影片的坐标 p.onEnterFrame = function() { //”Star”+n的onEnterFrame中不断降低该影片的_alpha直至0 this._alpha -= 5; if (this._alpha<0) { this.removeMovieClip(); delete this.onEnterFrame; //影片的_alpha小于0时,影片就没有存在的意义了,直接删除这个影片 } }; n++; } |
注意:

| MC.onEnterFrame = function() { this._x += 2; this._y += 3; this._rotaion += 3; }; |
//this指的就是MC,也就是调用这个函数的实例名。
实例2:
思路:按照实例1的方法,如法炮制,只改为鼠标经过,再多加些效果而以。
步骤1:绘制星形,保存为影片剪辑,连接—>导出—>标志符"star"。
步骤2:加入AS代码:
| var n:Number = 0; onMouseMove = function () { p = _root.attachMovie("Star", "Star"+n, n); p._x = _xmouse; p._y = _ymouse; p.onEnterFrame = function() { this._rotation += 5; this._xscale += 5; this._yscale += 5; this._alpha -= 5; if (this._alpha<0) { this.removeMovieClip(); delete this.onEnterFrame; } }; n++; }; |
//与实例1不同处用红字标出,不再加以说明。
实例3:变幻线
思路:1、两个空MC之间连线。
2、每个点都有各自的MC.onEnterFrame,在不停的移动;
3、用_root.onEnterFrame 连接舞台中各点。
| var num:Number = 5; //点的个数 var StageW = Stage.width; var StageH = Stage.height; //舞台的宽度(StageW),舞台的高度(StageH) for (i=0; i<num; i++) { p = _root.createEmptyMovieClip("dot"+i, i); p._x = random(StageW); p._y = random(StageH); //随机分配该点的X,Y坐标 p.xspeed = 10+int(random(20)); p.yspeed = 10+int(random(20)); //xspeed:向x方向移动的速度;yspeed:向y方向移动的速度 p.onEnterFrame = function() { if (this._x<=0 || this._x>=StageW) { this.xspeed *= -1; } if (this._y<=0 || this._y>=StageH) { this.yspeed *= -1; } //判断是否出了上下左右界,若出界,运动方向为反向(乘以-1) this._x += this.xspeed; this._y += this.yspeed; }; } _root.onEnterFrame = function() { _root.createEmptyMovieClip("line", -1); with (line) { lineStyle(2, 0x0f00ff); moveTo(dot0._x, dot0._y); for (n=1; n<num; n++) { lineTo(_root["dot"+n]._x, _root["dot"+n]._y); } lineTo(dot0._x, dot0._y); } }; //连接每个点 |
相关文章
最新评论共有 0 位网友发表了评论
发表评论
赛酷网·中国西部第一建站门户
阅读排行
设计素材