# AS3 Random Movement

**URL:** <https://forum.kirupa.com/t/as3-random-movement/638437>\
**Category:** flash\
**Created:** [July 2, 2018, 4:57pm UTC](https://forum.kirupa.com/t/as3-random-movement/638437 "2018-07-02T16:57:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sn0wy0wl](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sn0wy0wl/32/9181_2.png) [@sn0wy0wl](https://forum.kirupa.com/u/sn0wy0wl)\
**Post date:** [July 2, 2018, 4:57pm UTC](https://forum.kirupa.com/t/as3-random-movement/638437/1 "2018-07-02T16:57:21Z")

</div>

Hi there!

So I have been making use of an AS3 deconstruction for random movement from the old forums (see [https://www.kirupa.com/flash/random\_movement\_as3\_pg1.htm](https://www.kirupa.com/flash/random_movement_as3_pg1.htm) 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 Main.as)

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

			this.addChild(blueCircle);
			
			var redCircle:RedCircle = new RedCircle();

			this.addChild(redCircle);
		}
	}

```

and then I have a BlueCircle.as 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?
