Actionscript 3 remove child at point
-
09-10-2019 - |
문제
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);
}
제휴하지 않습니다 StackOverflow