我有许多以“问题”开头然后以数字结尾的字符串变量。(“问题 1”)每个变量都有一个问题(“它说 E 多少次?”) 舞台上有一个可编辑的文本框,用户在其中键入他希望在不同文本框中显示的问题编号。("1") 当用户点击一个按钮时,我希望Question1的文本应该显示在文本框中。我的代码如下所示:
var Question1:String = "How many times does it say E?" ;
var Question2:String = "How many times does it say B?" ;
var Question3:String = "How many times does it say A?" ;
myButton.addEventListener(MouseEvent.CLICK, displayQuestion);
function displayQuestion(event:MouseEvent):void
{
var QuestionNumber:Number = Number(userInputQuestionNumber.text);
textBoxDisplayQuestion.text= Question(QuestionNumber);
}
如何让textBoxDisplayQuestion显示问题的实际文本?(我现在的代码显然不起作用!!)
但是这个例子似乎不起作用:我创建了一个名为Question的类,代码如下:
import Question;
var QuNoLoad:Number;
var Qu1:Question = new Question(1,"how","yes","no","maybe","so","AnsB","AnsA");
trace(Qu1.QuNo, Qu1.Qu, Qu1.AnsA,Qu1.AnsB, Qu1.AnsC, Qu1.AnsD, Qu1.CorAns, Qu1.FaCorAns);
//the following is the code for the button
loadQu.addEventListener(MouseEvent.CLICK, loadQuClick);
function loadQuClick(event:MouseEvent):void
{
//this sets the variable "QuNoLoad" with the contents of the "textBoxQuLoad"
//imagine the user inputed "1"
QuNoLoad=Number(textBoxQuLoad.text);
//this SHOULD!! display the contents of "Qu1.Qu"
textQu.text= this["Qu"+QuNoLoad.toString()+".Qu"]
//and when i traced this statment the value was "undefined"
}
为什么???