gpt4 book ai didi

javascript - Flex 通过 flash 变量将值从 html 传递到 Flex 组件

转载 作者:行者123 更新时间:2023-11-28 02:37:06 25 4
gpt4 key购买 nike

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

最佳答案

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

1-首先在Application标签中注册一个事件监听器

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);
}

希望有帮助

关于javascript - Flex 通过 flash 变量将值从 html 传递到 Flex 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13317957/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com