dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Error #2025: The supplied DisplayObject must be a child of the caller.

  1. #1
    Member
    Join Date
    Jun 2005
    Posts
    37

    Error #2025: The supplied DisplayObject must be a child of the caller.

    I'm getting this error in the following script:

    Code:
    package com.main.classes
    {
    	import flash.display.MovieClip;
    	import flash.display.SimpleButton;
    	import flash.events.MouseEvent;
    	import flash.net.*;
    	import flash.display.Stage;
    	import flash.display.DisplayObject;
    	
    	public dynamic class DocumentClass extends MovieClip 
    	{
    		public var menuScreen:MenuScreen;
    		public var playScreen:ShootingGame;// Change name to file name of main game file
    		public var gameOverScreen:GameOverScreen;
    		public static var stage:Stage;
            public static var root:DisplayObject;
     
    		public function DocumentClass() 
    		{
    			DocumentClass.stage = this.stage;
                DocumentClass.root = this;
    			menuScreen = new MenuScreen();
    			menuScreen.addEventListener( NavigationEvent.START, onRequestStart );
    			menuScreen.x = 0;
    			menuScreen.y = 0;
    			addChild( menuScreen );
    		}
     
    		public function gameOver( gameEvent:GameEvent ):void
    		{
    			//var finalScore:Number = playScreen.getFinalScore();
    			var totalScore:Number = 0;
    			var movesScore:Number = 0;
    			var timeScore:Number = 0;
    			
    			gameOverScreen = new GameOverScreen();
    			gameOverScreen.addEventListener( NavigationEvent.RESTART, onRequestRestart );
    			gameOverScreen.x = 0;
    			gameOverScreen.y = 0;
    			//gameOverScreen.setFinalScore( finalScore );
    			//gameOverScreen.setBestScore(totalScore);
    			//gameOverScreen.totalScoreDisplay.text = totalScore.toString();
    			removeChild(playScreen);
    			addChild( gameOverScreen );
    			
    		}
     
    		public function onRequestRestart( navigationEvent:NavigationEvent ):void
    		{
    			restartGame();
    		}
    		
    		public function onRequestStart( navigationEvent:NavigationEvent ):void
    		{
    			playScreen = new ShootingGame();// Change to filename of main game file
    			playScreen.addEventListener( GameEvent.DEAD, gameOver );
    			playScreen.x = 0;
    			playScreen.y = 0;
    			removeChild( menuScreen);
    			addChild( playScreen );
    		}
    
    		public function restartGame():void
    		{
    			playScreen = new ShootingGame();// Change to filename of main game file
    			playScreen.addEventListener( GameEvent.DEAD, gameOver );
    			playScreen.x = 0;
    			playScreen.y = 0;
    			addChild( playScreen );
    			removeChild(gameOverScreen);
    		}
    	}
    }
    I've highlighted where the problem is occurring. Now, I think what I'm trying to do is remove an object from within another object. I think the object I'm trying to remove is actually on the root. What I haven't been able to work out is what code I need to use to fix this.

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Is this your Documentclass? If so then you should not get an error, since the reference is the main timeline. You can test once what you get when you do the trace(this); in your functions.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  3. #3
    Member
    Join Date
    Jun 2005
    Posts
    37
    Yes, it is my main DocumentClass. I have used the same code in other games without this problem.

    Using trace gives the result [object DocumentClass] when used in the DocumentClass, gameOver and onRequestStart functions.

  4. #4
    Member
    Join Date
    Jun 2005
    Posts
    37
    Ah, I think I've found what's causing the problem. In the ShootingGame.as file (playScreen) there are a number of objects added using DocumentClass.stage.addChild(object);

    Removing them before running the gameOver function seems to fix it.

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