网页传递参数到flex中的方法

1.在<Object>和<embed>中设置flashVars参数 ,例如:
<object id=’mySwf’ classid=’clsid:D27CDB6E-AE6D-11cf-96B8-444553540000′ codebase=’http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab’ height=’100%’ width=’100%’>
        <param name=’src’ value=’FlashVarTest.swf’/>
        <param name=’flashVars’ value=’firstName=Nick&lastName=Danger’/>
        <embed name=’mySwf’ src=’FlashVarTest.swf’ pluginspage=’http://www.adobe.com/go/getflashplayer’ height=’100%’ width=’100%’ flashVars=’firstName=Nick&lastName=Danger’/>
<embed src=’TitleTest.mxml.swf?myName=Danger’ … />  
</object>
2.或者在<Object>和<embed>中的src属性中直接加参数 ,例如:
<object … >
    <param name=’src’ value=’TitleTest.mxml.swf?
’firstName=Nick&lastName=Danger ’>
    …
    <embed src=’TitleTest.mxml.swf?
’firstName=Nick&lastName=Danger ’ … />
</object>
3. 修改加载flash的html页面,找到第二个AC_FL_RunContent 中的代码内容,代码如下
AC_FL_RunContent(
" src " " ${swf} " ,
" width " " ${width} " ,
" height " " ${height} " ,
" align " " middle " ,
" id " " ${application} " ,
" quality " " high " ,
" bgcolor " " ${bgcolor} " ,
" name " " ${application} " ,
" allowScriptAccess " , " sameDomain " ,
" type " " application/x-shockwave-flash " ,
" pluginspage " " http://www.adobe.com/go/getflashplayer "
);
在"pluginspage", " http://www.adobe.com/go/getflashplayer "位置后,加上代码("flashvars","youParmName=youValue"),即如下:
AC_FL_RunContent(
" src " " ${swf} " ,
" width " " ${width} " ,
" height " " ${height} " ,
" align " " middle " ,
" id " " ${application} " ,
" quality " " high " ,
" bgcolor " " ${bgcolor} " ,
" name " " ${application} " ,
" allowScriptAccess " , " sameDomain " ,
" type " " application/x-shockwave-flash " ,
" pluginspage " " http://www.adobe.com/go/getflashplayer ",   
   "flashvars","youParmName=youValue"
);

4.如果通过url直接访问Flash,可以直接再后面加参数 ,例如:
http://localhost:8100/flex/myApp.swf?
’firstName=Nick&lastName=Danger
如何在Flex中读取这些参数
可以用Application.application.parameters或LoaderConfig.parameters获得外部参数。
但是切忌:只能在Application部署完成之后才能获取这些参数。也就是在派发creationComplete之后才能获得。例如:
mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” width=”100%” height=”100%”
layout=”absolute” creationComplete=”initApp()”  initialize=”init()”&gt;
<mx:Script>
<![CDATA[
import mx.core.Application
private function init():void
{
trace(Application.application.parameters["id"]);//输出undefined证明获取参数失败
}
private function initApp():void
{
               var str : String = "";
                for (var i:String in Application.application.parameters)
               {
                   str += Application.application.parameters[i] + "/n";
                }
                 
                Alert.show(str);
               
                str = Application.application.parameters["
firstName "];
                Alert.show("dd="+ str);
}
]]>
</mx:Sctipt>
</mx:Application>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值