• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 623
  • Last Modified:

How do I use removechild in as3?

I get this error:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
0
10views
Asked:
10views
  • 3
1 Solution
 
biyikCommented:
You can remove smth. if it's on a display list. So you can control it on your code with if statement.
if
(this.yourMc.contains(MC)) 
{
        this.yourMc.removeChild(MC);
}

Open in new window

0
 
section25Commented:
You can use this to see the children of an object. If the child is not on the list then it is not a child of the parent. This will show you the children on the Root object (or Stage).

If you want to see the children of a specific object, change the "this" in this function to the name of the object yuo want to examine.

var s:DisplayObject;
for(a=1;a<=this.numChildren-1;a++){
   s = this.getChildAt(a);
   trace(s.name, getChildIndex(s));
}
0
 
section25Commented:
Make sure you define "a" as a variable before running the above code.
0
 
10viewsAuthor Commented:
I don't see my code snippet on the page, so I'll try sending another one.
The loadVid button loads the movie OK,
and the unloadVid unloads it.
If I click the unloadVid button again or click it before I click the loadVid button,
I get this error message:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at topJ_7_fla::MainTimeline/vidOut()


var myLoader:Loader = new Loader();
loadVid.addEventListener(MouseEvent.MOUSE_UP,buttonclick);
function buttonclick(event:MouseEvent)
{
var url:URLRequest = new URLRequest("swfs/video.swf");
myLoader.load(url);
addChild(myLoader);
}
 
unloadVid.addEventListener (MouseEvent.CLICK, vidOut);
function vidOut(event:MouseEvent)
{
myLoader.parent.removeChild(myLoader);
}

Open in new window

0
 
section25Commented:
If you have already unloaded the movie, then it is no longer on the display list and will give you an error if you try to unload it again. In that case you would need to do what biyik suggested above and check it first to make sure it is still on the display list before trying to remove it a second time.

function vidOut(event:MouseEvent)
{
  if(myLoader.parent.contains(myLoader){
     myLoader.parent.removeChild(myLoader);
  }
}
0

Featured Post

Industry Leaders: 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!

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