Actionscript 3 计时器完成时的随机电影剪辑

Actionscript 3 计时器完成时的随机电影剪辑,actionscript-3,timer,Actionscript 3,Timer,我正在用AS3制作一个游戏,我想在计时器完成后在屏幕上随机添加movieClips 例如: something.addEventListener(TimerEvent.TIMER_COMPLETE, Finish); function Finish(event : TimerEvent) : void { randomly add movieClip1 or movieClip2 or movieClip3 } 我该怎么做 多谢各位 编辑 谢谢你的回答。我试过很多方法,但都不管用。。我试过

我正在用AS3制作一个游戏,我想在计时器完成后在屏幕上随机添加movieClips

例如:

something.addEventListener(TimerEvent.TIMER_COMPLETE, Finish);

function Finish(event : TimerEvent) : void {
randomly add movieClip1 or movieClip2 or movieClip3
}
我该怎么做

多谢各位


编辑

谢谢你的回答。我试过很多方法,但都不管用。。我试过:

_movieClips.push(new _classes[Math.floor(Math.random() * _classes.length)]()); // this line chooses a random index of your _classes Array which will return the Class at that index 
stageRef.addChild(_movieClips[_movieClips.length-1]); 
if (stageRef.getChildByName("_movieClips[0]") == null) { 
trace("poubelle1"); 
_movieClips[0].addEventListener(MouseEvent.CLICK, removePoubelle, false, 0, true); 
}else if (stageRef.getChildByName("_movieClips[1]") == null) { 
trace("poubelle2"); 
_movieClips[1].addEventListener(MouseEvent.CLICK, removePoubelle2, false, 0, true); 
}else if (stageRef.getChildByName("_movieClips[2]") == null) { 
trace("poubelle3"); 
_movieClips[2].addEventListener(MouseEvent.CLICK, removePoubelle3, false, 0, true); 
}
没有错误,但我只能在movieClip刚刚出现时单击。如果我正在等待,并且出现了第二个,我不能单击其中任何一个

我试过:

_movieClips.push(new _classes[Math.floor(Math.random() * _classes.length)]()); // this line chooses a random index of your _classes Array which will return the Class at that index 
stageRef.addChild(_movieClips[_movieClips.length-1]); 
if (_movieClips[0].visible== true){ 
trace("poubelle1"); 
_movieClips[0].addEventListener(MouseEvent.CLICK, removePoubelle, false, 0, true); 
} 
if (_movieClips[1].visible== true){ 
trace("poubelle2"); 
_movieClips[1].addEventListener(MouseEvent.CLICK, removePoubelle2, false, 0, true); 
} 
if (_movieClips[2].visible== true){ 
trace("poubelle3"); 
_movieClips[2].addEventListener(MouseEvent.CLICK, removePoubelle3, false, 0, true); 
} 
但是错误#1010:一个术语没有定义,没有属性。 你知道我怎么做吗?
谢谢

可以使用带有类名的数组“加载”:

var _classes:Array = new Array(movieClip1, movieClip2, movieClip3);
var _movieClips:Array = new Array(); // this Array is used to instantiate your random MovieClips
然后,在计时器完成处理程序中:

_movieClips.push(new _classes[Math.floor(Math.random() * _classes.length)]); // this line chooses a random index of your _classes Array which will return the Class at that index
addChild(_movieClips[_movieClips.length-1]);

抱歉,我遇到了以下错误:错误#1007:尝试在非构造函数上实例化。你知道为什么吗?(这一行:_movieClips.push(新的_类[Math.floor(Math.random()*_classes.length)]);)您可能需要在第二个方括号之后添加一对空括号(),即-在行的末尾:…*_类别(长度)();;这些参数通常用于向新实例化的类传递参数。另一个问题可能是如何填充_类数组。不要在字符串中传递:即,不要“movieClip”。您需要movieClip,以便传递的是一个类,而不是一个类名字符串。如果仍然不起作用,请告诉我。太好了!是括号。非常感谢。出现该错误是因为将事件侦听器添加到类中,而不是该类的实例。在我提供的代码中,您可以通过_MovieClips数组引用添加的MovieClips;最近添加的MovieClip将位于数组的最后一个索引位置,即数组的长度-1(第一个添加的MovieClip将位于索引位置0)。添加事件侦听器,如_movieClips[\u movieClips.length-1].addEventListener(…),如果要将其添加到最近添加的MovieClip中。或者使用索引位置。如果这不合理,请告诉我。另外,作为提示;类名通常以大写字母开头。这可以减少关于什么是实例和什么是类的混淆。所以,也许可以给你的电影命名为MovieClips MovieClip1、MovieClip2等等(尽管你可能需要更具描述性的名字)。