Remember Thomas The Tank? Sure you do! And remember The Fat Controller who used to order him about, and talk without moving his lips and... sorry I'm getting off the point. Our Fat Controller clip is just like this, it's going to order our text field about. To be more precise it will order about the movie clip within which the text field (or graphic) lives. For the purpose of this example, because I want the field to continue scrolling without the user having to click over and over, I've made the commands in a looping MC which, when told to begin giving commands, will continually give commands until it's told to stop.

This is what we achieved in frames 2 and 3 of the fatController clip. Which have this code:

_level0.masker.contentText._y =
_level0.masker.contentText._y+(_level0:direction*5);

Note the above code has been put on two lines for tutorial neatness, in Flash it should all be on one line.

So this code first gets the current _y position (which is a numerical pixel value) of the movie clip containing our text field, then adds or subtracts 5 pixels, thus making the text field move up or down. We control whether pixels are added or removed using the variable I've named direction which is set to either 1 or -1. When set to -1 this means that the clip is moved up the screen, because -1 * 5 = -5. So we're adding a negative value, which is like subtracting. That's maths. Remember maths?

But fatController is lazy, so it's first frame is a stop action. If we don't tell it to do something it will sit around doing nothing. That's where our button auctions come in. Take the up button for example. It has the following code:

on (rollOver) {
 direction = -1;
 _level0.fatController.gotoAndPlay(2);
}
on (press, release, releaseOutside, rollOut, dragOut) {
 _level0.fatController.gotoAndStop(1);
}

So, on roll over, this button sets our direction variable to -1, so our text will move up the screen. Then it tells the fatController to get a move on! It plays fatController at Frame 2 which has our Y position incrimentation code, as discussed above. Frame 3 does the same and loops back to Frame 2. This loop continues and causes regular 5 pixels movements in the Y position of our clip. This gives the scrolling effect.
The second part of the button code tells the fatController to take a rest when the users moves the mouse off the up button. fatController then goes back to it's first frame, which has a stop instance, for a rest. Note that I've put a whole lot of events in the second on() tag. This is so our code wont stuff up if a user moves over the button, clicks and then moves out, or clicks and drags out, or some other weird, unpredictable scenario. This just makes our code function better in all environments, the only event you really need to include is rollOut.

Finally, the text field is dynamic so we can change the text easily. I've set the initial value in the first keyframe of the main stage, but you could just as easily use loadVariablesNUM() to load in a text file whose text you wish to show in the text field.

Not too hard hey? If you have questions post the on the forums please, rather than emailing me directly.

Jesse Stratford is the Co-Master of ActionScript.org and a freelance Flash developer and teacher. He is based in Australia and enjoys all things Flash.

NB: If you have comments or feedback please feel free to email me, but please do not email me Flash questions; the forums are provided for that purpose and you will get a faster answer by posting you question there.

If you have found this tutorial helpful, I hope that you will take 30 seconds to visit The Hunger Site where, with just one click you can make a free donation of food to a starving person in a third-world country. We do not benefit financially from this action; it is purely an act of charity.
This tutorial is protected by International Intellectual Property Rights laws and may not be reproduced or redistributed in full or part, without the prior written consent of the author. Unauthorized reproduction of this tutorial or its contents may result in prosecution. I've worked hard on this tutorial, please don't steal it.