AS3 accesing Library item form an exterior function
Hi, so here is the idea:
I want to create a simple game that creates blocks
package
{
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.display.Stage;
import Functions.LD_moveToPoint; // custom function
import Functions.makeBlocks; // custom function
public class Main extends MovieClip
{
public function Main()
{
var GameCTNR: Game_CTNR = new Game_CTNR();
addChild(GameCTNR);
//makeBlocks(blok10,Game_CTNR,15,3);
// blok10 is a library item to copy numerous times, Game_CTNR is a mc that holds all other mc's, 15 is the horizontal row count of blocks and 3 is the vertical count.
}
}
}
--------------------------------------------------------
and now the makeBlocks() function:
package Functions
{
import flash.geom.*
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.display.Stage;
public function makeBlocks(LibraryItem:Object, Target:Object, HorizontalCount:Number = 10, VerticalCount:Number = 3 ):Array
{
var h = 0;
var v = 0;
var Yoffset = 20
var StageWidth = 800
var blocksOffsetH = 1
var blocksOffsetV = 1
var BlockArray:Array = new Array();
for(h=0;h<=HorizontalCount-1;h++)
{
for(v=0;v<=VerticalCount-1;v++)
{
var BLOK: LibraryItem = new LibraryItem(); //pick an item from library and use it as a source for copying
BLOK.x=h*(BLOK.width+blocksOffsetH)+(StageWidth/2- ((BLOK.width+blocksOffsetH)*HorizontalCount/2))
BLOK.y=v*(BLOK.height+blocksOffsetV) + Yoffset
BlockArray.push(BLOK)
Target.addChild(BLOK) // add blocks to a object present in the scene
}
}
return BlockArray;
}
}
the problem is that It doesn't work, I can't use the LibraryItem variable as it throws an error.