Relative Path Gotcha
If you have an html page which into which is loaded a swf that resides in a sub-directory, which itself loads in swfs then you may come across the relative path gotcha. As the name implies, this will happen only if you specify the names of your assets relatively, but I consider this to be the default state since I do not develop applications onto the web directly, and my testing urls are different to my publication urls.
The problem is caused by the relative url in the document swf being interpreted as relative to the html page’s folder, not relative to the document swf’s folder. The solution is to reference the document swf’s folder in the URLRequest, as follows:
/**
* @return The folder in which the document swf is found
*/
public function get documentFolder():String
{
var url:String = root.loaderInfo.url;
return url.substr(0, url.lastIndexOf("/") + 1);
}
This code references the root swf’s loaderInfo and extracts its folder path. The asset swf’s url can then be accessed using
var request:URLRequest; request = new URLRequest(documentFolder + "relative/path/to/asset.swf");
-
http://alecmce.com Anonymous
-
http://alecmce.com Alec McEachran
-
Na
-
Na


