一般flex给外界调用会部署成三种方式:如:
http://localhost:8080/monitor.htm#type=test&...
http://localhost:8080/monitor.swf?type=test&...
http://localhost:8080/monitor.jsp?type=test&...
如何获得这三种不同的方式 下的参数呢?
第一种情况:通过BrowserManager直接获得#后面的参数,然后分割字符串&即可:
<?
xml version
=
"
1.0
"
encoding
=
"
utf-8
"
?>
< mx:Application xmlns:mx = " http://www.adobe.com/2006/mxml " layout = " absolute " minWidth = " 955 " minHeight = " 600 "
creationComplete = " init() " >
< mx:Script >
<! [CDATA[
import mx.controls.Alert;
import mx.managers.BrowserManager;
import mx.managers.IBrowserManager;
protected function init(): void
{
var bm:IBrowserManager = BrowserManager.getInstance();
bm.init();
var para:String = bm.fragment;
Alert.show(para);
}
]] >
< / mx:Script>
< mx:Application xmlns:mx = " http://www.adobe.com/2006/mxml " layout = " absolute " minWidth = " 955 " minHeight = " 600 "
creationComplete = " init() " >
< mx:Script >
<! [CDATA[
import mx.controls.Alert;
import mx.managers.BrowserManager;
import mx.managers.IBrowserManager;
protected function init(): void
{
var bm:IBrowserManager = BrowserManager.getInstance();
bm.init();
var para:String = bm.fragment;
Alert.show(para);
}
]] >
< / mx:Script>
</mx:Application>
第二种情况:通过Application.pararms
var str:String = application.parameters.type;
第三种情况:通过和js交互,获得参数值
function
getVars(){
var url = location.href;
var pattern = / (\w+)=(\w+) / ig;
var parames = {};
url.replace(pattern, function (a, b, c){
parames[b] = c;
});
var o = new Object();
o.topoId = parames[ ' topoId ' ] ;
o.nodeId = parames[ ' nodeId ' ] ;
return o;
var url = location.href;
var pattern = / (\w+)=(\w+) / ig;
var parames = {};
url.replace(pattern, function (a, b, c){
parames[b] = c;
});
var o = new Object();
o.topoId = parames[ ' topoId ' ] ;
o.nodeId = parames[ ' nodeId ' ] ;
return o;
}
在flex中
/**获得url地址栏上的参数*/
var info:Object = ExternalInterface.call("getVars");