stage.loaderInfo.url
将为您提供 swf 本身的地址,因此不会为您提供完整地址、查询或哈希标记。但是,您可以使用 Javascript 获取所有这些信息。
import flash.external.ExternalInterface;
function getFullAddress():String {
if (ExternalInterface.available) {
var href:String = ExternalInterface.call('function(){return window.location.href}');
if (href) return href.toString();
}
throw new Error('Make sure JS is enabled.');
}
var fullAddr:String = getFullAddress();
编辑:这是获取和修改您所要求的所有内容的方法。
import flash.external.ExternalInterface;
import flash.net.URLVariables;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.navigateToURL;
function getFullAddress():String {
if (ExternalInterface.available) {
var href:String = ExternalInterface.call('function(){return window.location.href}');
if (href) return href.toString();
}
throw new Error('Make sure JS is enabled.');
}
function getQuery(fullAddr:String):URLVariables {
if (!fullAddr.match(/\?[^#]/)) return new URLVariables();
var q:String = fullAddr.replace(/^.*?\?([^#]+)(#.*)?$/,'$1');
return new URLVariables(q);
}
function getAddress(fullAddr:String):String {
return fullAddr.replace(/\?.*/,'').replace(/#.*/,'');
}
function getRequest(url:String,query:URLVariables=null,method:String='GET'):URLRequest {
method = URLRequestMethod[method] || 'GET';
var req:URLRequest = new URLRequest(url);
req.method = method;
if (method == 'GET' && query != null) {
req.url += '?' + query.toString().replace(/%5f/gi,'_').replace(/%2d/gi,'-');
// this is because dash and underscore chars are also
// encoded by URLVariables. we want to omit this.
return req;
}
req.data = query;
return req;
}
var fullAddr:String = getFullAddress();
var addr:String = getAddress(fullAddr);
var query:URLVariables = getQuery(fullAddr);
query.name = 'Name_I_need_to_swap';
query.sname = 'Country_name';
// add as many variable-value pairs as you like
// and don't worry, they will be automatically
// encoded by the function called below
var req:URLRequest = getRequest(addr,query);
//navigateToURL(req);
// check the console to see the changed address
ExternalInterface.call('console.log',req);