簡體   English   中英

AS3在Flex 4中獲取FlashVars

[英]as3 get FlashVars in flex 4

我想使用動作腳本在HTML中獲取FlashVars,

html中的< OBJECT >標簽如下:

            <!--[if !IE]>-->
            <object type="application/x-shockwave-flash" data="test.swf" width="550" height="400">
                <param name="movie" value="test.swf" />
                <param name="quality" value="high" />
                <param name="bgcolor" value="#ffffff" />
                <param name="play" value="true" />
                <param name="loop" value="true" />
                <param name="wmode" value="window" />
                <param name="scale" value="showall" />
                <param name="menu" value="true" />
                <param name="devicefont" value="false" />
                <param name="salign" value="" />
                <param name="allowScriptAccess" value="sameDomain" />
                <param name="FlashVars" value="acc=3001&pwd=test">
            <!--<![endif]-->
                <a href="http://www.adobe.com/go/getflash">
                    <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" />
                </a>
            <!--[if !IE]>-->
            </object>
            <!--<![endif]-->

並且我的動作腳本被用作mxml使用的flex模型,因此我沒有movieclip或無法使用this.loaderInfo.parameters; root因為沒有displayObject。

還有其他方法可以在as3中獲取FlashVars值,

或者我可以在mxml中獲取FlashVars,然后讓as3獲取變量,例如:

var paramObj:Object = Application(FlexGlobals.topLevelApplication).parameters;
var test:String;
test = paramObj['acc'];

並在as3中:

var getText:String = test;

提前致謝。

由於topLevelApplication是靜態類型,因此您甚至可以在應用程序文件的任何位置訪問FlexGlobals。 因此,您可以在AS文件本身中執行此操作,而不是在MXML文件中執行此操作

我終於使用了Application.application.parameters 我使用Flex 4.6 SDK很奇怪,但是我的Flex版本是2,所以我不能使用FlexGlobals。 結果類似於使用FlexGlobals:

在您的html中:

<script type="text/javascript">
            // For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection. 
            var swfVersionStr = "11.1.0";
            // To use express install, set to playerProductInstall.swf, otherwise the empty string. 
            var xiSwfUrlStr = "playerProductInstall.swf";
            var flashvars = {};
            var params = {};
            params.quality = "high";
            params.bgcolor = "#ffffff";
            params.allowscriptaccess = "sameDomain";
            params.allowfullscreen = "true";
            params.FlashVars = "acc=3001&pwd=test";

import mx.core.Application;

然后在actionscript或mxml中使用代碼:

Application.application.parameters.acc;

以上結果將是3001。

我也嘗試添加<param name="acc=3001&pwd=test">但是操作腳本無法理解它(結果未定義),但我不確定為什么。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM