Reputation: 892
I would like to get the absolute path of my swf file from within Actionscript.
E.g. if the script called "http://www.mysite.com/banner/flash.swf" I'd expect "/banner"
In PHP I would do:
$fpath = str_replace('\\', '/', dirname(__FILE__));
$path = str_replace($_SERVER['DOCUMENT_ROOT'], '', $fpath);
How can I do this in Actionscript?
Upvotes: 0
Views: 2380
Reputation: 9055
I use this function in the top most class (the one that extends Sprite for AS3 projects or mx:Application for Flex projects).
private function GetURLParts():Object
{
var urlPattern:RegExp = /([\w]+):\/\/([\w\._-]+)+(\S+)*(\?\S+)?/;
var result:Array = urlPattern.exec(loaderInfo.loaderURL);
var parts:Object =
{
'protocol': result[1],
'domain': result[2],
'path': result[3]
};
return parts;
}
You could probably modify this to fit your needs.
Upvotes: 2