Getting a domain in AS3

I know how to get the page url, but how can I extract only the domain and domain?

It should return the same value with or without www, and it should also return the same value regardless of the file, with or without a slash, etc.

So, www.domain.com will return domain.com , and domain.com/index.php will return the same.

Is it possible?

If so, is there a way to do this without calling ExternalInterface.call('window.location.href.toString') ?

Thanks for the help!

+4
source share
3 answers

You can use the loaderInfo class, and then crop it with a regex.

Like it. This trace of found [0] will return the domain down .com.

 package{ import flash.display.LoaderInfo import flash.display.MovieClip public class sample extends MovieClip { public var urlStr:String; public function sample (){ getLocation(this.loaderInfo.url); } public function getLocation(urlStr:String){ var urlPattern:RegExp = new RegExp("http://(www|).*?\.(com|org|net)","i"); var found:Object = urlPattern.exec(urlStr); trace(found[0]); } } 

}

+5
source

Flex uses

 Application.application.url 

But in direct Flash, you need to do it differently.

http://renaun.com/blog/2008/10/16/264/

Then, of course, you can hack the result as you need, since this is a string.

+2
source
 var domain = "http://www.example.com/"; var pathArray = domain.split("//"); pathArray = pathArray[1].split("/"); trace(pathArray[0]); //traces www.example.com 
+2
source

All Articles