Loading XML with ActionScript and Arbol Negro

One of the most common task in actionscript in loading XML, it is the native way to load complex data; but there is a time when this process become a little anoying, because as you remember, in as2, load XML was just a couple of lines; in as3 is not that hard, but there are a couple of separate steps to load it and it’s sometimes confusing for begginers.

I have created XMLHandler to carry on those repetitions to “the easy way”, here is an example:

import flash.display.MovieClip;
import flash.events.Event;
import flash.events.ProgressEvent;
import net.absulit.arbolnegro.data.XMLHandler;
* ...
* @author Sebastián Sanabria Díaz
public class Main extends MovieClip

private var _xmlHandler:XMLHandler
public function Main()
_xmlHandler = new XMLHandler();
_xmlHandler.addEventListener(Event.COMPLETE, onCompleteXMLHandler);
_xmlHandler.addEventListener(ProgressEvent.PROGRESS, onProgressEvent);
_xmlHandler.path = "data.xml";

private function onProgressEvent(e:ProgressEvent):void
trace(e.bytesLoaded / e.bytesTotal);

private function onCompleteXMLHandler(e:Event):void
e.target.removeEventListener(Event.COMPLETE, onCompleteXMLHandler);
//trace(e.target.xml);//using event parameter
trace(_xmlHandler.xml);//using the private var



This is a very simple example, loads XML, traces it, also shows its progress, which in a bigger XML file will be more useful.

Download example files:


One Response to “Loading XML with ActionScript and Arbol Negro

  1. […] This post was mentioned on Twitter by Sebastian Sanabria, Arbol Negro Dev Team. Arbol Negro Dev Team said: Loading XML with actionscript and #ArbolNegro http://bit.ly/dhNKXn #as3 #flash #flashdev […]

Leave a Reply


= 3 + 3

Switch to our mobile site