2012-12-14 35 views
1

我在网站上的Flash中存在超链接问题。由于网站是CMS,经批准的不同阶段 我不知道确切的网址,所以Flash超链接 - 更改网址中的var名称

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根据现场的阶段变化。我可能需要做的是:

  • 抓取URL(或部分后最后一个 “/” 如果这甚至有可能)
  • 变 “名” 变量中的字符串

FE

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

回答

0

stage.loaderInfo.url将g ^等你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); 
0

你可以得到URL与this.loaderInfo.url