1

我有以下代码,它不会打印我想从 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'/>

我的弹性代码如下

<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>
4

2 回答 2

1

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

1-首先在Application标签中注册一个事件Listner

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- 在脚本部分定义监听函数并使用FlexGlobals.topLevelApplication

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

希望有帮助

于 2012-11-10T06:18:03.527 回答
0

如下更改嵌入代码就可以了。

<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>
于 2012-11-10T23:48:32.767 回答