1

我在现场 Flash 中的超链接有问题。由于网站在 CMS 中,审批的不同阶段我不知道确切的网址,所以

function piClick(e:MouseEvent):void
{
  var url:String = "/cms__Main?name=Target_name";
  var request:URLRequest = new URLRequest(url);
  try {
    navigateToURL(request, '_self');
  } catch (e:Error) {
    trace("Error occurred!");
  }
} 

不起作用,因为 cms_Main 会根据站点的阶段而变化。我可能需要做的是:

  • 抓取网址(或最后一个“/”之后的部分,如果可能的话)
  • 更改字符串中的“名称”变量

https://domain_name/.../status?name=Name_I_need_to_swap&sname=Country_name&..
4

2 回答 2

0

你可以得到网址this.loaderInfo.url

于 2012-12-14T12:19:38.907 回答
0

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);
于 2012-12-14T18:10:14.560 回答