dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: removeChild(); Problems

  1. #1
    Random(+123)
    Join Date
    Dec 2008
    Posts
    19

    removeChild(); Problems

    Hey, I'm having a bit of a problem.
    I keep getting a compiler message like this.

    Code:
    ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
    	at flash.display::DisplayObjectContainer/removeChild()
    	at MethodInfo-100()
    The swf runs fine with no other errors and works like it should just that this little error message is bugging me. Here is my code.
    It happened ever since I added the function "removeScope()" and ran it.

    I understand why I get it but I'm wondering if anyone can help me work around it.



    Code:
    function addScope():void {
    		addChild(scopeView);
    	}
    	addScope();
    
    	function removeScope():void {
    		removeChild(scopeView);
    	}
    
    	addChild(Bullet);
    	Bullet.x=50;
    	Bullet.y=50;
    
    	function activateBinoculars(e:KeyboardEvent):void {
    		if (Keyboard.SPACE) {
    			addChild(binocularView);
    			removeScope();
    			trace("Key is down");
    		}
    	}
    	function deactivateBinoculars(e:KeyboardEvent):void {
    		if (Keyboard.SPACE) {
    			removeChild(binocularView);
    			addScope();
    			trace("Key is up");
    		}
    	}
    There is some more code but I haven't put it in.

    Could the alternative be to just use the ".visible=false;"?

  2. #2
    lemon juice hurts your eyes florianvanthuyn's Avatar
    Join Date
    Jul 2005
    Location
    Merelbeke, Belgium
    Posts
    546
    I don't think your problem is located in the code you posted. Every child is added to and removed from "this" so normally this part should be working.

    You could try to put every removeChild() you use in a comment and re-add them one by one until you get the error.
    And if that works post the line that is causing the problem and the code you use it in
    Florian Vanthuyne

    WAR AGAINST SOLVED THREADS
    mark yours as Resolved under Thread Tools!

  3. #3
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    try tracing out , this.numChildren , before you remove scopeview. If you scopeview and binocularview are the only two children you have added to the display list then the number should be two. It might be a timing situation , where scopeview is not completely added to the stage yet. If thats the case , then you might consider delaying your removescope call. One way to do this is to add a listener to scopview , on added to stage.

  4. #4
    Random(+123)
    Join Date
    Dec 2008
    Posts
    19

    resolved

    Mk, I tried doing all the advice and decided the best thing was just to use the visible command as this was all I needed. Thanks a lot for the help guys though.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center