title: Convert a Relative URL to an Absolute URL in Actionscript / Flex
body: <p>I am working with Flex, and I need to take a relative URL source property and convert it to an absolute URL before loading it.</p>
  
  <p>The specific case I am working with involves tweaking SoundEffect's load method. I need to determine if a file will be loaded from the local file system or over the network from looking at the source property, and the easiest way I've found to do this is to generate the absolute URL.</p>
  
  <p>I'm having trouble generating the absolute URL for sound effect in particular. Here were my initial thoughts, which haven't worked.</p>
  
  <ol>
  <li><p>Look for the DisplayObject that the Sound Effect targets, and use its loaderInfo property. The target is null when the SoundEffect loads, so this doesn't work.</p></li>
  <li><p>Look at FlexGlobals.topLevelApplication, at the url or loaderInfo properties. Neither of these are set, however.</p></li>
  <li><p>Look at the FlexGlobals.topLevelApplication.systemManager.loaderInfo. This was also not set.</p></li>
  </ol>
  
  <p>The SoundEffect.as code basically boils down to</p>
  
  <pre><code>var url:String = "mySound.mp3";
  /*&gt;&gt; I'd like to convert the URL to absolute form here and tweak it as necessary &lt;&lt;*/
  var req:URLRequest = new URLRequest(url);
  var loader:Loader = new Loader();
  loader.load(req);
  </code></pre>
  
  <p>Does anyone know how to do this? Any help clarifying the rules of how relative urls are resolved for URLRequests in ActionScript would also be much appreciated.</p>
  
  <p><code>edit</code>
  I would also be perfectly satisfied with some way to tell whether the url will be loaded from the local file system or over the network. Looking at an absolute URL it would just be easy to look at the prefix, like <code>file://</code> or <code>http://</code>.</p>