ActionScript uses copy movie Duplicatemovieclip with mouse drag to follow StartDrag to make mouse move effect

Source: Internet
Author: User

The basic usage of ActionScript2.0 was described last time in "ActionScript" ActionScript2.0 HelloWorld (click to open link).

This preparation is intended to use the copy movie Duplicatemovieclip with the mouse drag following startdrag to make the mouse movement effect:


First, the preparatory work

1, first or the same as last time, create a new ActionScript2.0 file, and then save it first. Then, as shown, create a new graphic symbol by inserting a new component, or Ctrl+f8, selecting a graphic in the type, naming it arbitrarily.


2, after, for example, using the Ellipse tool, drag out a central, borderless circle. You can drag a circle first, and then use the selection tool to set its size and position in position and size. The X and y of the general position are half the opposite of the width and height, and the Ellipse tool is in the center of the component.


3, then insert a component, but this time the type is a movie clip. Name the title of the movie clip and be controlled by the script in a moment. Assuming this is ball_move, click OK.


4. Open the Library panel, or simply click F11 to drag the newly created component into the movie clip.


5, the 1th frame dragged into the component, the use of the selection tool, the location and size of the property to modify, the X, y are changed to 0, 0 let the element Center. After that, a keyframe is inserted at frame 20th, and the color effect of setting its alpha (transparency) is 0. Between frames 1th through 20th, for example, create a classic tween. Then click on "Scene 1" in the upper right corner and switch to the stage to start writing code.



Second, script programming

1. Drag the movie clip from the library to frame 1th of Scene 1, and click on the movie clip with the selection tool to modify its instance name to Ball_move, such as:


2. Then, right-click the 1th frame, open the actions panel and write directly to the following script:

var num = 0;if (num = = 0) {//_root is the position that refers to the timeline, that is, the Ball_move movie clip in the timeline//true the drag center position, specifies that the draggable movie clip is locked to the center of the mouse position//That is, if you num=0 and drag the mouse, The center of this movie clip is startdrag to its mouse ("_root.ball_move", True);} After the else{//is a copy of the entire movie clip, with Num's self-increment, the name of the new movie clip is BALL1_MC,BALL2_MC ... The new movie clip is in the NUM layer, and if the first NUM layer already has a movie clip covered///Because the movie clip is constantly playing, you can create a good video effect by constantly replacing the previously copied movie clip. Duplicatemovieclip ("_root.ball_mc", ("ball") + num + "_MC", num + 1), num = num + 1;//Here The num>20 begins again, and is echoed with a movie clip with 20 frames if (Num > 20) {num = 0;}}

Press Ctrl+enter to run and get the above effect.

ActionScript uses copy movie Duplicatemovieclip and mouse drag to follow StartDrag to make mouse movement effects

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.