我是 AS3 编程的新手,我第一次使用类来开发游戏。我的问题是我有一堆对象要启动,我不希望在我的文档类中完成,但我不知道是否可以使用另一个文件,以及如何在其中完成所有这些. 我的代码(文档类)是:
package {
import flash.display.MovieClip;
import flash.utils.getDefinitionByName;
public class Ingredient_game extends MovieClip {
//variables
var allFoods:Array;
//functions
public function Ingredient_game() {
// constructor code
//add an event listener to update position
addEventListener(Event.ENTER_FRAME, moveOnEscalator);
//initialise allFoods array
allFoods = new Array();
var mc1:MovieClip = new carrot();
var mc2:MovieClip = new lemon();
var mc3:MovieClip = new potato();
var mc4:MovieClip = new tomato();
var mc5:MovieClip = new cereals();
var mc6:MovieClip = new milk();
var mc7:MovieClip = new yoghurt();
var mc8:MovieClip = new apple();
var mc9:MovieClip = new bananas();
var mc10:MovieClip = new grapes();
var mc11:MovieClip = new orange();
var mc12:MovieClip = new pear();
var mc13:MovieClip = new strawberry();
var mc14:MovieClip = new watermelon();
allFoods.push(mc1);
allFoods.push(mc2);
allFoods.push(mc3);
allFoods.push(mc4);
allFoods.push(mc5);
allFoods.push(mc6);
allFoods.push(mc7);
allFoods.push(mc8);
allFoods.push(mc9);
allFoods.push(mc10);
allFoods.push(mc11);
allFoods.push(mc12);
allFoods.push(mc13);
allFoods.push(mc14);
for( var i = 0; i < allFoods.length; i++ ){
var newx:Number = 800+100*i;
allFoods[i].initialisePosition(newx, 500);
addChild(allFoods[i]);
}
}
function moveOnEscalator(e:Event):void{
for( var i = 0; i < allFoods.length; i++ ){
if( allFoods[i].x >= 0 ){
allFoods[i].x -= 5;
}
else{
allFoods[i].x = allFoods.length*100;
}
}
}
}
}
我真正需要的是把代码从另一个文件放到其他var mc1
地方allFoods.push(mc14);
!知道怎么做吗??