Mouse Follower in Flash

First thing to do is to setup the stage and layers. After we have this done, we'll move on to creating the Movie Clip (MC).

For the tutorial we'll make the Stage 400 x 300, with a fps (frames per second) of 12, which is standard. Background color can stay white.

Now for the Layers.

Default, you start with 1 layer, which is named Layer 1.

image 1

Lets make 1 New Layer. To do this press the New Layer Button. So now we have

Layer 2
Layer 1

Rename Layer 2 to "Actions". And Layer 1 to "Ball"

image 2

Next, we create the MC called Ball

Select the "Ball" layer and Create a small Circle or some other type of shape.

image 3

The Select the what you created and go to INSERT > Convert to Symbol

And rename it to "ball" and make sure the Movie Clip is Selected. Then Click on OK.

image 4

With the ball MC selected, change the Instance Name to ball.

image 5

While the ball MC is still selected lets add the actionscript to it. Right Click on the ball and select Actions.

In the Top Right corner of the Actions window click on the View Options and Select "Expert Mode". Then Copy and paste the code to the right into the Actions Box.

onClipEvent (enterFrame) {
      // Sets Property of 'ball' to where the mouse is
      setProperty(this, _x, _root.mousex);
      setProperty(this, _y, _root.mousey);
}

Now, Select the first Frame for the Actions layer, Then right click on the frame and choose Actions. Then Copy and Paste the Code to the right into the Actions box.

// Gets the current mouse pointer x and y values
// Then places them in stored varible called: mousex or mousey
_root.mousex  = getProperty(_root,_xmouse);
_root.mousey  = getProperty(_root,_ymouse);

So, next thing is to add a 2nd frame for both of the Layers. To do this Select Frame 2 on both layers, then right click and select Insert Frame. After that make sure only Frame 2 of Actions is selected and right click on frame 2 and select Insert Keyframe.

image 6

With Frame 2 of Actions selected place a gotoAndPlay(1); action. So that once it reaches frame 2 it replays.

image 7

To the right is what your finished timeline should look like.

Press ENTER+CTRL to test the movie.

image 8

Side Note: You can also achive this effect with using the drag function found under Actions > Movie Clip Control > startDrag.

With this effect you can create a few different effects and styles of Followers. With just by adding an MC that has animation you can create great effects. Thank again for doing this tutorial, If you have any questions please let me know.


Close    To Top
  • Prev Article-Flash:
  • Next Article-Flash:
  • Now: Tutorial for Web and Software Design > Flash > Basic > Flash Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction