Working with loadvars can be frustrating if your calling vars from “www.website.com/getVars.php” and testing them by navigating to “website.com/getVars.php”. Flash will not load vars accross a domain (cause your missing the www) without adding a policy file. There are a couple ways around this:
- Don’t use absolute paths when working with loadvars.
The issue here is testing locally and on the web, you can’t load vars from getVars.php locally if you’re web server is generating the file with a database…
- Force your users to include www. before the domain name.
I work for a tv network and I’m finishing up 4 flash sites that all use loadvars and I felt like writing a script that would work for all of them, instead of one for each site. The following is the result, and I thought I would share it with the faithful kirupa nerds.
<script language=“javascript”>
var thisURL = “” + window.location;
var WWW = (thisURL.indexOf(“www”));
var dissect = thisURL.split("/");
if((thisURL.indexOf(“www.”)<=0) && dissect[2].indexOf(“www”)<=0) {
dissect.splice(2,1,“www.” + dissect[2]);
window.location= dissect.join("/");
}
</script>
I compressed (and actually made the code more scalable) from 23 lines to 6
Enjoy! let me know of any errors