English 中文(简体)
如何在AS3中加载xml数据并在多个帧中显示它
原标题:How to load xml data and present it across multiple frames in AS3

我试图从xml文件加载数据,将它们加载到数组中,并在动态文本字段的不同帧中显示这些数组中的单词。例如,DynText文本字段中的两个帧将显示WordArray[0]。在此演示之后,WordArray[1]将在同一文本字段中的四个帧中显示,然后KeyWordArray[0]将在相同文本字段中显示一个帧,以此类推。

这是我到目前为止的代码:

var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("file2.xml"));

function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
ParsePass(xmlData);
}

var WordArray:Array = new Array();
var KeyWordArray:Array = new Array();

function ParsePass(passInput:XML):void {
var WordAll:XMLList = passInput.Pass.Word.text();
var PrimeAll:XMLList = passInput.Pass.Keyword.text();

for (var i in WordAll) {
    WordArray.push(WordAll[i]);
}
for (var p in PrimeAll) {
    KeyWordArray.push(PrimeAll[p]);
}

}

我能够加载xml数据,将其放入数组中,并使用以下命令在动态文本字段的第一帧中显示WordArray[0]:

DynText.text = WordArray[0];

but not in the other frames. I have tried to call functions within the ParsePass function, but it does not seem to work. I am sorry if this is a basic question. I am new to AS3. But I have searched the web and did not find any relevant answer to my question. So any help would be very appreciated.

最佳回答

在此处阅读XML解析:XML基础知识

要在帧上添加各种数据,请尝试使用addFrameScript()

You can add code to specific frame to load data to a container which is located on that frame. Or another solution would be to use the same container on all the frames but load data dynamically depending on the frame number.

编辑:

MyMC.addEventListener(Event.ENTER_FRAME, OnEnterFrameHandler);
function OnEnterFrameHandler(e:Event):void
{
   switch(e.target.currentFrame)
   {
       case 1: TextBox.text = WordArray[0];
               break;
       case 3: TextBox.text = WordArray[1];
               break;
       case 5: TextBox.text = WordArray[2];
               break;
   }
}

还要注意,在Flash中,帧枚举从1开始,并确保使用stop()方法在需要的帧上停止MovieClip。

问题回答

暂无回答




相关问题
how to represent it in dtd?

I have two element action and guid. guid is a required field when action is add. but when action is del it will not appear in file. How to represent this in dtd ?

.Net application configuration add xml-data

I need to add xml-content to my application configuration file. Is there a way to add it directly to the appSettings section or do I need to implement a configSection? Is it possible to add the xml ...

XStream serializing collections

I have a class structure that I would like to serialize with Xstream. The root class contains a collection of other objects (of varying types). I would like to only serialize part of the objects that ...

MS Word splits words in its XML format

I have a Word 2003 document saved as a XML in WordProcessingML format. It contains few placeholders which will be dynamically replaced by an appropriate content. But, the problem is that Word ...

Merging an XML file with a list of changes

I have two XML files that are generated by another application I have no control over. The first is a settings file, and the second is a list of changes that should be applied to the first. Main ...

How do I check if a node has no siblings?

I have a org.w3c.dom.Node object. I would like to see if it has any other siblings. Here s what I have tried: Node sibling = node.getNextSibling(); if(sibling == null) return true; else ...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

热门标签