的&QUOT持续的传奇; XML - 瞄准节点属性,推到Flash AS3阵列"阵列、节点、推到、属性

2023-09-09 21:50:58 作者:上了膛的枪

我即源于此previously问的一个问题一个问题: XML - 针对节点属性,推到Flash AS3阵列。有人告诉我,提出新问题,而不是更新旧的。

I have another question that stems from this previously asked question: XML - targeting node attribute, push into a Flash AS3 array. I was told to ask a new question rather than update the old one.

下面是我的XML文件的摘录。 (这是正确的格式,并且具有根节点等,但太长张贴了整个事情。下面就是我关心的部分。

Here is an excerpt of my XML file. (It is properly formatted, and has a root node, etc., but is too long to post the entire thing. Below is just the part I am concerned with.

<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 在问题属性标记。

This is what i am using to obtain the txt attribute from the question tag.

//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的长度的单独帧

Below is a function is on a separate frame that extends the length of the 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属性来填充动态文本:

Referencing that function, I then use this to target a specific txt attribute to populate a dynamic textfield:

question1_mc.question_txt.htmlText = "<b>Question 1: </b><br>"+ getQuestionAt(1);

我现在需要的是一种能够抓住从答案标签txt的属性值,并可以从任何地方访问他们在FLA。请记住,有两个答案的每一个问题。即:

What I now need is a way to grab the txt attribute value from the answer tags and be able to access them from anywhere in the fla. Keep in mind that there are two answers for every question. ie:

&LT;解答ID ='Q1A1'UID ='311288'的txt ='真重量=0/> &LT;解答ID ='Q1A2'UID ='311289'的txt ='假重量=1/>

< answer id='Q1A1' uId='311288' txt='True' weight='0'/ > < answer id='Q1A2' uId='311289' txt='False' weight='1'/ >

推荐答案

我觉得有一个更简单的方式来做到这一点。而不是在加载XML和存储您的问题一个对象,只是引用XML对象。该XML已经是一个对象,所以没有理由去分析它到另一个对象。此外,你就可以拉你所需要的,因为你需要它的信息。以下是我建议做这样的:

I think there's an easier way to do this. Rather than loading the XML and storing your questions in an Object, just reference the XML Object. The XML is already an Object, so there's no reason to parse it into another Object. Plus, you'll be able to pull all the information you need as you need it. Here's how I would suggest doing this:

var myXML:XML;

var myLoader:URLLoader = new URLLoader();
myLoader.addEventListener(Event.COMPLETE, complete);
myLoader.load(new URLRequest("html/BlahBlah/manifest.xml"));

function complete(e:Event):void {
    myLoader.removeEventListener(Event.COMPLETE, complete);
    myXML = new XML(e.target.data);

    //Data for question 1
    trace(getQuestionByIndex(1).@txt); // Question
    for each (var o:Object in getAnswersByQuestionIndex(1)) {
        trace(o.@txt); // Answers
    }
}

function getQuestionByIndex(index:int):XMLList {
    return myXML.question.(@id=="Q"+index);
}

function getAnswersByQuestionIndex(index:int):XMLList {
    return getQuestionByIndex(index).answer;
}