各 "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);
}
これは単なる配列の各位置に一度に全ての質問9をプッシュ:
<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つの質問が必要でした。質問タグのid属性を使用して各質問を区別する方法がわかりません。
EDIT:私はこれを試してみましたが、私はprocessXML関数内からではなく、それ以外でgetQuestionAt(2)を使用して質問テキストにアクセスすることができます。
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));
}
? フレーム6に** text_txt.htmlText = getQuestionAt(2); **というテキストフィールドを設定しようとしましたが、動作しません。 – Livi17
新しいレイヤーを作成します。新しいレイヤーは1つのフレームだけを作成し、そのフレームの長さは、フレーム全体の長さにします(たとえば6を長くします)。そのフレームにASコードを追加します。その場合、すべてのフレームで「可視」なので、関数を任意のフレームで呼び出すことができます。 – Engineer
私はあなたの提案を試みましたが、まだ動作しません...あなたのコードを** processXML()**関数の中に入れているからですか?上記の私の編集を参照してください。それは関数内では動作しますが、外部ではなく、flaのどこからでも動作します。 – Livi17