我正在創建一個AS3中的隱藏對象遊戲。大多數情況下它工作正常。我所看到的唯一問題是,我希望代碼將十個對象拉到一個單詞列表中供用戶在場景中查找。我希望列表也是隨機的,所以遊戲不會太平常。現在,我在這個場景中有大約30個物體,但是如果它拉出任何物體,它最多隻能拉三個單詞列表。誰能告訴我我要去哪裏?如何將定義數量的剪輯拖放到舞臺上?
var obArr:Array = new Array();
var randArray:Array = new Array();
var chkCnt:Number=10;
stage.addEventListener(Event.ENTER_FRAME, setupStage);
stage.addEventListener(MouseEvent.CLICK, clickOb);
//set up current stage
function setupStage(e:Event) {
chkCnt=10;
randArray.length=0;
obArr=[];
//count the objects on stage
for (var n=0; n<gb1.numChildren; n++) {
//get the children
var ob=gb1.getChildAt(n);
//only take movie clips
if (ob is MovieClip) {
//only count the movie clips that have name declared
if (ob.myname!=null) {
//push to array
obArr.push(MovieClip(ob));
}
}
}
//clear the list
nameslist.text="";
//build objects list
for (n=0; n<obArr.length; n++) {
//add the name of object
nameslist.appendText(String (obArr[n].myname));
nameslist.appendText("\n\n");
}
//this is not needed anymore;
stage.removeEventListener(Event.ENTER_FRAME, setupStage);
}
//stage was clicked;
function clickOb(e:MouseEvent) {
var clicked=false;
//check which object was clicked
for (var n=0; n<obArr.length; n++) {
//add the name of object
if (obArr[n].hitTestPoint(mouseX,mouseY,true)) {
//object is clicked
clicked=true;
//hide
obArr[n].visible=false;
//play sound
ping.play();
//remove from array
obArr.splice(n,1);
}
}
//rebuild text list
if (clicked) {
//clear the list
nameslist.text="";
//build objects list
for (n=0; n<obArr.length; n++) {
//add the name of object
nameslist.appendText(String (obArr[n].myname));
nameslist.appendText("\n\n");
}
//check if array is empty meaning all objects were removed;
if (n==0) {
GB2Unlock.visible=true;
}
}
}
它最容易發佈.fla – BadFeelingAboutThis