解决Flex从页面 URL里获取参数的问题
时间:2010-07-14 来源:fireflylover
1:当用http://xxxxx/xxx.mxml?name=hermit方式访问
可以用this.parameters.name这种方式在flex里面取url参数
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApplication()" >
<mx:Script>
private function initApplication():void
{
trace (this.parameters.name);
}
</mx:Script>
<mx:Label id="path" width="100%" text="{name}" />
</mx:Application>
2:当用http://xxxxx/xxx.swf?name=hermit方式访问
可以用this.parameters.name这种方式在flex里面取url参数
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApplication()" >
<mx:Script>
private function initApplication():void
{
trace (this.parameters.name);
}
</mx:Script>
<mx:Label id="path" width="100%" text="{name}" />
</mx:Application>
3:当用http://xxxxx/xxx.html?name=hermit方式访问
可以用this.parameters.name这种方式在flex里面取url参数
但是页面需要处理.
页面中加 入js方法
来源:(http://blog.sina.com.cn/s/blog_4b25b7d50100j82z.html) - 解决Flex从页面 URL里获取参数的问题_Bosee_新浪博客
var url,pos,parastr,para;
url = window.location.href;
pos = url.indexOf("?")
parastr = url.substring(pos+1);
return parastr;
}
在 AC_FL_RunContent 中加入
如 果页面是flex builder 通过模板自动生成的
那么需要在index.template.html文件中加入上面的代码.
4: 同3,但是如果希望js被禁用的时候,flex依然能工作
则需要把html变成jsp,
然后在jsp里面获取url参数,拼成字符串 XXXX,
在<object classid=下面
加<param name="FlashVars" value="XXXX" />
然后在flex里面依然能通过this.parameters.name去获取url参数.