ActionScript 3 基本的外部XML加载器
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 基本的外部XML加载器相关的知识,希望对你有一定的参考价值。
package
{
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.IOErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
/**
* ...
* @author ...
*/
public class LoadXML extends EventDispatcher
{
private var data:XML;
private var loader:URLLoader;
public function LoadXML(path:String)
{
loader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
loader.load(new URLRequest(path));
}
//---------------------------------------------------------------------------------------
private function onComplete(event:Event):void
{
try
{
data = new XML(event.target.data);
loader.removeEventListener(Event.COMPLETE, onComplete);
loader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
dispatchEvent(new Event(Event.COMPLETE));
}
catch (error:Error)
{
trace("Could not load XML: " + error);
}
}
//---------------------------------------------------------------------------------------
private function onIOError(event:IOErrorEvent):void
{
trace("An error occured trying to load the XML: " + event.text);
}
//---------------------------------------------------------------------------------------
public function getXML():XML
{
return data;
}
//---------------------------------------------------------------------------------------
}
}
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
//ADD THIS TO THE TIMELINE
import flash.events.Event;
var n:LoadXML = new LoadXML("data.xml");
var xml:XML;
n.addEventListener(Event.COMPLETE, onComplete);
function onComplete(event:Event):void
{
xml = n.getXML();
}
以上是关于ActionScript 3 基本的外部XML加载器的主要内容,如果未能解决你的问题,请参考以下文章
[ActionScript 3.0] as3处理xml的功能和遍历节点
ActionScript 3 外部文件的加载方法
ActionScript 3 加载外部
ActionScript 3 从其他域加载外部swf
ActionScript 3 用于加载和预加载外部闪存或图像的通用类
ActionScript 3 从外部加载的图像中获取位图数据。