试图加载一定数量的物体进行舞台,惨遭失败

时间:2009-10-31 11:24:18

标签: flash actionscript-3

我在下面评论了我的代码,以反映我在这里尝试做的事情。 Flash现在给我一个1084的错误,但我无法发现我的问题。我希望它与this['circle'+i]语句有关。

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)

function 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
 }
}

任何意见都赞赏。

1 个答案:

答案 0 :(得分:3)

“this”是一个关键字,您正在尝试将其定义为变量。

你要么去对象范围

this['circle'+i] = new circle();  

或本地范围

var c:circle = new circle();  

或对象范围数组/向量(最佳)

var circles:Array = new Array() // (outside the function)
circles[i] = new circle()       // (instead of this['circle'+i] = new circle();)


此外,类首先变为upcase( Circle 而不是 circle ),并且您希望在 i< 5 时循环,而不是 i == 5