4386 posts Community Mod Building awesome stuff for your mobile devices!
  • Has referred 100+ members
  • Has sold $125,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 1+ items on Envato Market
+14 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?

1677 posts Envato Elite Author
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+6 more
Tean says
var local:LocalConnection = new LocalConnection()
trace(local.domain);
1161 posts
  • Has referred 10+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Had an item featured in an Envato Bundle
+4 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 :)

1161 posts
  • Has referred 10+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Had an item featured in an Envato Bundle
+4 more
FlashTang says

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

cool :D

270 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $100+ on Envato Market
  • Has collected 10+ items on Envato Market
+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…

4386 posts Community Mod Building awesome stuff for your mobile devices!
  • Has referred 100+ members
  • Has sold $125,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 1+ items on Envato Market
+14 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
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $100+ on Envato Market
  • Has collected 10+ items on Envato Market
+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
  • Has been part of the Envato Community for over 6 years
  • Has referred 10+ members
  • Has sold $100+ on Envato Market
  • Has been a beta tester for an Envato feature
+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
  • Has referred 1+ members
  • Has sold $5,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Has been part of the Envato Community for over 5 years
+5 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);
};
1277 posts
  • Has been part of the Envato Community for over 7 years
  • Has referred 100+ members
  • Has sold $40,000+ on Envato Market
  • Interviewed on an Envato blog
+7 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