views:

19

answers:

2

Hi, I am still a newbie to flash....still trying to learn AS3 atm

I got some movie clips with different shapes and I would like to make a pattern from those movie clips. I have assigned the x y co-ordinates of those movie clips with the Math.random function. However, the shapes overlap all the time, what can I do to avoid it? Someone has suggested that I could add the clips to a list after being randomised, then define the area which couldn't be place by the other movie clips. However, how can I define that area in AS3? I have tried to do the hitTest, but I am not too sure what should I do if it has detected a hit, since there's a probability that it will hit another shape. Hope you guys could help me a bit!Thank you very much!

A: 

use this in flex:

http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/spark/components/TileGroup.html

and in flash look for some new layouts.

Eugene
A: 

This is a basic verison of the functionality with just 2 shapes, you could extend it by creating an array of shapes and looping to find if each new shape hits any other

var shape1:Shape1 = new Shape1();
shape1.x = 0;
shape1.y = 0;
addChild(shape1);

var shape2:Shape1 = new Shape1();
shape2.x = 0;
shape2.y = 0;
addChild(shape2);

while(shape1.hitTestObject(shape2))
{
    shape2.x = Math.random() * stage.stageWidth;
    shape2.y = Math.random() * stage.stageHeight;
}
daidai