Like this? Click on anywhere to produce a moving circle, then press 1 to have an arrow point to the circle nearest to the mouse.
What I did is basically what Hoeloe just said. You need to push a pointer of the movie clip into an array. I did it like this:
var targetArray:Array = new Array();
var newMC:Movieclip = _root.attachMovie("myCircle", "Circle"+_root.getNextHighestDepth(), _root.getNextHighestDepth());
targetArray.push(newMC);
Then you just search through the list. I just used a linear search (search through the list) since it's the easiest form of searching, and I won't be having a list that's bigger than 10 so it's fine for my use. The search goes like this:
- Declare an integer variable named "shortestDist". Its default value is null (no need to initialize)
- Declare a Movieclip variable named "nearestMC" and initialize it
- Search through the array using something like a for loop. If the distance current iteration (movie clip) in the array is null, OR if it's lesser than shortestDist, assign the distance to shortestDist, then assign that movieclip to nearestMC.
At the end of the loop, nearestMC points to the nearest MC.