A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Build Grid with Random Boxes

  1. #1
    Junior Member
    Join Date
    Aug 2001

    Build Grid with Random Boxes

    I'm starting to pull my hair out trying to build a grid with random boxes. The script that I was able to come up with so far randomly places a duplicated mc but they will be placed ontop of each other. Can someone please give me help and give me some advice on what I might be doing wrong and which direction I should be going in? I would be very greatfull for the help. Here is what I have been able to come up with so far.

    function buildGrid() {
    var xStart:Number = getProperty(box_mc, _x);
    var yStart:Number = getProperty(box_mc, _y);
    var xSpacing:Number = 10;
    var ySpacing:Number = 10;
    var v:Number = 0;
    var i:Number = -1;
    while (++i<32) {
    var j:Number = -1;
    while (++j<17) {
    var box:String = "grid"+v;
    var boxDepth:Number = getDepth(box_mc);
    if (boxDepth == 1) {
    _root.box_mc.duplicateMovieClip(box, v);
    _root[box]._x = xStart+random(i)*xSpacing;
    _root[box]._y = yStart+random(j)*ySpacing;
    } else if (_root[box] != 1) {

  2. #2
    Senior Member
    Join Date
    Sep 2000

    I'm not quite sure i understand the random part of the question, but this will build out a grid based on row / column amount. Movieclip in library has a linkageID of "box"... Might be of some help to get started.

    var columns = 32 // cells wide
    var rows = 17  // cells high
    var startX = 100 // starting point x-axis
    var startY = 13 // starting point y-axis
    var depth  = 0   // depth
    var space = 10; //block spacing
    for (i=0; i<columns; i++) {  
    	for (j=0; j<rows; j++) {  
    		this.attachMovie("box", "box_"+i+"_"+j, depth++);
    		ref = this["box_"+i+"_"+j];
    		ref._x=startX + (i * space);
    		ref._y=startY + (j * space);
    hope this helps some,

  3. #3
    Junior Member
    Join Date
    Aug 2001
    that does help. thanks

  4. #4
    Junior Member
    Join Date
    Feb 2005
    Hey Dunc, or anyone who can help.

    Could you show me how to bind and xml file to that grid?

    I want to make a gallery using an xml file and a grid. I want each cell in the column to have a linkable thumbnail in it.

    I could really use the help. Thanks?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center