如何加载XML数据和present它横跨在AS3多帧 [英] How to load xml data and present it across multiple frames in AS3

查看:135
本文介绍了如何加载XML数据和present它横跨在AS3多帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从XML文件加载数据,加载它们从这些阵列在不同的帧阵列和present词语的动态文本字段。因此,例如,WordArray [0]将是psented在DynText文本框的两帧$ P $。以下这个presentation,WordArray [1]将psented在同一文本字段四帧和$ P $然后KeyWordArray [0]将是psented在同一文本字段等一帧$ P $

I'm trying to load data from an xml file, load them in arrays and present words from these arrays in different frames in a dynamic text field. So for example, WordArray[0] will be presented for two frames in the DynText textfield. Following this presentation, WordArray[1] will be presented for four frames in the same text field and then KeyWordArray[0] will be presented for one frame in the same text field, etc.

下面是code我到目前为止有:

Here is the code I have so far:

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数据,把它放在数组和present WordArray [0]在使用动态文本字段的第一帧:

I am able to load the xml data, put it in arrays and present WordArray[0] in the first frame in a dynamic text field using:

DynText.text = WordArray[0];

,但不是在其他帧。我试图在ParsePass函数中调用的功能,但它似乎并没有工作。 我很抱歉,如果这是一个基本的问题。我是新来的AS3。但我在网上搜索,并没有发现任何相关的回答我的问题。因此,任何帮助将是非常美联社preciated。

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基础

Read about parsing XML here: XML Basics

有关上添加帧尝试使用 addFrameScript()的各种数据;

For adding various data on frames try using addFrameScript();

您可以添加code到特定的帧数据加载到一个容器位于该帧。 或另一种解决办法是将动态地使用上所有帧的同一容器中,但将数据加载根据帧号

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()方法。

Also note that in Flash frame enumeration starts from 1 and make sure you stop the MovieClip on the frame you need, using the stop() method.

这篇关于如何加载XML数据和present它横跨在AS3多帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆