Hi, I have some code here, works fine and everything, but I was just wondering if this code is an efficient way to add an object onto the screen. I just have mc's come on depending the amount in varFromAnotherFrame. Is there a better way to do this?
var someArray:Array = new Array();
for (var i:Number = 0; i < varFromAnotherFrame; i++)
{
if (someArray.length < 6)
{
var newMc:libraryMc = new libraryMc();
someArray[i] = newMc;
addChild(newMc);
newMc.x = -295 + (someArray.length * 80);
newMc.y = -10;
}
else if (someArray.length > 5 && someArray.length < 12)
{
var newMc2:secondLibraryItem = new sisecondLibraryItem();
someArray[i] = newMc2;
addChild(newMc2);
newMc2.x = -775 + (someArray.length * 80);
newMc2.y = -0;
}
}
Thanks Alex
that could be more transparent (ie, easier to understand) and efficient:
var someArray:Array = new Array();
for (var i:Number = 0; i < Math.min(12,varFromAnotherFrame); i++)
{
if (i < 6)
{
var newMc:libraryMc = new libraryMc();someArray.push(newMc);
addChild(newMc);
newMc.x = -295 + (someArray.length * 80);
newMc.y = -10;
}
else
{
var newMc2:secondLibraryItem = new sisecondLibraryItem();
someArray.push(newMc2);
addChild(newMc2);
newMc2.x = -775 + (someArray.length * 80);
newMc2.y = -0;
}
}
North America
Europe, Middle East and Africa
Asia Pacific