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.
- Click Statements > Variables > var
- Type count = 0
- 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.
- Click Statements > User-Defined Functions > function
- 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:
- Click Statements > Variables > set variable
- We are re-setting the count variable
- The Value is count+1
- 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:
- Click Global Functions > Miscellaneous Functions > trace
- Type count in the Message box
- 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.