Flash as 3.0 Novice Learning to fly Tutorial: Frame Cycle Learning Example

Source: Internet
Author: User

Multi-frame loops

The frames in Flash are cycled by default, and the leased gotoAndPlay () function implements a simple frame loop, which implements repeated execution of the code.

The purpose of the gotoAndPlay () function is to control or change the playback flow of a movie clip, if you place a program that needs to be repeated in frame 1th of the movie, and then add the gotoAndPlay (1) statement in frame 2nd. Repeated execution of the 1th frame screen program, then the gotoAndPlay () function constitutes a loop program structure.

The gotoAndPlay () function has no conditional judgment function and is an unconditional repetitive loop structure. But can be used with the IF statement. Form a loop that has the function of judging termination conditions.

The following frames are used to make uniform motion:

1. New Flash Document

2, in layer 1 of the first frame to create an instance of a movie clip named MC

3, new as layer, click the 1th frame input code:

//得到mc的横坐标
  var dx:Number = mc.x;
//定义速度
  var speed:Number = 10;

4, in the as layer of the 2nd frame insert blank frame, input code;

//横坐标加上速度
dx += speed;
//设置mc的横坐标
  mc.x = dx;

5, in the as layer of frame 3rd insert a blank frame, input code:

//判断是否超出舞台边界
  if(dx < stage.stageWidth)
{
//跳到第2帧并播放
  this.gotoAndPlay(2);
//如超出舞台的右边界
 } else
{
//停止播放
 this.stop();
}

Stage is an instance of the stage class, and the stage class is known as a Stagewidth property that represents the width of the stage.

6, test the movie, you can see the movie instance will always move to the right edge of the stage.

Judging from the test results, the motion of the film is not smooth, which is related to frame frequency and frame cycle structure. The flash default frame rate is 12FPS, which is played 12 frames a second. The above program because of the use of frame jump statements, the actual need for every two frames to perform the 2nd frame of the code once, that is, the 2nd frame code Execution frequency is 6FPS, so the animation effect will appear not smooth.

Layer Structure diagram:

The above example executes code at only half the speed of the frame, and the code is fragmented, and is not suitable for complex applications. We can use the Enterframe event to execute code at a frame rate, and the code can be centered in one frame.

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.