Is This swf Online?

Actionscript:
  1. private var _correctPath:String;
  2.  
  3. //.... somewhere a little later
  4.  
  5.  if (root.loaderInfo.url.split("http://").length == 1){
  6.         _correctPath = "http://www.mywebsite.com/this/is/an/absolute/path/";
  7.     }else{
  8.         _correctPath = "";
  9.     }

I like to do something like this when I'm working locally... it automatically tells my swf to use an absolute path for php files, xml files etc.... then, when I upload it, the LoaderInfo.url property contains an "http://" so it uses a relative path for all the external files. This is common especially if you don't have php and mysql installed on your machine and need to test these using your server.

This entry was posted in misc and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

4 Comments

  1. Posted February 11, 2009 at 12:00 pm | Permalink

    I’ve got something like this wrapped in a class called Environment for AS2 and AS3.

    Here is the AS2 version:
    http://evolve.reintroducing.com/2008/11/14/as2/as2-environment/

    And here is the AS3 version:
    http://evolve.reintroducing.com/2007/10/15/as3/as3-environment/

  2. Posted February 11, 2009 at 12:59 pm | Permalink

    very cool Matt…. took me awhile to figure out how to do it in AS3 the first time I needed to…. that whole root.loaderInfo thing was confusing at first….

  3. Posted August 8, 2009 at 5:31 pm | Permalink

    Hi Zevan! i´m been on your blog for the last hour provably. you have very nice examples. I´ll be back for sure.

    I just read this post, and i would like to share my one line of pure magic code:)

    this is a public static var i have in my document class. so, ican access it from anyclass

    public static var LOCAL:String = Security.sandboxType != Security.REMOTE ? “http://www.mywebsite.com” : “”;

    All the best
    andre

  4. Posted August 8, 2009 at 7:01 pm | Permalink

    very nice andre… glad your enjoying the site.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*