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(イベント)}"

<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 に答える