Skip to content

Instantly share code, notes, and snippets.

@aolba
Created December 4, 2013 19:38
Show Gist options
  • Save aolba/7794111 to your computer and use it in GitHub Desktop.
Save aolba/7794111 to your computer and use it in GitHub Desktop.
load cml
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.display.Loader;
private var myXML:XML;
// pass the path to the xml, and the function to execute once it's loaded
private function loadXML (path:String, nextFunc:Function):void
{
var loader:URLLoader = new URLLoader ();
var req:URLRequest = new URLRequest (path);
loader.addEventListener (ProgressEvent.PROGRESS, progressHandler, false, 0, true);
loader.addEventListener (Event.COMPLETE, nextFunc, false, 0, true);
loader.load (req);
}
private function progressHandler (evt:Event):void
{
var percent:Number = evt.currentTarget.bytesLoaded / evt.currentTarget.bytesTotal;
trace (percent);
}
// the COMPLETE function that executes when the file is laoded
private function myXMLLoaded (evt:Event):void
{
myXML = new XML(evt.target.data);
// myXML.item[0]
}
// call the file to load and the COMPLETE function for when its done
loadXML ("myFile.xml", myXMLLoaded);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment