Flash drag-and-drop command detailed introduction

Source: Internet
Author: User
Tags range
Note: The following tutorials are in the Flash MX 2004 version!

Some of the objects in the Flash movie you see on the web can be dragged by the mouse. For example, some similar tangram puzzle game, control volume slider, etc., using the flash in the drag action. Recently in the forum was asked to explain the implementation of the mouse drag and drop effect, today from the Internet to find a few articles synthesized from the next to everyone to explain!

Let me explain the drag-and-drop command.

1. First, introduce the detailed use of the start drag command, later in the following example to test.

Command format: StartDrag (the movie clip that you want to drag, [lock to the center of the mouse position, left, top, right, bottom]) or write to the movie clip you want to drag. StartDrag ([Lock to mouse position center, left, top, right, bottom])

command to explain: in the process of making animation, the above two writing methods can be optional. Within [] The optional parameters, that is, can write, or can not write. As for the left, top, and right, the next four parameters are used to control the moving range of the dragged object.

2. Stop dragging and dropping commands to explain

Command format: A dragged movie clip instance name. Stopdrag ()

This allows you to stop dragging and dropping objects.

Second, the example explanation

Here's a simple example of an experimental drag-and-drop command.

Operation Steps:

1, create a new flash document, and draw a circle on the stage. Select the circle and press F8 to convert the circle to a movie clip named: Circle. When you are sure, you will create an instance of the circle on the stage. The following figure:

2. Select this instance and press F9 to open the action panel. Enter the following script:

On (Press) {

This.startdrag (TRUE)///When the mouse presses (press), this instance (because we write the script in the instance itself, so here instead of the name of the movie clip instance) can be dragged, using the command as explained above. For the selection of parameters, here is only a lock to the center of the mouse position, if you want to choose not to lock to the center of the mouse position, you can change to false. Interested friends can change to false to see.

}

On (release) {

This.stopdrag ()//In the same way, when the Mouse is released (release), the drag action stops.
}

3, OK, now let's press CTRL + ENTER to test it, you will see the stage on the circle by your mouse drag effect.

Click here to download the source file

4, OK, through this example we can simply use drag and drop action. Now you need to continue with this example, remember the instructions above to the left, top, right, and down four parameters that control the drag range? Now to make an effect that has a constrained drag range.

5, now on the stage to draw a 200*100 size rectangle, note that as long as the border does not fill. The following figure:


6, if we want to drag when the circle can only be dragged in the rectangle, it is necessary to set the coordinates of the rectangle, and note the four vertices of the rectangle coordinates (this is very important!) )。 OK, for example, now the four vertices of the rectangle in this example are shown above. Then we have to take the four parameters should be: Left = 50, on = 100, right = 250, under = 200 now open the action panel, modify the script just as follows:

On (Press) {
This.startdrag (True, 50, 100, 250, 200);//Here we'll use the 4 parameters we just identified. The 4-point parameter implements a rectangular region's movement constraint on the Drag object!
}
On (release) {
This.stopdrag ();
}

7, hehe, can't wait to test your results? OK, press CTRL + ENTER to test it!

Click here to download the source file



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.