Skip to main content
mega_hunter_x
Participant
July 2, 2014
Answered

action script 3, problem with swapChildren and setChildIndex

  • July 2, 2014
  • 2 replies
  • 269 views

hello there everyone!!! i am making a fighting game in action script 3, and i am having a problem with swapChildren and setChildIndex. the case is that the last fighter that attacked gets in front of the other so i use swapChildren(fighter_1,fighter_2).

While the fight is going on it works alright, but when the fight ends and i change the scene the two fighters that swaped depths during the fight still appear on the stage!! its like they have been duplicated!! does anyone have a solution ? thanks in advance!!!

This topic has been closed for replies.
Correct answer kglad

to remove a displayobject and possibly null it, call removeF:

function removeF(dobj:DisplayObject,nullBool:Boolean):void{

if(dobj.stage){

dobj.parent.removeChild(dobj);

}

if(nullBool&&dobj){

dobj=null;

}

}

2 replies

mega_hunter_x
Participant
July 3, 2014

THANKS MAN!!! that is right, i just had to remove the fighters before changing the scene!! THANKS A LOT !!

kglad
Community Expert
Community Expert
July 3, 2014

you're welcome.

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
July 2, 2014

to remove a displayobject and possibly null it, call removeF:

function removeF(dobj:DisplayObject,nullBool:Boolean):void{

if(dobj.stage){

dobj.parent.removeChild(dobj);

}

if(nullBool&&dobj){

dobj=null;

}

}