Question

Is ther a way to get all movie clips inside a area with AS3 I need this to do multiple selection.

Was it helpful?

Solution

It might not be necessary to use getObjectsUnderPoint(). If all the items are in a single containing clip you could simply loop through the containers children and check if they are within your selection.

// The list of items contained in the selection.
var selection:Array = new Array();

// The rectangle that defines the selection in the containers coordinate space.
var selectionRect:Rectangle = new Rectangle(x, y, width, height);

// Loop throught the containers children.
for(var a:int; a<container.numChildren; a++){
    // Get the childs bounds in the containers coordinate space.
    var child:DisplayObject = container.getChildAt(a);
    var childBounds:Rectangle = child.getRect(container);

    // Check if this childs bounds against the selection bounds
    if(childBounds.intersects(selectionRect)){
        selection.push(child);
    }
}

OTHER TIPS

I am pretty sure there is nothing "built-in" that will get all the Movieclips inside an area.

The only thing that comes close is probably getObjectsUnderPoint. This method will give you the list of DisplayObjects under a single Point, not an area, but could be used to manually find MovieClips in a area.

You could have a sprite that is the "area". That meaning that it's the size of the area you want to check. So just loop through every movieclip and check with hitTestObject or hitTestPoint if the movieclip collides with the sprite. If so then it's in that area. This is how I create the drag and select units thing in RTS games.

Well if you want to check all objects under an area , you have to use for loop with hitTestPoint method. and this loop can be optmized by putting large increment on this for loop. for example if you know that you have no such object whose width or height is smaller than 50 pixel then you will put 50 as the increment in the nested loop either on width or height or both.. here is the sample to find all points under the rectangle area or any area you specify

for(var j:int=Rect.x; j0) { trace ("found objects"+objects); } } }

Well if you want to check all objects under an area , you have to use for loop with hitTestPoint method. and this loop can be optmized by putting large increment on this for loop. for example if you know that you have no such object whose width or height is smaller than 50 pixel then you will put 50 as the increment in the nested loop either on width or height or both.. here is the sample to find all points under the rectangle area or any area you specify

for(var j:int=Rect.x; j<=Rect.width; j++) {

for(var i:int=Rect.y; i<=Rect.height; i++) {

var pt:Point = new Point(x,y);

objects = container.getObjectsUnderPoint(pt)

if(objects.length>0) { trace ("found objects"+objects); }

}

}

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