PDA

View Full Version : droptarget


gzzle
02-18-2009, 09:40 AM
Hi guys,

I'm having a little problem of which I'm guessing the solution isn't that hard.. but I just can't put my finger on it...

The thing is:
I have got 5 movieclips which are able to drag and drop. Next to that I've got 20 containers which are all droptargets. The movieclips are able to be dragged and then dropped on a container. So far so good.....

But what I want is that when I drop a movieclip on a container which already has a movieclip dropped on it, the first movieclip gets removed and the second movieclip is dropped on the container. Or you could also say.. that the second movieclip replaces the first movieclip. This instead of the fact that a container has multiple movieclips dropped on itself.


for (var i:int = new int(0); i < containers.length; i++)
{
if (_currentSymbol.hitTestObject(containers[i]))
{
trace("snapped: " + i);
stage.removeChild(_currentSymbol);
containers[i].addChild(_currentSymbol);
_currentSymbol.x = 21;
_currentSymbol.y = 25;
$dropped = true;
break;
}
}


I hope someone can help me....

gzzle
02-18-2009, 11:45 AM
hmm.... maybe i was wrong by saying the solution could be quite simple.... ?

gzzle
02-18-2009, 01:18 PM
Ok... I think I'm getting a bit closer to the solution..

what i did is, get the numChildren and when this is more than it should be... I delete 1. Like this:


for (var i:int = new int(0); i < containers.length; i++)
{
if (_currentSymbol.hitTestObject(containers[i]))
{
trace(_currentSymbol);
trace(containers[i].numChildren);
trace("snapped: " + i);
if (containers[i].numChildren == 1);
{
containers[i].removeChildAt(0);
}
stage.removeChild(_currentSymbol);
containers[i].addChild(_currentSymbol);
_currentSymbol.x = 21;
_currentSymbol.y = 25;
$dropped = true;
break;
}
}


the thing is, that it not only removes the first movieclip (which is good) but the entire container as well!.. Anybody who knows how to fix it??

gzzle
02-18-2009, 02:18 PM
ok.. I solved it...

for those of you who are interested:


for (var i:int = new int(0); i < containers.length; i++)
{
if (_currentSymbol.hitTestObject(containers[i]))
{
trace(_currentSymbol);
trace("snapped: " + i);
stage.removeChild(_currentSymbol);
containers[i].addChild(_currentSymbol);
trace("numChildren: " + containers[i].numChildren);
_currentSymbol.x = 21;
_currentSymbol.y = 25;
if (containers[i].numChildren == 3)
{
containers[i].removeChildAt(1);
}
trace("numChildren2: " + containers[i].numChildren);
$dropped = true;
break;
}
}


:)