Macromedia Flash - The object moves with the mouse click position

With this exercise, we will show you how to create an object that will move with the mouse click position using the Action Script.

Step 1

Create a new Flash file and set Width and Height to 300px. Frame rate set to 45fps (Frame number per second)

Step 2

Double click on layer 1 and rename it to Background . Set the background color to # B8FECA or whatever color you like.

Step 3

Add a new layer and name it Object . Then create any object that you want it to run according to the click position.

Step 4

Select the object you created (Ctrl + A) and press F8 on the keyboard ( Convert to Symbol ) to convert it into a Movie Clip.

Macromedia Flash - The object moves with the mouse click position Picture 1

Step 5

Select Movie Clip ' Ob ject'> open Properties (Ctrl + F3) and enter the object content (as shown below).

Macromedia Flash - The object moves with the mouse click position Picture 2

Step 6

Continue to select the object, open the Action Script (F9) and enter the following script content:

onClipEvent (load) {
friction = "0.18";
targetx = Random (300) +20;
targety = Random (300) +20
}

onClipEvent (enterFrame) {
mouse_x = int (targetx-this._x);
mouse_y = int (targety-this._y);
if (mouse_x> 0 && mouse_y> 0) {
quad = Number (4);
}

if (mouse_x0) {
quad = Number (1);
}

if (mouse_xquad = Number (2);
}

if (mouse_x> 0 && mouse_y <0) {
quad = Number (3);
}

abs_x = Math.abs (mouse_x);
abs_y = Math.abs (mouse_y);
tg = abs_y / abs_x;
_root.maths = Math.atan (tg) * Number (180) /Math.PI;
if (quad == 1) {angle = number (90) - number (_root.maths)}
if (quad == 2) {angle = number (90) + number (_root.maths)}
if (quad == 3) {angle = number (270) - number (_root.maths)}
if (quad == 4) {angle = number (270) + number (_root.maths)}
if (not _root.done) {setProperty (_this, _rotation, angle); _root.done = true} _root.done = true}
speedx = difx * friction;
speedy = dify * friction;
setProperty (this, _y, _root.object._y + speedy);
setProperty (this, _x, _root.object._x + speedx);
difx = int (targetx) -this._x;
dify = int (targety) -this._y;
}

Step 7

Add a new layer and name it Circle . Select the Oval Tool (O)

- Fill Color : to colorless mode

- Stroke color : choose the color you like

- The contours of the circle: select the stroke or whatever you want

Macromedia Flash - The object moves with the mouse click position Picture 3

Macromedia Flash - The object moves with the mouse click position Picture 4

Step 8

Select the circle and press F8 to convert that circle into a Movie Clip

Macromedia Flash - The object moves with the mouse click position Picture 5

Step 9

Still select Movie Clip ' Circle '> Properties (Ctrl + F3) and enter the circle content for the part

Macromedia Flash - The object moves with the mouse click position Picture 6

Step 10

Double-click on the Movie Clip ' Circle ' or right-click and choose Edit in Place .

Step 11

Still select the circle> press F8 key to convert it to Movie Clip and name it circle_inside

Macromedia Flash - The object moves with the mouse click position Picture 7

Step 12

Click Frame 10 and press F6 key. Then open Action Script and enter the following script:

gotoAndPlay (1);

Step 13

Return to Frame 1, open Properties

- At Tween choose Motion

- At Rotate choose CCW

Macromedia Flash - The object moves with the mouse click position Picture 8

Macromedia Flash - The object moves with the mouse click position Picture 9

Step 14

Go back to the main scene (Scene 1), select the Circle layer, open Action Acript (F9) and enter the following script content:

onClipEvent (load) {
startDrag (this, true);
_root.drag = this;
}

onClipEvent (mouseDown) {
_root.difx = this._x- _root.object._x;
_root.object.targetx = this._x;
_root.dify = this._y- _root.object._y;
_root.object.targety = this._y;
_root.done = False
}

Step 15

Add a new layer and name it Action Script. Open the Action Script panel (F9) and enter the following script:

stop ();

And now you just need to check your results by pressing Ctrl + Enter or otherwise you can get the complete file here.

4 ★ | 1 Vote

May be interested

  • Macromedia Flash - Dynamic cursor objectPhoto of Macromedia Flash - Dynamic cursor object
    read this exercise and see how to create a dynamic cursor with just a few basic steps and of course use action script in flash 8.
  • Photoshop CS: Christmas cards for relativesPhoto of Photoshop CS: Christmas cards for relatives
    christmas season is near, you have prepared the gifts to give to relatives? each gift is a meaningful gift and do not forget to include a postcard and good wishes.
  • Photoshop CS: Creativity with new year cardsPhoto of Photoshop CS: Creativity with new year cards
    if you are a marksman in photoshop, it is not difficult to design yourself a postcard to celebrate your new year and send it to your relatives. what about those who don't know or don't know much about photoshop? will be a problem here. new year, who
  • Macromedia Flash - Move objectsPhoto of Macromedia Flash - Move objects
    with this exercise, you will learn how to move any object with the cursor in flash 8 using the action script.
  • Photoshop CS: Creativity with New Year's greeting card (Part II)Photo of Photoshop CS: Creativity with New Year's greeting card (Part II)
    a little reminder to you: this real lesson consists of many parts. working in each part is always related to each other. if the same operations are repeated in consecutive sections, i will just use the keyboard shortcut, or speak quickly through that section. therefore, to practice well
  • Photoshop CS: Creativity with New Year's greeting card (Part III)Photo of Photoshop CS: Creativity with New Year's greeting card (Part III)
    have you practiced good ground and ball design for this tet card? do you encounter any difficulties? don't be discouraged when you encounter any difficult steps. the result of labor when you create a postcard yourself is the greatest joy