Go Back   CodingForums.com > :: Client side development > Flash & ActionScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-05-2011, 04:09 AM   PM User | #1
hopelesscoder
New to the CF scene

 
Join Date: Aug 2011
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
hopelesscoder is an unknown quantity at this point
Drag and Drop Multiple Objects

Hi, I'm having problems with dragging and dropping of multiple objects that are spawned on the stage. I'm trying to make a game where players can drag the draggables between two boxes with slots that they are able to snap into.

This is the image of the stage.


The draggables that are spawned and slots on the stage are put in an array.
public var dropArray:Array = new Array(drop0,drop1,drop2,drop3,drop4);
public var snapArray:Array = new Array(snap0,snap1,snap2,snap3,snap4);

The codes for the snapping into place and the hittest object doesn't seem to work. It seems like the for loop is causing the problem.

private function snapBack(event:MouseEvent):void
{


for (var j:int=0; j<dropArray.length; j++)
{
var myTargetName:String=("drop"+j);
var myTargetisplayObject=getChildByName(myTargetName);
var target:MovieClip = event.currentTarget as MovieClip;
target.stopDrag();
//http://www.ilike2flash.com/2011/04/drag-and-drop-in-as3-part-3.html
var dragIndex:int = dragArray.indexOf(event.currentTarget);

if (item(event.currentTarget).hitTestObject(myTarget)) {


target.x=myTarget.x;
target.y=myTarget.y;
trace("drop");
trace(item(event.currentTarget).name);
}
else
{

target.x = positionsArray[dragIndex].xPos;
target.y = positionsArray[dragIndex].yPos;
trace("back");
}

}

}

I'm also having problems to not allow them to snap to the slot that already have a draggable in it.

Anyone care to help? Thanks in advance.
hopelesscoder is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:38 AM.


Advertisement
Log in to turn off these ads.