4601 posts Community Mod Building awesome stuff for your mobile devices!
  • Contributed a blog post
  • Elite Author: Sold more than $75,000 on Envato Market
  • Helps us moderate the forums
  • Has sold $125,000+ on Envato Market
+15 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?

1681 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);
1162 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 :)

1162 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 6 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…

4601 posts Community Mod Building awesome stuff for your mobile devices!
  • Contributed a blog post
  • Elite Author: Sold more than $75,000 on Envato Market
  • Helps us moderate the forums
  • Has sold $125,000+ on Envato Market
+15 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 6 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 7 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
+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);
};
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()));
}

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by