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]);

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

any suggestions?

Dain
  • 3
  • 2

2 Answers2

0

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!

PatrickS
  • 9,539
  • 2
  • 27
  • 31
  • ok tried it. it passes through the Holder.contains() but then it still throws the same error when it tries to remove it. strange huh – Dain Dec 14 '10 at 07:15
  • just realized i was missing a parenthese :( did you try the code as it were or did you modify it? – PatrickS Dec 14 '10 at 07:55
  • yeah i picked that up and added it. i decided to check the parent of the objects in the objects array and it gave me the type of object it was instead of the holder :S. anyhow i ended up using mattias ugly code solution – Dain Dec 14 '10 at 09:23
  • It's nice to be the ugly guy some times. It would be nice to know why Holder.contains( child ) works, but not Holder.removeChild( child ). – Mattias Dec 14 '10 at 09:53
  • i actually managed to get your solution to work except only with if(child.parent.parent == Holder) { holder.removeChild(child.parent);} i guess it was as you put it a grandchild :P... not sure how that happened. anyhow thanks for the help! – Dain Dec 14 '10 at 12:41
0

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);
}
Mattias
  • 3,907
  • 4
  • 28
  • 50