Basic Tutorials | drag
This article is intended for as beginners and friends who are interested in ActionScript. There are some deficiencies also please advise.
First look at the effect:
http://www.flash8.net/bbs/UploadFile/2005-5/200551917327317.swf
The steps are as follows:
1. Create a new flash document, 400x300 pixels, black background color (#000000);
2. Use the Ellipse tool to draw a 30x30 pixel's positive circle on the scene, the border line is not, the fill color is radial. (Can be in your own favorite color)
3. Click on the ellipse, press F8 to convert the ellipse to a movie clip, named Ball, as shown below:
4. Select the ball component on the scene, press F9 to open the action panel, and write the following code. The following figure:
On (Press) {
This.startdrag (); Click the mouse to start dragging;
}
On (release) {
This.stopdrag (); Left mouse button loosened stop drag;
}
Press the Ctrl+enter test to see.
You try to write this code to see what happens?
On (Press) {
This.startdrag ();
}
You can make a lot of string effects as long as you play your imagination.
I am here just a point of action, the most important thing is to do more hands, to extrapolate.
The above has made a drag ball, but a friend who likes to think about it may have seen its limitations. This is the ball. It can be dragged throughout the document, but sometimes we don't need to, we just want it to drag in a certain range, how do we do that? Let's explore the following:
Let's look at the format of the command first:
StartDrag (Target,[lock, left, top, right, bottom])
Where parameters:
StartDrag is the beginning of the drag means
Target refers to the destination path of the dragged movie clip.
Lock is a logical value that specifies whether the drag movie clip is locked to the center of the mouse position (true), or to the position where the user first clicks the movie clip (false). This parameter is optional.
The values of left, top, right, and bottom relative to the movie clip's parent coordinates, which specify the constraint rectangle for the movie clip. These parameters are also optional.
Good! Understand the command format after we continue.
is to change the code for the line! The following figure:
On (Press) {
This.startdrag (100,300,300,100); Click the mouse to start dragging; I just specify the range that it drags
}
On (release) {
This.stopdrag (); Left mouse button loosened stop drag;
}
Try, is not only in the range you only set to drag it!