`
fireflylover
  • 浏览: 107801 次
  • 性别: Icon_minigender_2
  • 来自: 武汉
社区版块
存档分类
最新评论

解决Flex从页面 URL里获取参数的问题

    博客分类:
  • FLEX
阅读更多

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_新浪博客

function getparafromurl() {
var url,pos,parastr,para;
url
= window.location.href;
pos
= url.indexOf("?")
parastr
= url.substring(pos+1);
return parastr;
}

在 AC_FL_RunContent 中加入

"FlashVars", getparafromurl(),


如 果页面是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参数.

 


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics