# \[AS3\] Closest movieclip

**URL:** https://forum.kirupa.com/t/as3-closest-movieclip/324673
**Category:** flash
**Created:** [September 2, 2011, 12:21pm UTC](https://forum.kirupa.com/t/as3-closest-movieclip/324673 "2011-09-02T12:21:50Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![mvrb](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@mvrb](https://forum.kirupa.com/u/mvrb)
#### Post date: [September 2, 2011, 12:21pm UTC](https://forum.kirupa.com/t/as3-closest-movieclip/324673/1 "2011-09-02T12:21:50Z")

</div>

Hello everyone. I’m trying to make a game where my movieclip will automaticly point at the closest enemy. I’ve tried push() the X and Y coordinates of my enemies to an array, but with no luck. This is my code so far:

[http://pastebin.com/Q6nRVQyZ](http://pastebin.com/Q6nRVQyZ)

I’ve added some comments, so you can see what’s going on.

If you have any questions or there’s anything else you don’t understand, please ask.

Also, this is my code for adding enemies:

```auto
var enemyContainer:MovieClip = new MovieClip();
addChild(enemyContainer);
for (var i:int = 0; i<5; i++){
	var enemy:MovieClip = new Enemy();
	enemyContainer.addChild(enemy);
	enemy.x = i*100;
	enemy.y = i*100;
}

```

Regards,  
Mathias
