通过Flash vars将值从HTML传递到flex组件



i具有以下代码,并且不会打印我要从javaScript传递的值。我很感激是否有人可以指出我犯的错误。

html我在template.html中编辑了代码,如下所示,包括IP = test和ip = 192.168.11.2如下所示

<param name="flashvars" value="IP=Test" />
<param name="allowFullScreen" value="true" />
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="${swf}.swf" width="${width}" height="${height}" flashVars="IP=192.168.11.2">
     <param name="quality" value="high" />
     <param name="bgcolor" value="${bgcolor}" />
     <param name="allowScriptAccess" value="sameDomain" />
     <param name="allowFullScreen" value="true" />
     <param name='flashVars' value='IP=192.168.11.2'/>

我的flex代码如下

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
            xmlns:fx="http://ns.adobe.com/mxml/2009"
            xmlns:s="library://ns.adobe.com/flex/spark"
            layout="absolute" viewSourceURL="srcview/index.html" creationComplete="{init();}">
<mx:Script><![CDATA[
[Bindable] private var ip_string:String;
private function init():void {
ip_string = Application.application.parameters.IP;
iplabel.text = ip_string;
}
]]>
</mx:Script>
<mx:Panel id="namePanel" width="1257" height="168" layout="absolute" alpha="1" roundedBottomCorners="true" borderStyle="none" cornerRadius="4" horizontalAlign="center" verticalAlign="middle" backgroundColor="#001e2a18" horizontalCenter="-136" verticalCenter="-411" fontSize="15" backgroundAlpha="0" color="#003e1e1e" themeColor="16316412">
<mx:Label x="21" y="5" text="UBI-Collage Gallery" width="1197" height="67.95" alpha="1" styleName="MyTextStyle" fontFamily="woodcut" fontSize="60" color="#00090908" textAlign="center" fontWeight="normal"/>
<mx:Label id="iplabel" x="90" y="85" styleName="codeStyle" textAlign="center" color="#00000000" fontFamily="woodcut" fontSize="32" text="IP"/>
</mx:Panel>
</mx:Application>

您需要在某些应用程序生命周期中读取参数,

1-首先注册应用程序标签中的事件列表

creationComplete =" {HandlerCreationComplete(event)}"

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" 
               xmlns:local="*"
               creationComplete="{handlerCreationComplete(event)}"
               >

2-在脚本部分中定义Listner函数,并使用 flexglobals.toplevelapplication

protected function handlerCreationComplete(event:FlexEvent):void
{
    var ip:String = FlexGlobals.topLevelApplication.parameters.IP;
    Alert.show(ip);
}

希望对

有帮助

更改嵌入代码如下。

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
        id="index" width="1550" height="1030"
        codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab"
        align="middle">
        <param name="movie" value="UbiPictureViewer.swf" />
        <param name="quality" value="high" />
        <param name="bgcolor" value="#869ca7" />
        <param name="allowScriptAccess" value="sameDomain" />
        <embed src="UbiCollage.swf" quality="high" bgcolor="#869ca7"
            width="1550" height="1030" name="index" align="middle"
            play="true"
            loop="false"
            quality="high"
            allowScriptAccess="sameDomain"
            flashVars="IP=<%=IP %>"
            type="application/x-shockwave-flash"
            pluginspage="http://www.adobe.com/go/getflashplayer">
        </embed>
</object>

最新更新