-
[RESOLVED] removeChild problem
Actionscript Code:
function btnClicked(e:MouseEvent):void {
switch (e.target) { case Aplayer1 : setChildIndex(Aplayer1,numChildren - 1); TweenMax.to(Aplayer1, 0.5, {x:159, y:266, scaleX:1, scaleY:1, colorTransform:{tint:0x000000, tintAmount:0}}); this.addChild(infoA1); infoA1.x = 126; infoA1.y = 389; //here i want to remove the movieclip that loaded from others buttonclicked this.removeChild(infoA3); this.removeChild(infoA2); this.removeChild(infoA4); break;
case Aplayer2 : setChildIndex(Aplayer2,numChildren - 1); TweenMax.to(Aplayer2, 0.5, {x:253, y:268, scaleX:1, scaleY:1, colorTransform:{tint:0x000000, tintAmount:0}}); this.addChild(infoA2); infoA2.x = 126; infoA2.y = 389; break;
case Aplayer3 : setChildIndex(Aplayer3,numChildren - 1); TweenMax.to(Aplayer3, 0.5, {x:364, y:264, scaleX:1, scaleY:1, colorTransform:{tint:0x000000, tintAmount:0}}); this.addChild(infoA3); infoA3.x = 126; infoA3.y = 389; break;
case Aplayer4 : setChildIndex(Aplayer4,numChildren - 1); TweenMax.to(Aplayer4, 0.5, {x:506, y:274, scaleX:1, scaleY:1, colorTransform:{tint:0x000000, tintAmount:0}}); this.addChild(infoA4); infoA4.x = 126; infoA4.y = 389; break; } }
When i click Aplayer1 it will load infoA1 movieclip to the stage, click on Aplayer2 will load infoA2...but it will overlapping infoA1,infoA2...
i try to remove the child with the script above it will show up error 2025.
how to resolve this problem?
-
Always post the error message. No one has memorized that 2025 means "supplied object must be a child of the caller" (I just googled it).
Anyway, the error message tells you exactly what's wrong. You can't remove an object that isn't a child of the thing you are telling to remove it. You can use the contains function to see whether the child is there to be removed before removing it.
-
Sorry that I've forget the error message...
and i'm a newbie from AS3...totally...
what do you mean by container?
-
I didn't write 'container'. I wrote 'contains'.
contains is a method of DisplayObjectContainer, which tells you if a given DisplayObject is a child of that DisplayObjectContainer.
Code:
//here i want to remove the movieclip that loaded from others buttonclicked
if (contains(infoA3)){
removeChild(infoA3);
}
if (contains(infoA2)){
removeChild(infoA2);
}
if (contains(infoA4)){
removeChild(infoA4);
}
But that's a lot of repeating. We could define a function:
Code:
function safeRemove(c:DisplayObject):void{
if (contains(c)){
removeChild(c);
}
}
and then use it like:
Code:
safeRemove(infoA3);
safeRemove(infoA2);
safeRemove(infoA4);
-
Thanks the script is works!
I'm totally noob in AS3. and i juz mention your name! you have solve many kinds on AS3 problems here and some of it is removeChild problems!
I've figure it out for 2 days...finally!
Thanks alot again!
may i ask what book should read to learn AS3?
-
I've never read any of the as3 instructional books. There's a sticky-thread at the top of this forum for book recommendations.
http://board.flashkit.com/board/showthread.php?t=752155
-
cool! anyway thanks again!
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
|