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.