Sometimes we need to get the swf path in our flex/flash project, it can be done with _root._url in actionscript 2, but _root not work in actionscript 3. How to get the swf path in as 3? The following is 2 ways on how to get it.
Hope it will be useful for you.
Source code 1:
- this.stage.loaderInfo.url
- var doMain:String = this.stage.loaderInfo.url;
- var doMainArray:Array = doMain.split("/");
- if (doMainArray[0] == "file:") {
- trace("Local debug mode.");
- }else{
- trace("Web host mode");
- }
Source code 2:
- import flash.external.ExternalInterface;
- //Method 1
- var urlPath = ExternalInterface.call("window.location.href.toString");
- //Method 2
- var urlPath = loaderInfo.url;
If you want to get the path of the HTML hosting the SWF, you can simply get it like:
- import flash.external.ExternalInterface;
- var full:String = ExternalInterface.call("window.location.href.toString");
Enjoy!

December 12th, 2009
Ntt.cc 








Posted in
Tags: 
RSS Feed
Email Feed
This works for me:
trace(loaderInfo.url);