Flash CS5 Actionscript 3.0不会进入随机帧

Flash CS5 Actionscript 3.0不会进入随机帧,flash,variables,random,frame,Flash,Variables,Random,Frame,我对Flash还很陌生,我正在我的网站上为你做一个地形测试 我的地形学测验的目标是随机获得72道城市名称问题。我已经做过了,但问题是,因为顺序是随机的,所以问题可能会再次出现。所以,如果你完成了一个问题,以后就不能再回来了。我想我可以通过给每个帧一个变量来解决这个问题,每个帧在开始时都有值“2”。如果转到某个帧并键入正确的cityname,该帧的变量将变为“1”。如果键入错误的答案,变量将变为“0”。在每一帧的开头,我都写道:“如果(city01==2){”,那么如果你以前从未遇到过这个问题,你

我对Flash还很陌生,我正在我的网站上为你做一个地形测试

我的地形学测验的目标是随机获得72道城市名称问题。我已经做过了,但问题是,因为顺序是随机的,所以问题可能会再次出现。所以,如果你完成了一个问题,以后就不能再回来了。我想我可以通过给每个帧一个变量来解决这个问题,每个帧在开始时都有值“2”。如果转到某个帧并键入正确的cityname,该帧的变量将变为“1”。如果键入错误的答案,变量将变为“0”。在每一帧的开头,我都写道:“如果(city01==2){”,那么如果你以前从未遇到过这个问题,你就会得到这个问题,如果没有,你就会进入下一个(随机)帧

在第一帧中,我定义了变量:

var input:String;
var randomnumber:int;

var city01:int = 2;
var city02:int = 2;
var city03:int = 2;
var city04:int = 2;
etc. etc. etc.
以下是问题框架代码的示例:

    stop();
if(city26 == 2){


okButton.addEventListener(MouseEvent.CLICK, okClickcity26);

function okClickcity26(event:MouseEvent):void{
    input = textbox.text;
    if(input == "Dakar"){
        city26 = 1; 
    }else{
        city26 = 0; 
    }

    randomnumber = Math.floor(Math.random()*(1+73-3))+3;
    gotoAndStop(randomnumber);
}
}else{
    randomnumber = Math.floor(Math.random()*(1+73-3))+3;
    gotoAndStop(randomnumber);
    }
Flash会将变量更改为“1”或“2”,但也会显示问题,而不会转到下一帧

所以Flash在最后执行代码:

    else{
randomnumber = Math.floor(Math.random()*(1+73-3))+3;
gotoAndStop(randomnumber);
}
但不去那个随机帧

有人知道我做错了什么吗


这是我在论坛上的第一个问题,所以我希望我能很好地解释我的问题,以便你能帮助我。谢谢。我可以提供一个不同的解决方案:也许你可以使用一系列问题ID/INT(看起来你可能已经有了),然后在洗牌之后,一个接一个地弹出ID以获得不重复的ID

也许这比跟踪每个问题的每个状态更容易,然后检查随机数的生成。只是我不确定,我看到的问题是,你想以随机顺序处理单个问题,但在看到问题后没有重复的问题



编辑:添加了使用数组的代码示例

数组(在本例中)可以充当问题ID(数字)的动态列表,您可以通过索引或多种方法访问这些ID。因此,您可以将这些数字/ID关联到一个帧并跳转到它们

它们在语言中非常常见(尽管它们可能被称为不同的),而且非常有用。在您的原始代码中,我将使用一个长度为72的数组来保存我的值,而不必逐个定义72个变量(city01、city02、city03等)

我强烈建议您阅读actionscript 3中的相关内容(因为这就是您正在使用的内容):

在代码中使用数组来显示我在原始答案中的意思的示例:

// create an array called "questionIds"
var questionIds:Array = new Array();

// using a loop to add ints 0 to 71 to the array
for(var counter:int = 0; counter < 72; counter++){
    questionIds.push(counter);
}

// the array contains the numbers 0 to 71 in order now, shuffle them in to a random order
trace("Preshuffled array: {"+ questionIds +"}");

questionIds.sort(function (inputA:int, inputB:int):int {
    return (Math.floor(Math.random() * 3) - 1);
});

trace("\nShuffled array: "+ questionIds +"}");

//to get a int from the array, can use pop() method, which removes and returns the last element on the array
// since that number is removed, it will never appear again
var currentId:int = questionIds.pop();

// can keep calling pop() method on the array to return the next last number
// what you do with the value of "currentId" is up to you -however you go to your question in your quiz
currentId = questionIds.pop();
trace(currentId);

// you can also check how many elements are left in the array by checking the length of it:
trace(questionIds.length); // which should be 70 left now as it started with 72 and 2 items were pop()'ed off

// when it hits 0, there are no more items left in the array, (calling pop() will then return "undefined")
if(questionIds.length == 0){
    trace("no more items left");
}
//创建一个名为“questionID”的数组
var questionId:Array=new Array();
//使用循环将整数0到71添加到数组中
用于(变量计数器:int=0;计数器<72;计数器++){
问题ID。推(计数器);
}
//数组按顺序包含数字0到71。现在,将它们随机排列
跟踪(“预串数组:{“+QuestionID+”}”);
sort(函数(inputA:int,inputB:int):int{
返回值(Math.floor(Math.random()*3)-1);
});
跟踪(“\n缓冲数组:“+QuestionID+”}”);
//要从数组中获取int,可以使用pop()方法,该方法删除并返回数组中的最后一个元素
//由于该数字已被删除,它将不再出现
var currentId:int=questionId.pop();
//可以继续调用数组上的pop()方法以返回最后一个数字
//如何处理“currentId”的值取决于您-无论您在测验中如何回答问题
currentId=questionID.pop();
跟踪(currentId);
//还可以通过检查数组的长度来检查数组中剩余的元素数:
跟踪(问题ID.长度);//现在应该剩下70个了,因为它从72开始,2个项目被弹出()
//当它达到0时,数组中就没有其他项了(调用pop()将返回“undefined”)
如果(questionID.length==0){
跟踪(“不再留下任何项目”);
}

首先感谢您的回答。我对数组不太熟悉,但是您知道是否可以让数组的每个部分都运行一个帧吗?