Back to "flash Basic Theory Class-Catalog"
Example 1:
Train of thought: 1. Use setinterval timer, constantly call the function of copying stars;
2. After each star is created, it continuously reduces its own _alpha until 0.
Step 1:
Draw a star, Save as a movie clip, and connect-> Export the-> marker "star".
Step 2:
Add as code:
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++;
}
Attention:
MC.onEnterFrame = function() {
this._x += 2;
this._y += 3;
this._rotaion += 3;
};
//this指的就是MC,也就是调用这个函数的实例名。