1
votes

I am re-learning ActionScript, and I am trying to learn from digitaldogbyte.com 'Dynamically attached library objects in ActionScript 3.0'. This example, in digialdogbyte, sets the position of each MovieClip across the X position. At high number of numberOfClips, the Objects run right and of the Stage, and out-of-view.

I am trying to adapt the following script to:

  1. wrap the flow of objects to a new line when the edge of the Stage is reached

  2. every other block is coloured red with text colour set to white

The ActionScript:

var numberOfClips:Number = 150;

var xStart:Number = 0;
var yStart:Number = 0;
var xVal:Number = xStart;
var xOffset:Number = 2;

for (var i:Number=0; i<numberOfClips; i++)
{
    var mc:myClip = new myClip();
    mc.name = "myClip"+(i+1);
    this.addChild (mc);

    mc.y = yStart;
    mc.x = xVal;
    xVal = mc.x + mc.width + this.xOffset;
    mc.label_txt.text = (i).toString();

}

I'd be grateful if anyone could suggest ways to adapt this script as such.

1

1 Answers

2
votes

Add something simple like:

var numberOfClips:Number = 150;
var grid:Rectangle = new Rectangle(0, 0, 20, 20);

for(var i:Number = 0; i < numberOfClips; i++)
{
    var mc:myClip = new myClip();
    addChild(mc);

    mc.x = grid.x;
    mc.y = grid.y;

    grid.x += grid.width;

    // If the new x position is outside of the stage, reset it and
    // increase the y position.
    if(grid.x + grid.width > stage.stageWidth)
    {
        grid.x = 0;
        grid.y += grid.height;
    }

}

You can adjust the width and height of the grid on line 2.