The URL of the Adobe Air URL returning the server at runtime
I am not familiar with Adobe Air and I am uploading a file to a server. For simple testing purposes, I have a hardcoded download url (specifically the url of the download directory on the server pointed to by the amf channel) into code. Is there a way in adobe air to get the server url at runtime?
Or does the question make no sense at all because there is a better way to do it?
It looks to me like you want the download url to be dynamic. In this case, you can use many methods to obtain such data at runtime. I would use XML if I were you, and I will illustrate how to do it in the following.
//THE XML - Place in same folder as the FLA and name setup.xml
<?XML version="1.0" encoding="utf-8"?>
<xml>
<upload url="path/to/file" />
</xml>
Now a very simple XML file, it can also easily include background music information, CDATA-packed CSS text, or any other type of data you would like to store and retrieve.
//The ActionScript 3.0
package
{
import flash.display.Sprite;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
public class TestDocClass extends Sprite
{
private var _xml:XML;
private var _xmlLoader:URLLoader;
private var _xmlRequest:URLRequest;
public function TestDocClass():void
{
_xmlLoader = new URLLoader();
_xmlRequest = new URLRequest('setup.xml');
_xmlLoader.addEventListener(Event.COMPLETE, onXMLComplete, false, 0, true);
_xmlLoader.load(_xmlRequest);
}
private function onXMLComplete(e:Event):void
{
_xmlLoader.removeEventListener(Event.COMPLETE, onXMLComplete, false);
//Create the XML object and insert the data.
_xml = new XML(e.target.data);
//Now to access the upload line we use its Namespace of "upload"
//The @ symbol specifies we are retrieving an attribute.
trace(_xml.upload.@url);
}
}
}
That way, wherever you need this load clause, you just call _xml.upload.@url
, or you can set a variable to that value when the data is received ( var uploadURL:String = _xml.upload.@url
).
source to share