DisplayObjectContainer.getObjectsUnderPoint()
getObjectsUnderPoint
ここで証明されているように、DisplayObjectContainers を返さないことに注意してください。
var mc:MovieClip = new MovieClip();
var shape:Shape = new Shape();
shape.graphics.beginFill(0);
shape.graphics.drawRect(0,0,5,5);
mc.addChild(shape);
var shape2:Shape = new Shape();
shape2.graphics.beginFill(0);
shape2.graphics.drawRect(0,0,5,5);
mc.addChild(shape2);
addChild(mc);
getObjectsUnderPoint(new Point(1,1)); // returns [object Shape],[object Shape]
返された DisplayObjectsのプロパティを使用して、parent
DisplayObjectContainer を見つけることができます...
var containerBeingLocated:Sprite;
for each (var obj:DisplayObject in objectsUnderPoint) {
if (isWithin(obj, containerBeingLocated)) {
trace('container located');
}
}
function isWithin ($obj:DisplayObject, $container:DisplayObjectContainer):Boolean {
while ($obj) {
if ($obj === $container) {
return true;
} else {
$obj = $obj.parent;
}
}
return false;
}