Opening files and URLs

URL

URL

I don’t know about you, but I really hate those little bits of code that you will use in every single game but not during the actual development of it. As far as I’m concerned, even if not the most noble usage of the “reuse your code” rule, getting rid of these pesky little pieces of code is the single most useful usage of object oriented programming, not because I read it somewhere but because I’ll never have to worry about it again!

Opening files and URLs are two examples those pesky bits of code and to me both are perfect candidates to our framework Toolkit class! So here’s the code of the two static functions that were created to deal with it.

/*Opens an external file. Upon completing the task, callbacks to the
 *given function.*/
public static function OpenFile(filename:String, callback:Function)
{
	var ldr:URLLoader = new URLLoader();
 
	ldr.load(new URLRequest(filename));
	ldr.addEventListener(Event.COMPLETE, callback);
}
 
/*Opens a URL on a new window.*/
public static function OpenURL(url:String)
{
	var urlReq:URLRequest = new URLRequest(url);
	navigateToURL(urlReq, "_blank");
}

Posted: March 11th, 2009
at 12:00am by Vlad

Tagged with ,


Categories: The code of VGS

Comments: No comments