문제

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?

도움이 되었습니까?

해결책

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!

다른 팁

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);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top