|
-
[RESOLVED] Drag and drop question
I've created drag and drop widgets that have a separate target for each object draged, and in those cases, I've directed the dragged object to position over the target.
Now I need to have one common target, and send each dragged object to a different location.
I have a hidden object that I want each dragged piece to rest over after a successful hitTest. I set the _targetPiece.x and _targetPiece.y for each drag object in the function that loads them to the stage. All this makes sense when the target piece and the hidden target object are the same, but since the target and the destination are different, I'm confused over how to change this to work.
I though that if I changed _targetPiece (bold red) in the hitTest to "hitTarget", the instance name of the common target, that would work, but the object just rests where the dragging stops. Can someone suggest how I can change the following code to fit?
Code:
private function checkTarget(event:MouseEvent):void
//The listener tells flash to go here for instructions when the object is released after a drag
{
if(event.currentTarget.hitTestObject(event.currentTarget._targetPiece))
{
//tells the piece to position itself exactly over the target if the drage touches the target piece
event.currentTarget.x = event.currentTarget._targetPiece.x;
event.currentTarget.y = event.currentTarget._targetPiece.y;
trace(event.currentTarget._targetPiece.X);
trace(event.currentTarget._targetPiece.y);
//since each drag object has its own listener, we want to remove these when done
//(otherwise they might move them to the wrong position)
event.currentTarget.removeEventListener(MouseEvent.MOUSE_UP, checkTarget);
event.currentTarget.disable();
//if all pieces are in place, the game is over._
_currentPieces ++;
if(_currentPieces >= _totalPieces)
{
celebrateSuccess();
}
}
else
{
//else put the piece back to its starting point
event.currentTarget.x = event.currentTarget._origX;
event.currentTarget.y = event.currentTarget._origY;
}
}
-
[resolved]
I created a variable: private var _hit:*;
I gave each object this statement: object._hit=hitgoal_mc (this is the instance name of the target). I then replaced _targetPiece in the if statement with _hit. That worked. Might not be the best solution, but it's good enough to get me away.
Hope this helps someone else.
Thomas
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|