Tips: How To Get The SWF Path In ActionScript 3

presentblue-icon 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:

  1. this.stage.loaderInfo.url
  2.  
  3. var doMain:String = this.stage.loaderInfo.url;
  4. var doMainArray:Array = doMain.split("/");
  5. if (doMainArray[0] == "file:") {
  6. trace("Local debug mode.");
  7. }else{
  8. trace("Web host mode");
  9. }

Source code 2:

  1. import flash.external.ExternalInterface;
  2. //Method 1
  3. var urlPath = ExternalInterface.call("window.location.href.toString");
  4. //Method 2
  5. var urlPath = loaderInfo.url;

If you want to get the path of the HTML hosting the SWF, you can simply get it like:

  1. import flash.external.ExternalInterface;
  2. var full:String = ExternalInterface.call("window.location.href.toString");

Enjoy!

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • Reddit
  • Technorati
  • StumbleUpon
  • Twitter
RSS Enjoy this Post? Subscribe to Ntt.cc

RSS Feed   RSS Feed     Email Feed  Email Feed
You can leave a response, or trackback from your own site.

One Response to “Tips: How To Get The SWF Path In ActionScript 3”

  1. Eric Holm says:

    This works for me:

    trace(loaderInfo.url);

Leave a Reply