Mouse Trails

Multiple Attachments

Let's get those clips on the stage and use the count variable to give each clip a unique name and depth level:

  1. Click ActionScript 2.0 Classes > Movie > MovieClip > Methods > attachMovieClip
  2. We'll drop these right on the Stage, so the Object is _root
  3. Type in the Linkage Name you setup earlier: trail (and make certain Expression is deselected)
  4. The New Name is "trail"+count (make sure Expression is selected)
  5. The Depth is count

Do you understand what's happening in the function thus far? Let's imagine it's the first time through and count = 0. The mouse moves and count = 0+1, which of course = 1. Now we attach the trail movieClip from the Library. We put quotes around "trail" because we really do mean "trail", and we don't want Flash to evaluate some variable called trail. We give this new movieClip the instance name "trail"+count and this time we do want Flash to evaluate the script and return trail1. Finally, we set the depth equal to count, so trail1 is on level 1.

The next time we move the mouse count=1+1, which is 2. Now we attach the trail movieClip from the Library. We put quotes around "trail" because we really do mean "trail", and we don't want Flash to evaluate some variable called trail. We give this new movieClip the instance name "trail"+count and this time we do want Flash to evaluate the script and return trail2. Finally, we set the depth equal to count, so trail2 is on level 2, and will not replace the clip on Level 1.

The next time we move the mouse count=2+1, which is 3. Now we attach the trail movieClip from the Library. We put quotes around "trail" because we really do mean "trail", and we don't want Flash to evaluate some variable called trail. We give this new movieClip the instance name "trail"+count and this time we do want Flash to evaluate the script and return trail3. Finally, we set the depth equal to count, so trail3 is on level 3, and will not replace the clips on Level 1 or 2.

Now let's setup an easy way to reference each of those movieClips using a variable:

  1. Click Statements > Variables > var
  2. In the Variable box type newClip = _root["trail"+count]
  3. Select the MovieClip data type

Now set the x and y position of newClip equal to _xmouse and _ymouse using set variable:

Test:

Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player