2008-06-05

取得 Domain Name (AS3 版)

/**
* author: shinder lin
* email: shinder.lin@gmail.com
*/
package lin.shinder.net
{
import flash.display.DisplayObject;
public class HttpDomain
{
static public var defaultDomain:String = "http://localhost";
static public function getDomain(displayObj:DisplayObject)
{
var url_str:String = displayObj['stage'].loaderInfo.loaderURL;
if (url_str.indexOf("http://") == 0 || url_str.indexOf("https://") == 0) {
var s_index:int = url_str.indexOf("/", 10);
return url_str.substring(0, s_index);
} else {
return defaultDomain;
}
}
}
}

由 URL 取得 Domain Name (AS2 版)

1 則留言:

Shinder 提到...

/**
* author: shinder lin
* 不使用 static 的版本
*/
package {
import flash.display.DisplayObject;
public class HttpDomain {
public var defaultDomain:String = "http://localhost";
private var displayObj:DisplayObject;
public function HttpDomain(displayObj:DisplayObject)
{
this.displayObj = displayObj;
}
public function getDomain() {
var url_str:String = displayObj['stage'].loaderInfo.loaderURL;
if (url_str.indexOf("http://") == 0 || url_str.indexOf("https://") == 0) {
var s_index:int = url_str.indexOf("/", 10);
return url_str.substring(0,s_index);
} else {
return defaultDomain;
}
}
}
}

FB 留言