如何将参数从Web应用程序(JSP)传递到Flex应用程序(mxml文件)

时间:2011-09-19 20:55:46

标签: actionscript-3 flex flex3

1 个答案:

答案 0 :(得分:1)

假设您在JSP中嵌入了Flex应用程序(Flash swf) - 我的建议是使用“FlashVars”将参数从JSP传递到Flex应用程序。

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="100%" height="100%"
        codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
        <param name="movie" value="LPort.swf" />
        <param name="FlashVars" value="paramA=<%=paramA%>&paramB=<%=paramB%>" />
        <param name="quality" value="high" />
        <param name="bgcolor" value="#869ca7" />
  <param name="menu" value="false"/>
    <param name="wmode" value="opaque" />
        <param name="allowScriptAccess" value="always" />
        <embed src="LPort.swf" quality="high" bgcolor="#869ca7" id="Logbook"
            width="100%" height="100%" name="LPort" align="middle"
            FlashVars="paramA=<%=paramA%>&paramB=<%=paramB%>"
    menu="false"
            play="true"
            loop="false"
            wmode="opaque"
            allowScriptAccess="always"
            type="application/x-shockwave-flash"
            pluginspage="http://www.adobe.com/go/getflashplayer">
        </embed>
</object>

然后在Flex应用程序中,您可以按如下方式访问这些参数(我假设是一个String的转换)。

if (Application.application.parameters.paramA != undefined)
{
  myFlexVarA = String(Application.application.parameters.paramA);
}
if (Application.application.parameters.paramB != undefined)
{
  myFlexVarB = String(Application.application.parameters.paramB);
}