AS3 Random Movement


Hi there!

So I have been making use of an AS3 deconstruction for random movement from the old forums (see for reference)

This has been a fantastic help to me. I have now added different coloured circles and they’re bouncing away happily. However, currently I have made a new page for each circle to link to its own personal random movement .as file. There must be a way to instead link the various objects to the random movement algorithm?

For reference, I have (in my

	private function PopulateCircles():void
		for (var i:int=0; i < 10; i++)
			var blueCircle:BlueCircle = new BlueCircle();

			var redCircle:RedCircle = new RedCircle();


and then I have a and a RedCircle.AS. The only difference in each .as is the namechange of class and function, starting like this;

public class RedCircle extends MovieClip
	private var newX:Number = 0;
	private var newY:Number = 0;

	private var speed:Number;

	private var speedX:Number;
	private var speedY:Number;

	private var totalDistance:Number;
	private var previousDistance:Number = 0;
	private var currentDistance:Number = 0;

	public function RedCircle()
		this.addEventListener(Event.ADDED_TO_STAGE, Setup);

tl;dr: Is there a way to not have to create (almost) the same .as for every different coloured circle I want to move randomly?