/**************************************************************** TextLoader class Flashscript.biz 2008 *****************************************************************/ package biz.Flashscript.utils { import flash.events.*; import flash.system.Capabilities; import flash.net.*; import biz.Flashscript.utils.PassParameters; // public class TextLoader { // // for xml // private var txtLoader:URLLoader; // public function TextLoader () { } // // loading XML files // public function initText (textFile:String,loadParse:Function,myCache:Boolean=false,aNum:Object=null,bStr:Object=null,cBool:Object=null):void { var URL:String=textFile; /* // in order to prevent caching of an XML file we add these lines to make the URL unique. // However, the browser will recognize. */ if (myCache) { if (Capabilities.playerType != "External" && Capabilities.playerType != "Standalone") { URL+= "?" + new Date + Math.floor(Math.random() * 10000); } } // // the original or modified url will be processed. // var request:URLRequest=new URLRequest(URL); txtLoader=new URLLoader ; txtLoader.addEventListener (IOErrorEvent.IO_ERROR,ifFailed); txtLoader.addEventListener (HTTPStatusEvent.HTTP_STATUS,httpStatus); /* We pass on when the event is complete. This also allows to pass on parameters. However, do not forget to cast the variables for the parameters for further use, since they are of datatype object. */ txtLoader.addEventListener (ProgressEvent.PROGRESS, progressHandler); txtLoader.addEventListener(Event.COMPLETE, PassParameters.addArguments(loadParse, [aNum,bStr,cBool])); // // if the url calls an XML file from a foreign domain, proxy will be "true". // request.method=URLRequestMethod.POST; txtLoader.load (request); } private function progressHandler (event:ProgressEvent):void { trace ("bytesLoaded=" + event.target.bytesLoaded + " bytesTotal=" + event.target.bytesTotal); } // // error handler // private function ifFailed (event:IOErrorEvent):void { trace ("ioErrorHandler: " + event); } // // http status handler: This will give a trace when the xml is loaded // private function httpStatus (event:HTTPStatusEvent):void { trace ("status: " + event.status); } } }