Copy link to clipboard
Copied
Hi,
for the project I'm working on, I need to assign a value to different URL for tracking purposes. the assets will be served on different websites, with each website using a different value.
Currently I have in my class file
import flash.external.*;
public function checkURL() {
//var domainName:String = ExternalInterface.call("window.location.href.toString");
var domainName:String = stage.loaderInfo.loaderURL;
var urlPathSubstring = domainName.substr(7,18);
var urlPathSubstring2 = domainName.substr(7,16);
var urlPathSubstring3 = domainName.substr(7,24);
var urlPathSubstring4 = domainName.substr(7,30);
var urlPathSubstring5 = domainName.substr(7,22);
var urlPathSubstring6 = domainName.substr(7,30);
var urlPathSubstring7 = domainName.substr(7,22);
if(urlPathSubstring2=="http://www.xxxxxxxx.com"){
is_value=0;
}
else if(urlPathSubstring3=="http://staging.xxxxxxxx.com"){
is_value=1;
}
else if(urlPathSubstring7=="http://yyyyyyyy.xxxxxxxx.com"){
is_value=0;
}
else if(urlPathSubstring6=="http://yyyyyyyy.staging.xxxxxxxx.com"){
is_value=1;
}
else if(urlPathSubstring5=="http://zzzzzzzzz.xxxxxxxx.com"){
is_value=0;
}
else if(urlPathSubstring4=="http://zzzzzzzzz.staging.xxxxxxxx.com"){
is_value=1;
}
else if(urlPathSubstring=="http://demo.qqqqqqqqq.com"){
is_value=2;
}else{
is_value=5;
}
}
[note, due to legal purposes I had to void out the URL in the if statements]
when I compile and do a trace, the domainName var spits out the location of the .swf and shows the is_value=5, which it should. Once I upload this to the demo server, the is_value is still showing up as 5, when it should be is_value=2.
I had originally started with externalInterface call and that was doing the same thing with the is_values. The code will run, it just seems like it might not be running through the substring and just defaults to the else statement.
Anything that y'all see or any suggestions?
Thanks!
Copy link to clipboard
Copied
You should make yourself a nice big textfield and use that to check the various values (urlPathSubstring thru 7). Normally I'd suggest using the trace function, but since you need to be testing on a server the textfield approach will allow you to see the values you expect.
You might find that regardless of your conditionals, the values you require from the domainNames are not yet fully processed before the conditionals are executed.
Copy link to clipboard
Copied
Thanks for the info. The next step I had planned was to add in the text box so we were on the same page. I first added domainName as a public var, then moved the code (domainName = stage.loaderInfo.loaderURL;) up to the init function (also tried it in the first public class function).
added in a text box to see what happens when I compile and also what happens on one of the servers. So the odd thing is that when I do a trace, the path to the .swf on my computer shows up but not in the text box. I get "bsbsbsps" showing and on the live server it shows "ppsbp_spb" bizarre!
I'm not 100% certain as to why this isn't grabbing the initial domain. I also tried the output in the text box for all of the urlPathSubstring, that just showed the "bsbsbsps" for each locally, and "ppppppp" for the live server.
From what I could read up on,
.loaderInfo.loaderURL;
would be the better way to grab the initial domain - for the AS2 builds that I had worked on, the
ExternalInterface.call("window.location.href.toString");
worked fine. I guess the first thing would be to really understand which code would be best to continue working with, and why the AS3 version seems to have issues when the older AS2 version didn't.
Thanks!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now