Ok, here is my code:
BlockGame.as: (document class)
package
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.ui.Mouse;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.utils.getDefinitionByName;
public class BlockGame extends MovieClip
{
public var bank:block_bank;
public var bg:backgroundImage;
public var blue:BlueBlock;
public var green:GreenBlock;
public var red:RedBlock;
public var yellow:YellowBlock;
public var random_color:Number;
public static var mouse_x:Number;
public static var mouse_y:Number;
public function BlockGame()
{
var movieArray:Array = new Array();
movieArray = ["blue","green","red","yellow"];
for (var i:Number=1; i<=64; i++)
{
random_color = Math.floor(Math.random() * 4);
if ((movieArray[random_color]) == "blue")
{
blue = new BlueBlock();
addChild( blue );
}
else if ((movieArray[random_color]) == "green")
{
green = new GreenBlock();
addChild( green );
}
else if ((movieArray[random_color]) == "red")
{
red = new RedBlock();
addChild( red );
}
else
{
yellow = new YellowBlock();
addChild( yellow );
}
}
bank = new block_bank();
addChild( bank );
bg = new backgroundImage();
addChild( bg );
setChildIndex( bg, 0 );
addEventListener(Event.ENTER_FRAME, mouseLocations);
}
function mouseLocations(evt:Event)
{
mouse_x = stage.mouseX;
mouse_y = stage.mouseY;
}
}
}
BlueBlocks.as: (identical to GreenBlocks and RedBlocks and YellowBlocks)
package
{
import flash.events.EventDispatcher;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.ui.Mouse;
public class BlueBlock extends MovieClip
{
public var calculations:Array;
public var box_x:Number;
public var box_y:Number;
public var box_size:Number;
public function BlueBlock():void
{
this.addEventListener(Event.ENTER_FRAME, sizelocation);
this.width = 25;
this.height = 25;
this.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
this.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
box_x = (Math.round(((Math.random()* block_bank.bank_x ) + block_bank.bank_width )/25)*25);
box_y = (Math.round(((Math.random()* block_bank.bank_x ) + block_bank.bank_height )/25)*25);
}
public function sizelocation(event:Event):void
{
this.width = box_size;
this.height = box_size;
this.x = box_x;
this.y = box_y;
}
function mouseDownHandler(evt:MouseEvent):void
{
Mouse.hide();
addEventListener(Event.ENTER_FRAME, calculateLocation);
}
function mouseUpHandler(evt:MouseEvent):void
{
Mouse.show();
removeEventListener(Event.ENTER_FRAME, calculateLocation);
}
function calculateLocation(evt:Event):void
{
calculations = Blocks.snapto();
box_x = calculations[0];
box_y = calculations[1];
box_size = calculations[2];
this.parent.setChildIndex(this, this.parent.numChildren-1);
}
}
}
The issue here is that all the blocks come in at 0,0 instead of the random position that it should come in at.