Jump to content

- - - - -

Flash XML Loader class

  • Please log in to reply
No replies to this topic

#1 curthard89


    Young Padawan

  • Members
  • Pip
  • 226 posts

Posted 17 December 2007 - 06:35 PM

yo guys, not really a tutorial but a script i might aswell share that i created some time ago,

this is a xml loader class for use with as2.

import mx.utils.Delegate;
import mx.display.*;
import mx.events.*;
import mx.utils.*;

class mwm.data.xmlData extends EventDispatcher
	private static var XML_AR_ARRAY:Array;
	private static var XML_DATA_TRUE:Boolean;
	private static var XML_DATA_ARRAY:Array;
	public var xmlArray:Array;
	private var xm;
	public var dispatchEvent:Function;
	public var addEventListener:Function;
	public var removeEventListener:Function;
	function xmlData() {
	function load(file) {
		XML_DATA_ARRAY = new Array();
		var thisObj:xmlData = this;
		xm = new XML();
		XML_DATA_ARRAY = new Array();			
		xm.ignoreWhite = true;
		xm.onLoad = Delegate.create(this, runEvent);
	function runEvent(loaded:Boolean) {
		var full_arr = xm.firstChild.childNodes; 
		var len:Number = full_arr.length-1;
		for(var i:Number=0;i<=len;i++){
			XML_AR_ARRAY = new Array();
			for(var a:Number=0;a<=full_arr[i].childNodes.length-1;a++){
				var st =  full_arr[i].childNodes[a].firstChild.nodeValue;
			xmlArray = XML_DATA_ARRAY;

to use this class, u must change the mwm.data on the class name line to the path that it is it from the flash file keeping xmlData on the end.

then import it into the flash doc,

and the actionscript to use is

for example

var something:xmlData = new xmlData();
var somethingObj = new Object();
somethingObj.onLoad = function() {
once xml loaded, do my stuff in here

hope it helps with lengthy process of xml loading, this also supports multiple xml sheets per flash movie :yodasearch:

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users