Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In AS3 / Flash Can a URL Request / Loader Use "//" without Specifying a http or https Protocol?

I have a flash app running that loads remote data and we're transitioning to use (SSL) https://

I am wondering is it possible to just use "//" as you would in JavaScript to automatically assume the parent page's protocol (http or https).

Thanks

update: it seems to me that you can use a url format like "//www.something.com" but instead of assuming the page protocol it seems like it's just defaulting to "http://www.something.com".

Now I'm working around this by checking if the SWF is an SSL url. Something like this:

if( loaderInfo.url.indexOf("https:") == 0 ) {
    //replace http: with https:
}

Which is unfortunately inconvenient to be doing that everywhere you handle a remote asset URL. Just loading everything with matching proto would be a lot nicer... like "//www.someurl.com/wouldbenicer.xml", especially since js and html both work that way.

Blah.

Any ideas?

like image 322
OG Sean Avatar asked Mar 04 '26 05:03

OG Sean


2 Answers

"//" relative proto doesn't work in flash the way the browser works with urls in HTML, instead it defaults to http://

Workaround:

Check the URL of the SWF to see if the URL about to be loaded should be modified to have https:// protocol:

 if( loaderInfo.url.indexOf("https:") == 0 ) {
     //replace http: with https:
 } else {
   //replace https: with http:
 }
like image 136
OG Sean Avatar answered Mar 06 '26 02:03

OG Sean


Building upon OG Sean's answer, here's a wrapper function that'll manage protocol-relative URLs and default to HTTP.

function relativeURL(url:String) {
    var scheme = (loaderInfo.url.indexOf("https:") == 0) ? "https:": "http:";
    var url = scheme + url.replace(/^https?:/,"");
    return url;
}
like image 28
novwhisky Avatar answered Mar 06 '26 02:03

novwhisky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!