PDA

View Full Version : Removing Dynamic SWF Question



coloradocelt
January 13th, 2009, 06:10 PM
Hey all,

I am placing an external swf files with the following code:


var removeSpaces0:RegExp = / /g;
var noSpaces0:String = String(itemZero);
var structureName0:String = (noSpaces0.replace(removeSpaces0, ""));
var anatomyPicture0:Loader = new Loader();
stage.addChild(anatomyPicture0);
anatomyPicture0.contentLoaderInfo.addEventListener ( Event.INIT, handleInit0 );
anatomyPicture0.load( new URLRequest( "swfFiles/" + structureName0 + ".swf" ) );

function handleInit0(evt:Event):void {
var extMovie0:* = anatomyPicture0.content;
removeArray.push(extMovie0);
extMovie0.x = (stage.stageWidth - anatomyPicture0.width)/2;
extMovie0.y = (stage.stageHeight - anatomyPicture0.height)/2;
}

I am trying to remove it (and a couple of others clips) with the following code:


function theRemover(evt:MouseEvent):void {
for (var z:Number = 0; z <= 1; z++) {
var totalChildren:Number = this.numChildren - 1;
removeChildAt(totalChildren);
removeChild(removeArray.pop());
}
}

I am getting this error:

"ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at symptomToProtocolAnatomy_fla::MainTimeline/theRemover()"

Any help is greatly appreciated.

ayumilove
January 13th, 2009, 07:37 PM
I guess it means like this.
Suppose ABC [a person] who wants to send his children to school.
But the children that he is sending is not his child [someone's else]

In order to send, those children must be his children.

So to translate it, you are trying to remove something that is not under the caller.

coloradocelt
January 14th, 2009, 11:52 AM
Who would be the parent in this case?

coloradocelt
January 14th, 2009, 01:15 PM
Figured this one out! Whew.

I was not aware that you removed the swf Loader instead. So here is what I ended up doing:


if (whichButton == "anatButton0") {
var removeSpaces0:RegExp = / /g;
var noSpaces0:String = String(itemZero);
var structureName0:String = (noSpaces0.replace(removeSpaces0, ""));
var anatomyPicture0:Loader = new Loader();
anatomyPicture0.contentLoaderInfo.addEventListener ( Event.INIT, handleInit0 );
anatomyPicture0.load( new URLRequest( "swfFiles/" + structureName0 + ".swf" ) );
anatomyPicture0.name = "swf0";
removeArray.push("swf0");
addChild(anatomyPicture0);

function handleInit0(evt:Event):void {
var extMovie0:* = anatomyPicture0.content;
extMovie0.x = (stage.stageWidth - anatomyPicture0.width)/2;
extMovie0.y = (stage.stageHeight - anatomyPicture0.height)/2;
}

}

and then to remove:


function theRemover(evt:MouseEvent):void {
removeChild(getChildByName(removeArray.pop()));
for (var z:Number = 0; z <= 1; z++) {
var totalChildren:Number = this.numChildren - 1;
removeChildAt(totalChildren);
}
}

Is there a more elegant way to accomplish this?