Mouse Trails

Count

OK let's get into the ActionScript now. We're going to start by initializing a variable called count, which we'll use later to keep track of all the movieClips you'll attach to the stage.

  1. Click Statements > Variables > var
  2. Type count = 0
  3. Select Number from the Type drop-down-list

We're working toward attaching new movieClips only when the user moves the mouse, so we will use the Flash's built-in onMouseMove function.

  1. Click Statements > User-Defined Functions > function
  2. Type onMouseMove in the Name box

The first thing we want Flash to do is increment the count variable by 1. That's easy if we use count=count+1, which may seem just a little confusing if you've done algebra, but haven't done much programming. But it makes perfect sense to say count will be whatever count was plus one:

  1. Click Statements > Variables > set variable
  2. We are re-setting the count variable
  3. The Value is count+1
  4. Make certain you select the Expression box

Let's make certain this is working. Back in the old days, I would drop a dynamic text box on the stage and set Var equal to count and test it out, but now that I'm a well-talented computer programmer, I use trace:

  1. Click Global Functions > Miscellaneous Functions > trace
  2. Type count in the Message box
  3. Select the Expression box

When you test the movie, you should see count increment in the Output window when you move the mouse:

If your project is NOT working, pay particular attention to the "expression" boxes in the instructions (especially if you are getting a string of NaN, which stands for "Not A Number"). If yours does work correctly, get rid of that trace code now.