Question

hi i'm new to AS3 and i was wondering what is the best way to remove a child at a point. i tried

Holder.removeChild(Holder.getObjectsUnderPoint(new Point(exampleX, exampleY))[0]);

however that returned ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.

any suggestions?

Was it helpful?

Solution

The getObjectsUnderPoint() method will return an Array of DisplayObjects that may not necessarily be direct children of your Holder object, they may be grand children or grand grand children etc...

You could set a conditional like this:

var objects:Array =  Holder.getObjectsUnderPoint( yourPoint );
for each( var child:DisplayObject in objects )
{
    if( child.parent == Holder )
       Holder.removeChild( child ) ;
}

Holder.contains doesn't filter anything since it will return the grandChildren as well... My mistake!

OTHER TIPS

I don´t know why Patricks version does not work. Here is an alternative (ugly code) solution using the parent of the clip.

var clips : Array =  _container.getObjectsUnderPoint(_point);

for each(var clip : DisplayObject in clips)
{
    clip.parent.removeChild(clip);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top