我还有一个问题源于此前提出的问题: XML - targeting node attribute, push into a Flash AS3 array。我被告知要问一个新问题,而不是更新旧问题。“XML - 针对节点属性,推入Flash AS3阵列”的持续传奇
这是我的XML文件的摘录。 (这是正确的格式,并且具有根节点等,但过长后整个事情。下面就是我所关心的部分。
<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>
这是我使用获得什么所述TXT属性从问题标签。
//load the xml
var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("html/BlahBlah/manifest.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void {
myXML = new XML(e.target.data);
trace(myXML.*);
//.....Your 'myXML' is here....
questions = {};
//Extracting question from xml
for each (var item:XML in myXML.question) {
questions[item. @ id] = item. @ txt;
}
}
下面是一个功能是在延伸的FLA的长度的单独的帧。
//Question list
var questions:Object;
//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];
}
引用该功能,然后我用它来针对特定的txt属性来填充动态文本:
question1_mc.question_txt.htmlText = "<b>Question 1: </b><br>"+ getQuestionAt(1);
我现在需要的是一种方法,抓住从答案标签TXT属性值,并能从fla的任何地方访问它们。请记住,每个问题都有两个答案。即:
<答案ID = 'Q1A1' UID = '311288' 的txt = '真 '重量=' 0 '/>
<答案ID =' Q1A2' UID = '311289' 的txt =' False'weight ='1'/>
跟踪输出在第一帧上工作正常。如何在下面的框架6上填充3个文本框? ** question1_txt.htmlText =? answer1_txt.htmlText =? answer2_txt.htmlText =?** – Livi17 2012-03-19 16:41:24
如果你在第一帧定义你的函数并在你进步之前加载你的xml,那么你应该可以调用相同的函数。 question1_txt.htmlText = getQuestionByIndex(1)。@ txt and answer1_txt.htmlText = getAnswersByQuestionIndex(1)[0]。@ txt – Corey 2012-03-19 16:58:09
感谢Corey,这是完美的工作! – Livi17 2012-03-19 17:06:17