开发者

Actionscript 3 remove child at point

开发者 https://www.devze.com 2023-01-30 05:15 出处:网络
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]);

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]);
开发者_如何学C

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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号