Hey all,
I would like to add some sort of event listener to an object upon its addition to the display list, such that clicking on the object removes it. How do I do that?
It would look something like this, although this doesn’t work…
var foo = new CustomObject();
addChild(foo);
foo.addEventListener(MouseEvent.CLICK, removeFoo);
function removeFoo(event:MouseEvent):void {
removeChild(event.target);
}
The part that wouldn’t work of course is “removeChild(event.target)”. I guess I could do something like this:
function removeFoo(event:MouseEvent):void {
if (foo) {
if (foo.parent != null) {
removeChild(foo);
}
}
{
…but I’m hoping for something a bit more modular than that.
Any help?
Thanks,