How do I load library objects by string list using Flash and AS3?
I need to understand string lists, arrays, and sprites better.
WHAT I WANT TO DO
Load enemies to stage using a string list "Orange ball, red ball, green ball etc"
EXPLANATION
The tutorials I've been given are too basic, or they are incomplete
examples that don't explain the classes being used.
Trace statements are not showing me how I'm accessing the name or class of an object. I need examples. Non-packaged classes preferred. Thanks.
WHAT I GOT WORKING "I knew I'd mix up the class and name"
SYMBOL PROPERTIES
name is they're not name specific, I call mine noname"
class is Pyramid
//Creates 10 enemies and trace statement
import flash.display.Sprite;
var sprites:Array = new Array();
for(var i:Number=0;i<10;i++){
//var test:Sprite = new Sprite();
var test:Pyramid = new Pyramid();
sprites.push(test);
addChild(test);
test.name = "littlebox_"+ i
trace(test.name)
with(test){
x=i*25;
}
}
///////////////////////////////////////////////////////////////////////
/*debu's example*/
//Creates 10 enemies
var enemyArray:Array = new Array();
for (var i:int = 0; i < 10; i++)
{
var noname:Pyramid = new Pyramid();
noname.x = i*10; //this will just assign some different x and y value depending on i.
noname.y = i*11;
enemyArray.push(noname); //put the enemy into the array
addChild(noname); //puts it on the stage
}
///////////////////////////////////////////////////////////////////////
//centered and trace statement
var sprite:Sprite;
var noname:Pyramid = new Pyramid;
//var noname:Pyramid2 = new Pyramid2;
sprite = new Sprite();
sprite.name = "Pyramid" + 1;
addChild( noname);
noname.x = stage.stageWidth/3;
noname.y = stage.stageHeight/3;
trace( getChildByName( "Pyramid" + 1 ) ); // [object Sprite]
PREVIOUS MODIFIED
var enemyList:Object = new Object();
//var enemy:Sprite = new Sprite();
var enemy:BadGuy = new BadGuy();
enemy.name = "BadGuy";
enemyList [enemy.name] = enemy;
//var enemyList:Object = new Object();
//for (var i:int = 0; i < 10; i++) {
//var enemy:Sprite = new Sprite();
//var enemy:BadGuy = new BadGuy();
//enemy.name = "BadGuy" + i;
//enemyList [enemy.name] = enemy;
//}
//for (var i:String in enemyList){
//var enemy:Sprite = enemyList[i]
//do something to enemy sprite
//}