# Simple Drag and Drop with Condition (multiple object and target)?

**URL:** <https://forum.kirupa.com/t/simple-drag-and-drop-with-condition-multiple-object-and-target/330111>\
**Category:** Uncategorized\
**Created:** [December 2, 2012, 10:25am UTC](https://forum.kirupa.com/t/simple-drag-and-drop-with-condition-multiple-object-and-target/330111 "2012-12-02T10:25:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![newinflash](https://avatars.discourse-cdn.com/v4/letter/n/439d5e/32.png) [@newinflash](https://forum.kirupa.com/u/newinflash)\
**Post date:** [December 2, 2012, 10:25am UTC](https://forum.kirupa.com/t/simple-drag-and-drop-with-condition-multiple-object-and-target/330111/1 "2012-12-02T10:25:42Z")

</div>

hi! :snug: i’m new in as3 and we’re on a research project, and currently i’m working on a drag and drop game. The concept is to drag the animals to their home. (e.g. the goat,carabao,dog must be dragged to the land) and I also need score, I don’t know where to put it.please help :emb: here’s my code which only support 1 object and without condtion and score ☹

[SIZE=2]var dragArray:Array = [turtle\_mc, goat\_mc, eagle\_mc, shark\_mc];[/SIZE]  
[SIZE=2]var matchArray:Array = [land\_match, air\_match, water\_match, landwater\_match];[/SIZE]  
[SIZE=2]var posArray:Array = [{x:0, y:0}, {x:518.30, y:0}, {x:1.30, y:268.65}, {x:519.55, y:270.10}];[/SIZE]  
[SIZE=2]  
[/SIZE]  
[SIZE=2]  
[/SIZE]  
[SIZE=2]var currentClip:MovieClip;[/SIZE]  
[SIZE=2]var startX:Number;[/SIZE]  
[SIZE=2]var startY:Number;[/SIZE]  
[SIZE=2]  
[/SIZE]  
[SIZE=2]for(var i:int = 0; i \< dragArray.length; i++) {[/SIZE]  
[SIZE=2] dragArray\*.buttonMode = true;[/SIZE]  
[SIZE=2] dragArray\*.addEventListener(MouseEvent.MOUSE\_DOWN, item\_onMouseDown);[/SIZE]  
[SIZE=2] //matchArray\*.alpha = 0.2;[/SIZE]  
[SIZE=2]}[/SIZE]  
[SIZE=2]  
[/SIZE]  
[SIZE=2]function item\_onMouseDown(event:MouseEvent):void {[/SIZE]  
[SIZE=2] currentClip = MovieClip(event.currentTarget);[/SIZE]  
[SIZE=2] startX = currentClip.x;[/SIZE]  
[SIZE=2] startY = currentClip.y;[/SIZE]  
[SIZE=2] addChild(currentClip); //bring to the front[/SIZE]  
[SIZE=2] currentClip.startDrag();[/SIZE]  
[SIZE=2] stage.addEventListener(MouseEvent.MOUSE\_UP, stage\_onMouseUp);[/SIZE]  
[SIZE=2]}[/SIZE]  
[SIZE=2]  
[/SIZE]  
[SIZE=2]function stage\_onMouseUp(event:MouseEvent):void {[/SIZE]  
[SIZE=2] stage.removeEventListener(MouseEvent.MOUSE\_UP, stage\_onMouseUp);[/SIZE]  
[SIZE=2] currentClip.stopDrag();[/SIZE]  
[SIZE=2] var index:int = dragArray.indexOf(currentClip);[/SIZE]  
[SIZE=2] var matchClip:MovieClip = MovieClip(matchArray[index]);[/SIZE]  
[SIZE=2] if(matchClip.hitTestPoint(currentClip.x, currentClip.y, true)) {[/SIZE]  
[SIZE=2] //a match was made! position the clip using the posArray values:[/SIZE]  
[SIZE=2] currentClip.x = posArray[index].x;[/SIZE]  
[SIZE=2] currentClip.y = posArray[index].y;[/SIZE]  
[SIZE=2] //make it not draggable anymore:[/SIZE]  
[SIZE=2] currentClip.removeEventListener(MouseEvent.MOUSE\_DOWN, item\_onMouseDown);[/SIZE]  
[SIZE=2] currentClip.buttonMode = false;[/SIZE]  
[SIZE=2] } else {[/SIZE]  
[SIZE=2] //match was not made, so send the clip back where it started:[/SIZE]  
[SIZE=2] currentClip.x = startX;[/SIZE]  
[SIZE=2] currentClip.y = startY;[/SIZE]  
[SIZE=2] }[/SIZE]  
[SIZE=2]}[/SIZE]
