0 Replies - 1044 Views - Last Post: 20 April 2009 - 02:54 PM

#1 skater_00  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 12
  • View blog
  • Posts: 256
  • Joined: 30-April 08

XMLParser

Posted 20 April 2009 - 02:54 PM

Description: Parsing external XML files in your projects.
/* ----------------- */
/* ActionScript File */
/* ----------------- */

package net.dreamincode.as3
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.net.URLLoader;
	import flash.net.URLRequest;

	public class XMLParser extends EventDispatcher
	{
		/* --- Constructor --- */
		public function XMLParser(target:IEventDispatcher = null):void
		{
			super(target);
		}
		
		/* --- Properties --- */
		public var dataXML:XML;
		public static const XML_PARSED:String = "xml parsed";
		
		/* --- Methods --- */
		public function parseXML(xml:String):void
		{
			var xmlLoader:URLLoader = new URLLoader();
			xmlLoader.addEventListener(Event.COMPLETE, completeHandler);
			xmlLoader.load(new URLRequest(xml));
		}
		
		private function completeHandler(event:Event):void
		{
			dataXML = new XML(event.target.data);
			this.dispatchEvent(new Event(XMLParser.XML_PARSED));
		}
	}
}

/* ---------- */
/* Main Class */
/* ---------- */

var xmlParser:XMLParser = new XMLParser();
xmlParser.addEventListener(XMLParser.XML_PARSED, xmlParsedHandler);
xmlParser.parseXML("assets/data.xml");


Is This A Good Question/Topic? 0
  • +

Page 1 of 1