- Has been a member for 4-5 years
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Sold between 50 000 and 100 000 dollars
- Microlancer Beta Tester
- Community Moderator
- Interviewed on the Envato Notes blog
- Author was Featured
- Bought between 1 and 9 items
- Referred between 50 and 99 users
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?
- Author was Featured
- Sold between 50 000 and 100 000 dollars
- Author had a Free File of the Month
- Bought between 1 and 9 items
- Exclusive Author
- Europe
- Has been a member for 3-4 years
- Referred between 10 and 49 users
- Repeatedly Helped protect Envato Marketplaces against copyright violations
var local:LocalConnection = new LocalConnection() trace(local.domain);
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 
interesting. i didnt realize localconnection can be used like this!

i use loaderInfo.url.indexOf(“http”) to identify whether it is local or http…
- Has been a member for 4-5 years
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Sold between 50 000 and 100 000 dollars
- Microlancer Beta Tester
- Community Moderator
- Interviewed on the Envato Notes blog
- Author was Featured
- Bought between 1 and 9 items
- Referred between 50 and 99 users
magickaito said
interesting. i didnt realize localconnection can be used like this!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!
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?
Enabled said
magickaito said
interesting. i didnt realize localconnection can be used like this!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 postedNone 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.
theflyingtinman said
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);
};
- Author was Featured
- Bought between 50 and 99 items
- Contributed a Tutorial to a Tuts+ Site
- Exclusive Author
- Has been a member for 5-6 years
- Interviewed on the Envato Notes blog
- Item was Featured
- Referred between 100 and 199 users
- Repeatedly Helped protect Envato Marketplaces against copyright violations
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()));
}
