我想添加一个我加载到Array
的子项
我有Math.random
函数返回Number
并应触发addChild
后来我想把它拼接成另一个Array
。
var ground1: MovieClip = new Ground_01;
var ground2: MovieClip = new Ground_02;
var ground3: MovieClip = new Ground_03;
var groundArray: Array = new Array();
var groundMoveArray: Array = new Array();
public function loadGroundArray() {
groundArray.push(ground1);
groundArray.push(ground2);
groundArray.push(ground3);
}
public function randomGround(minNum: Number, maxNum: Number): Number {
minNum = 0;
maxNum = groundArray.length;
return (Math.ceil(Math.random() * (0 + maxNum)));
}
答案 0 :(得分:0)
var ground1: MovieClip = new Ground_01();
var ground2: MovieClip = new Ground_02();
var ground3: MovieClip = new Ground_03();
var groundArray: Array = new Array();
var groundMoveArray: Array = new Array();
public function loadGroundArray() {
groundArray.push(ground1);
groundArray.push(ground2);
groundArray.push(ground3);
}
public function addRandomGroundToStage(): void {
var randomGroundIndex:int = Math.round(Math.random*(groundArray.length-1));
addChild(groundArray[randomGroundIndex]);
}