0
votes

I basically need for a child to add another child to the parent. I know about localConnection, or whatever it is called, and that's too messy for me to use. Is there any way for me to do this?

This is the main code var c:childboy = new childboy(); //in the constructor of the class it is suposed to add a child

And this is the code of childboy package { import flash.display.Loader;

public class childboy
{
    var ass:Loader = new Loader();

    public function childboy()
    {
        parent.addChild(ass);
    }

}

}

1
Children should not manipulate their parents like this. It violates good OOP. What is your end goal? - Amy Blankenship

1 Answers

1
votes

The parent property only exist when you make the addChild(obj) first.

So create a function like this in your class and remove the content of the constructor.

public function start():void {
    parent.addChild(ass);
}

and outside of your class you have to do this.

var o:childboy = new childboy();
addChild(o);
o.start();