Created
December 4, 2013 19:38
-
-
Save aolba/7794111 to your computer and use it in GitHub Desktop.
load cml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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