`

Tuesday, September 14, 2010

removeChild Problem in AS 3.0

People are getting insane with removeChild() in AS3. They addChild()
the object in the same level but they can’t remove it.


There are several ways to use removeChild() of course it depends what
you need.

First Method

myMovieClip.parent.removeChild(myMovieClip);

Second Method:

MovieClip(myMovieClip).parent.removeChild(myMovieClip);

Third Method:


function loadPic():void
{
var
myMovieClip:MovieClip = new MovieClip();
var my_Loader:Loader = new Loader();
addChild(my_Loader);
addChild(myMovieClip);
var my_url:URLRequest = new URLRequest("image.png");
my_Loader.
load(my_url);
}



function loadPic():void
{
my_Loader.parent.removeChild(my_Loader);
}



These are the common mistake when using removeChild() of AS3, there are other problems or factors that’s why removeChild is not working in your project.

It probably improper declaring the function or events or objects. Just check the codes, and to make sure it will work use First Method or Second Method as my advise.

No comments: