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

本文介绍了如何在Flex应用中通过this.parameters.name获取不同类型的文件(.mxml, .swf, .html)URL中的参数,并提供了JavaScript和JSP辅助处理的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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参数.

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值