A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: removeChild Problems

  1. #1
    Member
    Join Date
    Jan 2010
    Posts
    40

    removeChild Problems

    Hi, I'm working on a game that needs certain pages to be loaded depending on a random generated number.

    Here's what I've done to make each room load up
    Actionscript Code:
    function onEssenButtonClick(event:MouseEvent):void
        {
            if (1 == theNumber){
            addChild(essenPage1);
            removeChild(mapPage);
            }
            if (2 == theNumber){
            addChild(essenPage2);
            removeChild(mapPage);
            }
        }
    function onLibButtonClick(event:MouseEvent):void
        {
            if (1 == theNumber){
            addChild(libPage1);
            removeChild(mapPage);
            }
            if (2 == theNumber){
            addChild(libPage2);
            removeChild(mapPage);
            }
        }

    Each of these rooms have the 'mapButton' on it and here's what I'm using to back out of the room.
    Actionscript Code:
    function onMapButtonClick(event:MouseEvent):void
        {
        addChild(mapPage);
        removeChild(this);
        }

    I'm getting this error:
    Code:
    ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
    	at flash.display::DisplayObjectContainer/removeChild()
    	at Main/onMapButtonClick()
    I know I'm meant to put the relevant page inside removeChild"(this)" but the 'mapButton' applies to all pages and there is in total, 36 of them.

    Please help.

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    maybe...
    Code:
    var thePage:MovieClip;
    function onEssenButtonClick(event:MouseEvent):void {
    	if (1==theNumber) {
    		thePage=essenPage1;
    		addChild(essenPage1);
    		removeChild(mapPage);
    	}
    	if (2==theNumber) {
    		thePage=essenPage22;
    		addChild(essenPage2);
    		removeChild(mapPage);
    	}
    }
    function onLibButtonClick(event:MouseEvent):void {
    	if (1==theNumber) {
    		thePage=libPage1;
    		addChild(libPage1);
    		removeChild(mapPage);
    	}
    	if (2==theNumber) {
    		thePage=libPage2;
    		addChild(libPage2);
    		removeChild(mapPage);
    	}
    }
    function onMapButtonClick(event:MouseEvent):void {
    	addChild(mapPage);
    	removeChild(thePage);
    }

  3. #3
    Member
    Join Date
    Jan 2010
    Posts
    40
    It works! Thank you so much

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