(注:采用fb4 beta1开发,由于兼容问题,可以适当加以修改放到自己的环境中,测试的时候需要放到服务器上面,本人的测试url为
http://127.0.0.1/astest/asjs.html?msnum=13112345678)
mxml文件:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" creationComplete="application1_creationCompleteHandler(event)" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;
private var tempParam:String;
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
var param:String=ExternalInterface.call("test");
if(param!=""){
tempParam=param;
}
handlerParam();
}
private function handlerParam():void{
testText.text=tempParam;
}
]]>
</fx:Script>
<s:TextInput id="testText" x="23" y="34" width="198" height="31"/>
</s:Application>
index.template.html模板文件需要添加的js代码:
var tempparam="";
var localurl2 = location.href;
function getParameter(paraStr, url)
{
var result = "";
var str = "&" + url.split("?")[1];
var paraName = paraStr + "=";
if(str.indexOf("&"+paraName)!=-1)
{
if(str.substring(str.indexOf(paraName),str.length).indexOf("&")!=-1)
{
var TmpStr=str.substring(str.indexOf(paraName),str.length);
result=TmpStr.substr(TmpStr.indexOf(paraName),TmpStr.indexOf("&")-TmpStr.indexOf(paraName));
}
else
{
result=str.substring(str.indexOf(paraName),str.length);
}
}
else
{
result="msnum is null";
}
return (result.replace("&",""));
}
function initData(){
var r = getParameter("msnum",localurl2);
var pName = r.split("=")[0];
var pValue = r.split("=")[1];
tempparam=pValue;
}
function test(){
return tempparam;
}
还需要对body标签进行设置onload事件:
<body οnlοad="initData()">
配置方面如果有问题可以加QQ:626839566