"Question"으로 시작하는 문자열 변수가 여러 개 있고 그 중 숫자로 끝납니다. ("질문 1") 각 변수에 질문이 있습니다 ("E가 몇 번이나 나옵니까?") 무대에 사용자가 입력하는 편집 가능한 텍스트 상자가있어서 질문 번호를 다른 텍스트 상자. ("1") 사용자가 단추를 클릭 할 때 질문 1 텍스트가 텍스트 상자에 표시되어야합니다. 내 코드는 다음과 같습니다두 변수의 내용을 병합하는 방법
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이 질문의 실제 텍스트를 표시 얻을 수 있습니까 ?? (내가 가진 코드는 지금 분명 !! 작동하지 않습니다)
그러나이 예제가 제대로 작동 나던 : 나는 질문라는 클래스를 생성하고 여기에 코드입니다 :
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"
}
왜? ?
this["Question" + QuestionNumber.toString()]
가 동적 설정이 연산자를 사용하여 오브젝트의 속성에 대한 값을 검색 할 수
감사합니다. 매우 명확한!! – user2434923