所以我有窗口在哪里有问题和2个单选按钮。在AS3中,我添加了答案标签和值。它看起来像是:
function myAnswers(e:MouseEvent):void {
answer.rb1.label = "Answer 1"; // This answer should be always CORRECT
answer.rb2.label = "Answer 2"; // This answer should be always INCORRECT
answer.rb1.value = "TRUE"; // Here I set for rb1 value "TRUE"
answer.rb2.value = "FALSE"; // Here I set for rb2 value "FALSE"
}
我如何随机化这些答案并始终将答案1保留为TRUE值?
我的意思是如果我设置为rb1 label =“Answer 1”我需要设置为rb1 value =“TRUE”。
答案 0 :(得分:0)
您可以使用Math.random()
方法确定rb1
或rb2
是否应包含“正确”答案:
function myAnswers(e:MouseEvent):void {
// First, we decide whether rb1 or rb2 should be the "correct" radio button
var correctRadio:RadioButton = Math.random() > .5 ? answer.rb1 : answer.rb2;
// Then, we set incorrectRadio to the opposite of correct radio
var inccorrectRadio:RadioButton = correctRadio == answer.rb1 ? answer.rb2 : answer.rb1;
// Finally, we set the labels and values on the "correct" and "incorrect" radio buttons
correctRadio.label = "Answer 1"; // This answer should be always CORRECT
inccorrectRadio.label = "Answer 2"; // This answer should be always INCORRECT
correctRadio.value = "TRUE"; // Here I set the correct radio value "TRUE"
inccorrectRadio.value = "FALSE"; // Here I set the incorrect radio value "FALSE"
}