Flex - How to pass parameters to a swf

依然范特西╮ 提交于 2019-12-11 18:10:11

问题


I am using FlashVars to pass params in the swf but it is not working.

Here is the html code:

<noscript>
        <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="100%" height="100%" id="tpc">
            <param name="movie" value="tpc.swf" />
            <param name="quality" value="high" />
            <param name="bgcolor" value="#ffffff" />
            <param name="allowScriptAccess" value="sameDomain" />
            <param name="allowFullScreen" value="true" />
            <param name=FlashVars value="myVariable=Hello%20World&mySecondVariable=Goodbye">

            <!--[if !IE]>-->
            <object type="application/x-shockwave-flash" data="tpc.swf" width="100%" height="100%">
                <param name="quality" value="high" />
                <param name="bgcolor" value="#ffffff" />
                <param name="allowScriptAccess" value="sameDomain" />
                <param name="allowFullScreen" value="true" />
                **<param name=FlashVars value="myVariable=Hello%20World&mySecondVariable=Goodbye">**

            <!--<![endif]-->
            <!--[if gte IE 6]>-->
                <p> 
                    Either scripts and active content are not permitted to run or Adobe Flash Player version
                    10.0.0 or greater is not installed.
                </p>
            <!--<![endif]-->
                <a href="http://www.adobe.com/go/getflashplayer">
                    <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash Player" />
                </a>
            <!--[if !IE]>-->
            </object>
            <!--<![endif]-->
        </object>
    </noscript>     

Here is the .mxml file code:

            var keyStr:String;
            var valueStr:String;

            var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;

            var length:int = 0;

            for (keyStr in paramObj) {
                length++;
            }

            if (length == 0) {
                ta.appendText("Length is zero so below is the dummy data:\n");
                paramObj = {test:"Test", test2:"Test2"};
            }

            for (keyStr in paramObj) {   
                valueStr = String(paramObj[keyStr]);
                ta.appendText("\t" + keyStr + ":\t" + valueStr + "\n");
            }

回答1:


First, don't use that HTML. Use swfobject to embed your Flash swf into your html. It's easier to do and supported by Adobe.

Second, you're not accessing the vars properly and probably trying to access the vars too soon. You need to wait for the application's creationComplete event before trying to access it. There's a real good tutorial on everything I just said on Adobe Help.




回答2:


Within the <object> try adding an <embed> like this:

<embed src="file.swf?myVariable=Hello%20World&mySecondVariable=Goodbye" width="" height="" />


来源:https://stackoverflow.com/questions/6273759/flex-how-to-pass-parameters-to-a-swf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!