Lesson 4 second animation: control plane movement

Source: Internet
Author: User
Reproduced http://xiaomin1978.blog.51cto.com/6098465/1033012

Course Content: The program controls the video clips created in Flash ide. the straight lines in the previous article are directly generated by the program, and the planes in this article are created in IDE.

Course Effect: The Plane moves from the upper left corner along the Y = 2x straight to the lower right corner

Knowledge point:

1. Create SWC resources in Flash CS

2. Use SWC resources in flashdevelop

3. Create a SWC resource object and control its motion

Main Steps

1. Create the Flash file plane. fla in Flash CS, import the airplane image, and export the Flash file as a SWC resource. For details, refer to Chapter 2 using movieclip in Flash CS (video clip)

2. Create a secondanimation project in flashdevelop, copy plane. SWC to the lib directory, and add it to the library.

3. Modify the main. As program to control aircraft movement

The red code has been injected.

Package

{

Import flash. display. Sprite;

Import flash. Events. event;

/**

*...

* @ Author happydagui

*/

Public class main extends Sprite

{

Private var DX: int;

Private var plane: plane;

Public Function main (): void

{

If (stage) Init ();

Else addeventlistener (event. added_to_stage, init );

// Declare an event to move an object at each frame

Addeventlistener (event. enter_frame, myenterframe );

}

Private function Init (E: event = NULL): void

{

Removeeventlistener (event. added_to_stage, init );

// Entry point

// Initialize the scene and add the plane to the stage

DX = 0;

Plane = new plane ();

Addchild (plane );

}

Public Function myenterframe (Event: Event): void

{

If (dx & lt; 200)

{

// Step size plus 1, each frame plus 1 pixel

Dx + = 1;

// Along the line y = 2x

Plane. x = DX;

Plane. Y = 2 * DX;

}

}

}

}

Press Ctrl + enter to run the program.

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.