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

cavedwellAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.