我正在创建一个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