I need to add many children (addChild()) in a specific area. This area is not in a regular shape (figure). I noticed that if I want to add many children into my figure Flash creates rectangle that represent my figure and some of my children are going out of the figure but into this rectangle. I came to the idea to make many small rectangles that will cover my non regular figure and using arrays to distribute all the children into those small rectangles. Is this the right way? I will appreciate some ideas. Thanks
//----------------------------------------------------------------------------
function randomRange(max:Number, min:Number = 0):Number
{
return Math.random() * (max - min) + min;
}
public function Main()
{
var bounds:Rectangle = Area_mc.getBounds(Area_mc.stage);
var xIncr:int = randomRange(15,320);
var yIncr:int = randomRange(15,220);
for (var xPos=bounds.x; xPos <= bounds.x + bounds.width; xPos += xIncr)
{
for (var yPos=bounds.y; yPos <= bounds.y + bounds.height; yPos += yIncr)
{
var isInsideShape:Boolean = Area_mc.hitTestPoint(xPos,yPos,true);
if (isInsideShape)
{
//trace(isInsideShape);
stage.addChild(_symbol);
_symbol.x = xPos;
_symbol.y = yPos;
}
}
}
}
Ok, I have random X and Y but the child always going on the right side of the container!:)