Click anywhere on the stage below and watch it happen.

Grab the source for this one here. (Zipped, PC Flash 5 file).

In the example above, our obedient little clip moves where-ever we tell it. And it's smart too, if we tell it to move somewhere else while it's still moving, it does just that, but it doesn't get confused with how many steps it's taken already. Clever little circle! Let's take a look at the code.

This one is handled by the same mechanism as the random mover. The differences here include:

  1. Our target isn't random any more; it's supplied by the user.
  2. Once it gets to where it's going, it stops until the user tells it to go somewhere else.

So, instead of having a random() function generate our target _x and _y, we read them in when the user clicks somewhere. I've done this with an invisible draggable button with the following code:

on (release) {
        _root.target_x = _root._xmouse;
        _root.target_y = _root._ymouse;
        _root.xdiv = (_root.target_x-_root.circle._x)/20;
        _root.ydiv = (_root.target_y-_root.circle._y)/20;
        if (_root.running == true) {
                _root.controller.loops = 0;
        }
        _root.controller.gotoAndPlay(2);
}

Notice that this button takes the place of our Frame 1 in the random mover example. Let's examine the code.

What it does and how (line by line):

  1. Standard button 'on' command.
  2. Variable target_x equals the _x of the mouse when clicked.
  3. As above for _y.
  4. Variable xdiv equals the difference between the current position and the target, divided by 20, just like in our previous example.
  5. As above for ydiv.
  6. If variable running is True (we'll talk about this variable later);
  7. Variable loops equals zero. So now we must take 20 more steps... Like I say, we'll talk about this later.
  8. Tell 'controller' to go to and play frame 2.

This last line, begins our controller clip looping. The controller clip in this example is very much like that of the previous example; it goes ahead and increments the _x and _y until we've taken the right number of steps. However, we have to include some extra code for this scenario: What if the user clicks one place, and before our movie clip gets there, clicks another? Well our obedient little clip wants to go to the latest place, but it's already taken maybe 5 steps and it's been told to only take 20 steps. So it has 15 steps left, but each step is 1/20th the distance to the target. The result? It wont reach the second target. This is where the extra code comes in.

The variable running is true while our controller clip is looping. Once the looping is finished, it's set back to false. So if someone clicks this invisible button while the controller is looping (while the circle is moving), we must set the number of moves available back to 20 so as not to confuse our little circle. This is the reason for the code on the button which states:

if (_root.running == true) {
        _root.controller.loops = 0;
}
So now we can get back to the fatController. His structure has changed slightly from our Random example. We'll examine that over the page.