[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1890
  • Last Modified:

removeChild throwing error

Error is being produced on the line containing 'mc_web.removeChild(loader);' in the portion shown below.

else
            {
                  mc_web.removeChild(loader);
                  i++;
                  
                  loader.load(movURL);
                  //trace(src[i]);
                  mc_web.addChild(loader);
            }
Strangely enough, the same removeChild works in the 'if section right above the 'else'.

I have tried
this.removeChild(loader);
this.parent.removeChild(loader);
this.parent.mc_web.removeChild(loader);

but the same error persists.

Thanks.
mc_web.mc_T_okr.alpha = 0.3;
mc_web.mc_R_okr.alpha = 0.3;
mc_web.mc_B_okr.alpha = 0.3;
mc_web.mc_L_okr.alpha = 0.3;
 
var i:Number = 0;
var src:Array = new Array("pic1.swf","pic2.swf","pic3.swf");
var movURL:URLRequest = new URLRequest(src[i]);
var loader:Loader = new Loader();
 
var timer:Timer = new Timer(10000,1);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, gameover);
 
function gameover(event:TimerEvent):void
{
	mc_statusText.text = "Game Over";
	mc_start.alpha = 1;
	mc_start.addEventListener(MouseEvent.CLICK, startgame);
	}
 
	
mc_start.addEventListener(MouseEvent.CLICK, startgame);
function startgame(event:MouseEvent):void
{
	timer.start();
	mc_start.alpha = 0.1;
	mc_start.removeEventListener(MouseEvent.CLICK, startgame);
	
	loader.load(movURL);
	loader.x = -157;
	loader.y = -130;
	mc_web.addChild(loader);
	
	}
 
//zoom functionality
function scaleup(event:MouseEvent):void
{
	mc_web.scaleX += .05;
	mc_web.scaleY += .05;
	mc_statusText.text = "";
	}
	
function scaledn(event:MouseEvent):void
{
	mc_web.scaleX -= .05;
	mc_web.scaleY -= .05;
	mc_statusText.text = "";
	}
	
mc_in.addEventListener(MouseEvent.CLICK, scaleup);
mc_out.addEventListener(MouseEvent.CLICK, scaledn);
 
 
//pan functionality
 
function panUp(event:MouseEvent):void
{
	
	mc_web.y -= 5;
	mc_statusText.text = "";
	}
	
function panDn(event:MouseEvent):void
{
	
	mc_web.y += 5;
	mc_statusText.text = "";
	}
	
function panLt(event:MouseEvent):void
{
	mc_web.x -= 5;
	mc_statusText.text = "";
	}
	
function panRt(event:MouseEvent):void
{
	mc_web.x += 5;
	mc_statusText.text = "";
	}
	
mc_up.addEventListener(MouseEvent.CLICK, panUp);
mc_dn.addEventListener(MouseEvent.CLICK, panDn);
mc_lt.addEventListener(MouseEvent.CLICK, panLt);
mc_rt.addEventListener(MouseEvent.CLICK, panRt);
 
 
//check if the photo is framed correctly
 
var yahooSound:yahoo_sound = new yahoo_sound()
mc_click.addEventListener(MouseEvent.CLICK, checkFraming);
 
function checkFraming(event:MouseEvent):void
{
	if(mc_web.mc_L_okr.hitTestObject(mc_Lframe) && mc_web.mc_T_okr.hitTestObject(mc_Tframe) && mc_web.mc_R_okr.hitTestObject(mc_Rframe) && mc_web.mc_B_okr.hitTestObject(mc_Bframe))
	{
		yahooSound.play();
		mc_statusText.text = "You got it!";
		
				
		if(i==src.length-1)
		{	mc_web.removeChild(loader);
			mc_click.removeEventListener(MouseEvent.CLICK, checkFraming);
			mc_click.alpha = 0.1;
			timer.stop();
			mc_statusText.text = "You Won!";
		}
		else 
		{
			mc_web.removeChild(loader);
			i++;
			
			loader.load(movURL);
			//trace(src[i]);
			mc_web.addChild(loader);
		}
			
	
	}
	else
	mc_statusText.text = "Please try again!";
}

Open in new window

0
cavedwell
Asked:
cavedwell
  • 3
  • 3
1 Solution
 
Aneesh ChopraCommented:
use "loade.content", not just "loader"


mc_web.removeChild(loader.content);
0
 
cavedwellAuthor Commented:
Thanks but this threw another error-
TypeError: Error #2007: Parameter child must be non-null.
      at flash.display::DisplayObjectContainer/removeChild()
      at vfc_fla::MainTimeline/checkFraming()[vfc_fla.MainTimeline::frame1:200]
0
 
Aneesh ChopraCommented:
try error handling in case loader.content content is null


try{
mc_web.removeChild(loader.content);
}
catch(e)
{

}
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
cavedwellAuthor Commented:
Just type in 'catch(e);' below the block statement containing 'mc_web.removeChild(loader.content);'? That did not work...'catch' was not recognized. I am sure I did not understand what you're asking me to do. Can you please explain a bit? Thanks a lot! Appreciate your patience.

Apart from this, it beats me that in the 'if' part of the if..else statement mc_web.removeChild(loader) removes the clip just fine but not in the else part. Do you know why?
0
 
Aneesh ChopraCommented:
'catch' statement must be used after try can't be used alone..

I suggest to replace following code:
//-------------------------
mc_web.removeChild(loader.content);
//-------------------------


replace it with following exact code:

//-------------------------
try{
mc_web.removeChild(loader.content);
}
catch(e)
{

}
//-------------------------


if it still does not work for you, I suggest to attach your sample FLA for quick solution


0
 
cavedwellAuthor Commented:
Thank you for your quick responses! I needed to move on quickly and did not have time for extensive error diagnosis so I changed my logic a bit to circumvent the problem. But thanks anyway.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now