4948 posts Community Mod Building awesome stuff for your mobile devices!
  • Trendsetter
  • Weekly Top Seller
  • Elite Author
  • Author Level 8
+17 more
Enabled
Moderator
says

I’m having trouble with this, can’t find anything useful in the AS3 docs.

For AS2 I used this

var Local = new LocalConnection();
var movieDomain = Local.domain();
if(String(movieDomain) == "localhost"){
    xml.loadData("xmlfile.xml");
}else{
    xmlData.load("xmlfile.xml?"+Math.random());
}

This loads an XML locally, but adds a cache buster if online.

How do I do the same for AS3 ? :| Any suggestions?

1689 posts Envato Elite Author
  • Affiliate Level 2
  • Author Level 8
  • Collector Level 1
  • Top Monthly Author
+8 more
Tean
says
var local:LocalConnection = new LocalConnection()
trace(local.domain);
1163 posts
  • Affiliate Level 2
  • Author Level 6
  • Collector Level 3
  • Top Monthly Author
+6 more
FlashTang
says
local=loaderInfo.url.slice(0,4).toLocaleLowerCase()!="http"&&loaderInfo.url.slice(0,3).toLocaleLowerCase()!="ftp";
if(local){

}else{
   ...?rn=Math.ramdom()
}

Maybe toLocaleLowerCase() is needless

Or maybe there is a better one :)

1163 posts
  • Affiliate Level 2
  • Author Level 6
  • Collector Level 3
  • Top Monthly Author
+6 more
FlashTang
says

var local:LocalConnection = new LocalConnection()
trace(local.domain);

cool :D

270 posts
  • 6 Years of Membership
  • Affiliate Level 1
  • Author Level 2
  • Collector Level 2
+1 more
magickaito
says

interesting. i didnt realize localconnection can be used like this! :D

i use loaderInfo.url.indexOf(“http”) to identify whether it is local or http…

4948 posts Community Mod Building awesome stuff for your mobile devices!
  • Trendsetter
  • Weekly Top Seller
  • Elite Author
  • Author Level 8
+17 more
Enabled
Moderator
says

interesting. i didnt realize localconnection can be used like this! :D i use loaderInfo.url.indexOf(“http”) to identify whether it is local or http…

Well, none of the above seem to work. I have a cache buster in AS3 , and it doesn’t work locally because it loads an xml like:

"folder/file.xml"+"cb?"+Math.random()

I need a cache buster in a if/else statement. If local connection is true , then load without math random, else load with math random …

I’ve been trying since I first posted :| None work This is so frustrating!

270 posts
  • 6 Years of Membership
  • Affiliate Level 1
  • Author Level 2
  • Collector Level 2
+1 more
magickaito
says

why does it load like that locally?

var _isLocal:Boolean = false;

_isLocal = new LocalConnection().domain == "localhost";

function get noCache():String
{
    var noCache:String = _isLocal ? "" : "?nocache=" + new Date().getTime();
    return noCache;
}

you want to try this?

2309 posts
  • 7 Years of Membership
  • Affiliate Level 2
  • Author Level 2
  • Beta Tester
+5 more
theflyingtinman
says


interesting. i didnt realize localconnection can be used like this! :D i use loaderInfo.url.indexOf(“http”) to identify whether it is local or http…

Well, none of the above seem to work. I have a cache buster in AS3 , and it doesn’t work locally because it loads an xml like:

"folder/file.xml"+"cb?"+Math.random()

I need a cache buster in a if/else statement. If local connection is true , then load without math random, else load with math random …

I’ve been trying since I first posted :| None work This is so frustrating!

I don’t know whether you noticed the difference in Tean’s (correct) solution: In AS2 “domain()” is a method on LocalConnection: in AS3 “domain” is a property of LocalConnection (no parentheses)

Edit: not sure what this line:

"folder/file.xml"+"cb?"+Math.random()

is supposed to be but it would evaluate to “folder/file.xmlcb?” + Math.random() which is obviously going to cause a problem.

182 posts
  • Affiliate Level 1
  • Author Level 4
  • Collector Level 1
  • 6 Years of Membership
+4 more
marpies
says

I don’t know whether you noticed the difference in Tean’s (correct) solution: In AS2 “domain()” is a method on LocalConnection: in AS3 “domain” is a property of LocalConnection (no parentheses)

That’s right.

I use this static method in my class and it works perfectly.

public static function getURL(url:String):URLRequest
{
    var domain:LocalConnection = new LocalConnection();
    if(domain.domain != "localhost")    // IF NOT RUNNING ON LOCAL COMPUTER
        url += "?" + Math.random();
    return new URLRequest(url);
};
1281 posts
  • 7 Years of Membership
  • Affiliate Level 4
  • Author Level 6
  • Blog Interview
+8 more
rondog
says

I use this

var onLocalMachine = (loaderInfo.url.substring(0,4) != "http") ? true : false;
if (onLocalMachine)
{
    loader.load(new URLRequest(xml));
}
else
{
    loader.load(new URLRequest(xml + "?"+new Date().getTime()));
}
by
by
by
by
by
by