Tutorial details:
Written by: Jesse Stratford
Time: 30 - 45 minutes
Difficulty Level: Intermediate
Requirements: Flash 4, 5 or higher.
Topics Covered: How to control objects completely via actionscript or via a mix of user interaction and actionscript.
Assumed knowledge: Instances, paths, drag 'n drop, getProperty(), setProperty(), looping MCs, random().

Download the source for the above movie here. (Zipped, PC Flash 5 file).

Believe it or not I get enough questions about making smooth actionscript based tweens to dynamic X and Y positions, and/or random tweens to dynamic X and Y positions, that I've decided to write a tutorial. This tutorial will cover how to make an object move smoothly to a specified place on the stage using Actionscript. This place can be specified by the user clicking, or entering numbers, or can be generated randomly. Let's take a look shall we?

The primary application of this kind of stuff is in games and navigations. Then again I say that about most Actionscript. I've only ever used it in games but I'm sure it can be used in navigations also, somehow :o) Above I've an example of how we can make an object move smoothly and randomly, and later I will show you how we can make it move smoothly to a user-specified position. The best part about these two examples is that they both use the same code (almost) and it's very straight forward.

OK, say you have an object on the stage and you want to move it around randomly. Those of you who are a bit more experienced or creative may also realize that this will require generating random X and Y positions (_x and _y). What most people fall down on is how on Earth to make the animation smooth. We don't want our object to just jump from one _x, _y tuple (a tuple is a group of terms or variables) to another, we want it to animate there. This is deceptively simple also, once you see it done. This tutorial will outline a few methods of achieving the smooth movement effect.