2012-12-14 53 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