dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: RemoveChild giving error - what am I doing wrong?

  1. #1
    Senior Member
    Join Date
    Jan 2008
    Location
    UK
    Posts
    269

    RemoveChild giving error - what am I doing wrong?

    Clearly I'm going about this the wrong way. I can add a movie clip but can't remove it. My code is as follows:

    Code:
    var gui:MovieClip = new MovieClip;
    
    //main loop is here
    
    function make_gui():void{
    	
    	var tempgui:gamegui_mc = new gamegui_mc();
    	gui = tempgui;
    	stage.addChild(gui);
    }
    
    
    function clean_up():void{
    		
    	stage.removeChild(gui);
    }
    and the error I get is:
    The supplied DisplayObject must be a child of the caller.
    pointing to the line with removeChild on it. I don't know what it means by 'the caller'. 'gui' is a child of the stage, but I guess 'stage' is not the caller - so what is?!

    I have tried many variations to no avail - can someone please point out the error of my ways?

    Cheers!
    Last edited by _Ric_; 01-23-2008 at 05:23 PM.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Are you sure that gui has the same value in the remove line as it does in the add line? I do not think that "caller" means anything important here.

    Try this to see what it says. It'll still fail, but it'll be more informative.
    Code:
    function clean_up():void{
    	trace("gui on stage? "+stage.contains(gui));
    	stage.removeChild(gui);
    }

  3. #3
    Senior Member
    Join Date
    Jan 2008
    Location
    UK
    Posts
    269
    Thank you - that gave the result 'false', and that made me realise that I was calling the clean_up function repeatedly from my main loop after the object had already been removed. Stupid mistake! Added a flag to make sure it only gets called once, and all is well again.

    Cheers.

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