PDA

View Full Version : RemoveChild throwing error...tried and tried!



caveDweller
November 11th, 2008, 07:54 PM
Can't figure out what's up. Keep getting this error: ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at ViewFinder_mockup_fla::MainTimeline/checkFraming()














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!"
mc_web.removeChild(loader);

if(i==src.length-1)
{
mc_click.removeEventListener(MouseEvent.CLICK, checkFraming);
mc_click.alpha = 0.1;
}
else
{
i++;
loader.load(movURL);
//trace(src[i]);
mc_web.addChild(loader);
}


}
else
mc_statusText.text = "Please try again!"
}

Thanks!!
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!"
mc_web.removeChild(loader);

if(i==src.length-1)
{
mc_click.removeEventListener(MouseEvent.CLICK, checkFraming);
mc_click.alpha = 0.1;
}
else
{
i++;
loader.load(movURL);
//trace(src[I]);
mc_web.addChild(loader);
}


}
else
mc_statusText.text = "Please try again!"
}

sekasi
November 11th, 2008, 09:39 PM
read my sticky in this forum.

caveDweller
November 11th, 2008, 10:52 PM
Thanks for the tip Sekasi. I am reproducing part of the code which is giving error (the line as told by Flash debugger is in bold)

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!"
this.mc_web.removeChild(loader);

if(i==src.length-1)
{ mc_web.removeChild(loader);
mc_click.removeEventListener(MouseEvent.CLICK, checkFraming);
mc_click.alpha = 0.1;
}
else
{
i++;

loader.load(movURL);
//trace(src[i]);
mc_web.addChild(loader);
}


}
else
mc_statusText.text = "Please try again!" A

birdwing
November 12th, 2008, 12:28 AM
at one point in the code you are referring to mc_web as if its not inside another object.. on the line that returns the error you have this.mc_web which tells flash that mc_web is inside of "this" (what this is i can't figure out from your code)

this seems like a simple nesting error. try replaceing the bold line with: mc_web.removeChild(loader);

I'm not 100% sure if thats what the issue is but its the only thing i can see out of this.

caveDweller
November 12th, 2008, 08:40 AM
Yes, that was the very first try. I had thought that as I have added the clip I can remove it the same way. Of course, it didn't work :-( mc_web.removeChild(loader);
BTW, I find it so hard to edit anything I type on this forum - the cursor position is always invisible and if I want to add anythinginside a sentence , it adds to the end of everything. I'm using Firefox.

AjitpalS
November 19th, 2008, 07:43 AM
Display List in as3 is index, Suppose you have three movie clip(1_mc, 2_mc & 3_mc) in main scene, than removing movieclip. Before removing child, let index look like this:-
[1]=1_mc;
[2]=2_mc;
[3]=3_mc;
after calling {removeChild(1_mc);} will just change display list index as
[1]=2_mc;
[2]=3_mc;

to solve this you can try removeChildAt(movieclip,index); and put it in for loop like this:-
trace("Before children are :- "+ main_mc.numChildren); //3 answer
for (; main_mc.numChildren>0; ) {
main_mc.removeChildAt(0);
}
trace("After children are :- "+ main_mc.numChildren); //0 answer