trying to load a certain number of objects to stage, failing miserably
I commented my code below to reflect what I am attempting to do here. Flash is throwing me a 1084 error at the moment but I cannot spot my issue. I expect that it is something to do with the this['circle'+i]
statement.
var boxOne = new box(); stage.addChild(boxOne); boxOne.x = stage.stageWidth/2; boxOne.y = stage.stageHeight/2; //This far is fine, no issues. boxOne.addEventListener(MouseEvent.CLICK,spawn) fu开发者_开发知识库nction spawn() { //Spawn function called by MouseEvent for (var i:int = 0;i==5;i++) { //For a total of 5 times var this['circle'+i] = new circle(); //Make a new circle object stage.addChild(this['circle'+i]); //Add it to the stage this['circle'+i].x = stage.stageWidth / (Math.random()*10); //Set X this['circle'+i].y = stage.stageHeight / (Math.random()*10); //Set Y } }
Any input appreciated.
"this" is a keyword, and you're trying to define it as a variable.
You either go object scope
this['circle'+i] = new circle();
or local scope
var c:circle = new circle();
or an object scope array/vector (best)
var circles:Array = new Array() // (outside the function)
circles[i] = new circle() // (instead of this['circle'+i] = new circle();)
Also, classes go upcase first (Circle not circle), and you want to loop while i<5, not i==5
精彩评论