Skip to main content
Known Participant
March 29, 2011
Question

Help in clearing a drag and drop object

  • March 29, 2011
  • 2 replies
  • 2186 views

Hello i am new to flash, well not new but havent used it in years. I am using this tutorial

http://www.flashclassroom.com/docs/documents/444_dragdroptargetsflashcs3.pdf

I got it working but the problem is, is when i go to the next frame the items that are matched succesfully stay there, I want to know how to clear them, so they don't get in the way of the next frames. Maybe it is something simple?

Hopefully someone can help soon, thanks a lot

This topic has been closed for replies.

2 replies

Known Participant
March 31, 2011

i think ill just commit suicide, thanks anyhow

kglad
Community Expert
Community Expert
March 31, 2011

you're welcome.

Known Participant
April 1, 2011

can anyone help? Must be easy for a really clever person!!

kglad
Community Expert
Community Expert
March 29, 2011

you can use removeChild() to remove objects from the displaylist, removeEventListener to remove their listeners (if they have any) and assign all their references to null to ready them for gc.

Known Participant
March 29, 2011

Hi thanks for the quick reply. Do you know where i put this information? ( I am rubbish at flash) I put it after the action code and then it said incorrect number or arguments. Thanks

March 29, 2011

try:

function dropObject(event:MouseEvent):void {

event.target.stopDrag();

var matchingTargetName:String = "target" + event.target.name;

var matchingTarget:DisplayObject = getChildByName(matchingTargetName);

if (event.target.dropTarget != null && event.target.dropTarget.parent == matchingTarget){

event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickupObject);

event.target.removeEventListener(MouseEvent.MOUSE_UP, dropObject);

event.target.parent.removeChild(event.target);

event.target.parent.removeChild(matchingTarget);

} else {

event.target.x = objectoriginalX;

event.target.y = objectoriginalY;

}

}