PDA

View Full Version : Having Problem removing mc from Array


SammyFM
05-29-2008, 12:11 PM
I have a prolem with the push method over here.

If drag was successful, mc should be pushed to turn_array - works!
If not, mc should be removed from turn_array.

The problem is, that i could not use pop or shit to do it, bīcause, also other
mc can be droped and be a part of turn_array.

Is there a way to do that, something like: delete turn_array[(event.curentTarget)]; ?

function dropIt(event:MouseEvent):void
{
event.currentTarget.stopDrag();

if (event.currentTarget.dropTarget != null && event.currentTarget.dropTarget.parent == target_1)
{
event.currentTarget.x = event.currentTarget.startX;
event.currentTarget.y = event.currentTarget.startY;
event.currentTarget.buttonMode=true

turn_array.push(event.currentTarget); // here i add to the array

} else
{
event.currentTarget.x = event.currentTarget.endX;
event.currentTarget.y = event.currentTarget.endY;

delete turn_array[(event.currentTarget)];// here delete from array
}
}

panel
05-29-2008, 12:18 PM
You have iterate thought array


for(var i:uint=0; i<turn_array.length; i++)
{
if(event.currentTarget == turn_array[i])
{
turn_array.splice(i,1)
break;
}
}

SammyFM
05-29-2008, 12:29 PM
Ah, ok. Thanx - works great!!!!!:);)

SammyFM
05-29-2008, 12:55 PM
And i found another problem with that array:

if you press on the draged mc, while sittin on the target and you just keep klicking, of course the mc will be
added and added as often as you click on it to the array.

can i say something like:

if target reached and added to array, stop adding to array if droped again?

...of course this must be undone if the target is deleted from the array

SammyFM
05-29-2008, 01:39 PM
Ok i got it:

if (event.currentTarget == turn_array[i])
{
trace("iīm already selected")
}
else
{
turn_array.push(event.currentTarget);
}