【发布时间】:2012-04-04 02:17:31
【问题描述】:
我还有另一个问题源于这个先前提出的问题: XML - targeting node attribute, push into a Flash AS3 array。我被告知要问一个新问题而不是更新旧问题。
这是我的 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>
这是我用来从 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 中的任何地方访问它们的方法。请记住,每个问题都有两个答案。即:
真' weight='0'/ >
False' weight='1'/ >
【问题讨论】:
标签: xml actionscript-3 flash