Is there a easy / good way of getting the url from the URLLoader object? It seems at least two other people (this guy and this this guy) have wondered the same thing. Maybe we can get an answer here on s.o.?
+2
A:
package
{
import flash.net.URLLoader;
import flash.net.URLRequest;
public dynamic class urlURLLoader extends URLLoader
{
private var _req:URLRequest;
public function urlURLLoader( request:flash.net.URLRequest = null ):void
{ super( request );
_req = request;
}
public override function load( request:flash.net.URLRequest ):void
{ _req = request;
super.load( request );
}
public function get urlRequest( ):URLRequest
{ return _req;
}
}
jedierikb
2009-07-31 22:15:39
+1
A:
Thats a nice approach. The reverse approach would be to wrap your URLLoader in a class and store the info there, if you want the requesting class to be informed that a load completed and which url was successfully loaded.
You would access it something like,
customLoader.url="http://.....";
customLoader.onLoadDelegate = this;
customLoader.load();
and wait for a callback in
public function customLoaderComplete(url:String, data:[Object or whatever you set]) {
}
in the customLoader class you store the url and delegate
private var url:String;
private var onLoadDelegate:Object;
public function set url(_url:String):void {
url = _url;
}
public function set onLoadDelegate(_onLoadDelegate:Object):void {
onLoadDelegate = _onLoadDelegate;
}
then you create the request, URLLoader etc, and set the Event.COMPLETE listener to trigger a function which reports back to the delegate
public function dataLoaded(event:Event):void {
.. parse event.target.data if needed...
onLoadDelegate.customLoaderComplete(url, data);
}
If you take it a step further the top level "request issuing" class can adhere to an interface/extend a base class so you don't have to use anonymous objects.
Michael
2009-08-01 03:38:12