# Getting multiple random objects to aim for the same target from library

**URL:** <https://forum.kirupa.com/t/getting-multiple-random-objects-to-aim-for-the-same-target-from-library/320797>\
**Category:** flash\
**Created:** [April 1, 2011, 5:37pm UTC](https://forum.kirupa.com/t/getting-multiple-random-objects-to-aim-for-the-same-target-from-library/320797 "2011-04-01T17:37:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![NickA2](https://avatars.discourse-cdn.com/v4/letter/n/9de053/32.png) [@NickA2](https://forum.kirupa.com/u/NickA2)\
**Post date:** [April 1, 2011, 5:37pm UTC](https://forum.kirupa.com/t/getting-multiple-random-objects-to-aim-for-the-same-target-from-library/320797/1 "2011-04-01T17:37:24Z")

</div>

With some excellent help from ilike2 I was able to import random objects from a library that can then be dragged to their respective targets (on repeat).

However, I forgot to mention that I need to drag more than one of these objects onto the same target and I don’t know how to change the actionscript to accommodate this.

Would anyone be able to help me with this?

In the example below I would also like Blue2 to target targetBlue\_mc

Here is the code:

```auto
var movieArray:Array = new Array(new Red(), new Green(), new Blue(), new Blue2());
var targetArray:Array = new Array(targetRed_mc, targetGreen_mc, targetBlue_mc );
var tempMc:MovieClip;
var r:int;

function init():void{
	r = Math.random() * movieArray.length;
	
	tempMc = movieArray[r];
	tempMc.x = 250;
	tempMc.y = 50;
	tempMc.buttonMode = true;
	tempMc.arrayIndex = r;
	tempMc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
	tempMc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
	addChild(tempMc);
	
}

function pickUp(e:MouseEvent):void {
    e.target.startDrag(true);
	
}

function dropIt(e:MouseEvent):void{
	e.target.stopDrag();

	if (e.target.hitTestObject(targetArray[e.target.arrayIndex])) {
		e.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickUp);
		e.target.removeEventListener(MouseEvent.MOUSE_UP, dropIt);
		e.target.buttonMode = false;
		e.target.x = targetArray[e.target.arrayIndex].x;
        e.target.y = targetArray[e.target.arrayIndex].y;
		
		setTimeout(startAgain, 500)
	}
}

function startAgain():void{
	removeChild(tempMc);
	init();
}

init();

```

Also attached is the test file
