Flash AS3.0 Tutorial: How to load a movie clip in a library into an animation effect convert a movie clip to a class [go]

Source: Internet
Author: User
Tags addchild event listener

Http://www.yindaoxian.com/html/design/flash-11821.html

This example is the Flash AS3.0 rookie to learn a series of tutorials, in this flash AS3.0 tutorial we will learn an eagle flying example of how to download the video clips in storage will be produced animation effect, hope to bring help to friends ~ ~.

Learn AS3.0 rookie take off-download movie clips from storage

In the flash authoring environment, you can drag movie clips from the library onto the stage so that they appear in the SWF file. When you use ActionScript to add a movie clip, you are actually adding an instance of the movie to the timeline. Frames are part of the timeline, and you can use the actions panel to associate the as code with the frame. The timeline is therefore the parent container of the display object added with the as code, unless another display object is specified.

Add a movie clip to the current timeline:
The following example imports a movie clip named "Eagle" from the. FLA Library
1, new Flash document (AS3), save.
2, open the "Eagle" film clips, copied to the library, (here do not explain the production of film editing process).
3, right click on the "Eagle" movie clips, in the Drop-down menu, click "Properties" to open the property panel, check "Export for Astionscript" in the Class: text box input: Hawk, press "OK" as shown:

4, return to Scene 1, select the layer 1 frame, press F9 key, open the action panel input code:

var Myhaw:hawk = new Hawk ();
AddChild (Myhaw);

The first line declares an instance name with Var: Myhaw to the movie clip.
The second line uses the Addchild () command to add the instance Myhaw to the display list.
tip: When the display container is not explicitly specified, the movie clip instance is the current frame that is added to the timeline.

We press Ctrl+enter to test that the movie has been shown on the screen. See unnamed 1.FLA document

5, we have added the movie clip to the timeline, we continue to add code, do an eagle to follow the mouse to move. Open move

As a panel, add the following code:

var Myhaw:hawk = new Hawk ();
Registering Mouse click event Listeners
Stage.addeventlistener (Mouseevent.click, Addhawk);

To define a listener function
function Addhawk (e:mouseevent): void {
AddChild (Myhaw);
}

Registering Mouse Move event listeners
Stage.addeventlistener (Mouseevent.mouse_move, Movehaw);

To define a move event listener function
function Movehaw (e:mouseevent): void {
Place Myhaw in the mouse position
myhaw.x = Stage.mousex;
Myhaw.y = Stage.mousey;
}

The example above uses the handling of events and the declaration of functions. See unnamed 2.FLA document

The following is an example of a movie clip drag-and-drop:

The specific creation process is no longer repeated, referring to the example above

No more nonsense, directly on the code:

Declaring instances
var Myhaw:hawk = new Hawk ();
Add to display list
AddChild (Myhaw);
Myhaw position (x,y coordinates)
myhaw.x = 100;
MYHAW.Y = 100;

Register the mouse to press event listeners
Myhaw.addeventlistener (Mouseevent.mouse_down, Draghaw);
Register mouse to release event listeners
Myhaw.addeventlistener (mouseevent.mouse_up, Drophaw);

Define mouse down event listener functions
function Draghaw (dragevent:mouseevent): void {
Start dragging
Dragevent.currentTarget.startDrag ();
}
Defining mouse Release Event listener functions
function Drophaw (dropevent:mouseevent): void {

Stop dragging
Dropevent.currentTarget.stopDrag ();
}

Press the mouse to drag and drop the object, when the mouse is released, the object will stop following the pointer. See unnamed 3.FLA document

Add a movie clip to a container
The Displayobjectcontainer object (and the object created by the inherited Displayobjectcontainer Class) can contain 0 or more display items.

As with mobile containers, display items in all container objects move relative to the container.

Example:
1, new Flash document (AS3), open the unnamed 1.fla file.
2, use the Library drop-down menu to select the "Unnamed 1.fla" library. As shown in figure:

3, drag the "Eagle" movie clip from the library and put it on the stage.
4, through the Library drop-down menu to select back to the new file library. As shown in figure:

Note:the "eagle" movie clips and related footage are already listed in the current file's library.

5, delete the movie clips on the stage.
6, select the timeline 1th frame, named: As, open the Action panel, enter the code:

Declaring instances
var Myhaw:hawk = new Hawk ();
Add to display list
AddChild (Myhaw);
Myhaw position (x,y coordinates)
myhaw.x = 100;
MYHAW.Y = 100;

Register the mouse to press event listeners
Myhaw.addeventlistener (Mouseevent.mouse_down, Draghaw);
Register mouse to release event listeners
Myhaw.addeventlistener (mouseevent.mouse_up, Drophaw);

Define mouse down event listener functions
function Draghaw (dragevent:mouseevent): void {
Start dragging
Dragevent.currentTarget.startDrag ();
}
Defining mouse Release Event listener functions
function Drophaw (dropevent:mouseevent): void {

Stop dragging
Dropevent.currentTarget.stopDrag ();
}

7, create a new layer, and drag it to the bottom of the as layer and rename it to text. Select frame 1th and use the Text tool to enter on the stage: Click and move Mysprite, to (150,200) coordinate position. (Mysprite is a container for movie clips)

8, test the film. See Unnamed 4.fla files

Flash Player plays the SWF file and, by default, the movie clip appears in the upper-left corner of the stage. An event listener in your code responds to mouse clicks, and when you click anywhere on the stage, the movie clip's registration point is repositioned to 150 pixels above the stage and 200 pixels from the left of the stage.

Related Article

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.