ActionScript 3 XML加载器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 XML加载器相关的知识,希望对你有一定的参考价值。

import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.HTTPStatusEvent;
	import flash.events.IEventDispatcher;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	import flash.events.SecurityErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLRequest;

var dataXML:XML;
var path = "test.xml";
var xmlRequest:URLRequest = new URLRequest(path);
var xmlLoader:URLLoader = new URLLoader()
xmlLoader.dataFormat = URLLoaderDataFormat.TEXT;
configXmlLoaderListeners(xmlLoader);
xmlLoader.load(xmlRequest);



//---------------------------------
//
// Listeners
//
//--------------------------------

function configXmlLoaderListeners(dispatcher:IEventDispatcher):void {
	dispatcher.addEventListener(Event.COMPLETE, xmlCompleteHandler);
	dispatcher.addEventListener(Event.OPEN, xmlOpenHandler);
	dispatcher.addEventListener(ProgressEvent.PROGRESS, xmlProgressHandler);
	dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, xmlSecurityErrorHandler);
	dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, xmlHttpStatusHandler);
	dispatcher.addEventListener(IOErrorEvent.IO_ERROR, xmlIoErrorHandler);
}

function xmlCompleteHandler(event:Event):void {
	var loader:URLLoader = URLLoader(event.target);
	//trace("completeHandler: " + loader.data);

	 try{
        dataXML = new XML(event.target.data)
		//trace("dataXML " + dataXML);
		
		gotoAndStop("build menu");
		
    } catch (error:TypeError){
        trace("Could not parse the XML")
        trace(error.message)
    }
}


// Optional listeners

function xmlOpenHandler(event:Event):void {
	trace("openHandler: " + event);
}

function xmlProgressHandler(event:ProgressEvent):void {
	trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
}

function xmlSecurityErrorHandler(event:SecurityErrorEvent):void {
	trace("securityErrorHandler: " + event);
}

function xmlHttpStatusHandler(event:HTTPStatusEvent):void {
	trace("httpStatusHandler: " + event);
}

function xmlIoErrorHandler(event:IOErrorEvent):void {
	trace("ioErrorHandler: " + event);
}

以上是关于ActionScript 3 XML加载器的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript 3 XML加载器

ActionScript 3 XML管理器类

ActionScript 3 加载xml

ActionScript 3 加载xml

ActionScript 3 AS3:XML加载

ActionScript 3 加载多个XML文件