Question

I got a media clip called point with multiple child graphics. When my char hit a child i want to get the name or the child number of that graphic

if (point.hitTestPoint(char.x + 20,char.y + 30,true)){
    //name of child hit
}

Is this possible?

Was it helpful?

Solution

You can brute this by hit testing the children in the container. Something like...

if (point.hitTestPoint(char.x + 20,char.y + 30)) {
  for(var n:int = 0; n < point.numChildren; n++) {
    if(point.getChildAt(n).hitTestPoint(char.x + 20,char.y + 30,true)) {
      // Do something. Store name, whatever
      break;
    }
  }
}

This isn't the most optimal method, but is simple and matches how you are currently doing it. If you are doing this for a game at high speed, then you would want to look into some kind of spatial partitioning to optimise your test.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top