views:

52

answers:

5

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

A: 

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.

TandemAdam
A: 

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.

TreeTree
can u put some code it sounds realy good
Delta
A: 

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

Muhammad Irfan
A: 

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

}

}

Muhammad Irfan
A: 

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);
    }
}
cmann