[Flash Basic theory Class 09] stars and Changing lines [onenterframe]

Source: Internet
Author: User
Tags setinterval

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,也就是调用这个函数的实例名。

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.