각 "question"태그의 "txt"속성의 내용을 AS3 Flash의 "questions"라는 배열로 푸시하려고합니다. 다음은 내 XML 파일에서 발췌 한 것입니다.XML - 대상 노드 속성, Flash AS3 배열로 푸시
// get number of questions
trace(myXML.question.length());
numberOfQuestions = myXML.question.length();
//loop and push questions into questions array at top
for (var i:int = 0; i < numberOfQuestions; i++) {
trace("Hello.");
questions.push([email protected]);
trace(questions);
}
이 단지 배열의 각 위치에 한 번에 모든 질문에 구를 밀어 :
<question id='Q1' uId='99036' no_ans='2' txt='In a flat structure employees are not expected to provide their bosses with their opinions.' feedback='' type='MC' passingWeight='1' url='media/'>
<answer id='Q1A1' uId='311288' txt='True' weight='0'/>
<answer id='Q1A2' uId='311289' txt='False' weight='1'/>
</question>
<question id='Q2' uId='99037' no_ans='2' txt='In a hierarchy, information typically flows downward.' feedback='' type='MC' passingWeight='1' url='media/'>
<answer id='Q2A1' uId='311290' txt='True' weight='1'/>
<answer id='Q2A2' uId='311291' txt='False' weight='0'/>
</question>
<question id='Q3' uId='99038' no_ans='2' txt='Someone who keeps many projects going at one time is an example of someone who is flexible-time oriented.' feedback='' type='MC' passingWeight='1' url='media/'>
<answer id='Q3A1' uId='311292' txt='True' weight='1'/>
<answer id='Q3A2' uId='311293' txt='False' weight='0'/>
</question>
여기에 루프에서 내 시도이다. 나는 배열 위치 당 1 개의 질문을 원했다. 각 질문을 구별하기 위해 question 태그의 id 속성을 사용하는 방법을 잘 모르겠습니다.
편집
:하지만 외부 그것의, 나는이 시도 및 I (2) processXML 함수 내에서 getQuestionAt를 사용하여 질문 텍스트를 액세스 할 수 있습니다.var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("html/VUBZ7318CROSSCULTUREQUIZ/manifest.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void {
myXML = new XML(e.target.data);
//trace(myXML.question)
// get number of questions
trace(myXML.question.length());
numberOfQuestions = myXML.question.length();
//Question list
var questions:Object = {};
//Extracting question from xml
for each (var item:XML in myXML.question) {
questions[item. @ id] = item. @ txt;
}
//Some method for fetching question from question list
function getQuestionAt(index:Number):String {
if (questions["Q" + index] == undefined) {
throw new Error("Wrong index for question!!!");
}
return questions["Q"+index];
}
//Getting question from list
trace("Here is question No 2:\t" + getQuestionAt(2));
}
가 어떻게이 FLA에 다른 프레임에서 질문 중 하나에 액세스합니까? 프레임 6에 ** text_txt.htmlText = getQuestionAt (2); **가있는 텍스트 필드를 채우려고했으나 작동하지 않습니다. – Livi17
하나의 프레임 만있는 새 레이어를 만들고 전체 프레임 (예 : 6 초) 동안 해당 프레임의 길이를 만듭니다. 그런 다음 해당 프레임에 AS 코드를 추가하십시오. 이 경우 모든 프레임에서 '표시'되어 모든 프레임에서 함수를 호출 할 수 있습니다. – Engineer
당신의 제안을 시도했지만 여전히 작동하지 않습니다 ... 당신의 코드를 ** processXML() ** 함수 안에 넣었습니까? 위의 편집을 참조하십시오. 그것은 함수 내부에서 작동하지만, 외부에서 또는 fla의 다른 곳에서는 작동하지 않습니다. – Livi17