Flex - 如何将参数传递给 swf [英] Flex - How to pass parameters to a swf

查看:21
本文介绍了Flex - 如何将参数传递给 swf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 FlashVars 在 swf 中传递参数,但它不起作用.

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

这是html代码:

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

这里是 .mxml 文件代码:

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

推荐答案

首先,不要使用那种 HTML.使用 swfobject 将您的 Flash swf 嵌入到您的 html 中.Adobe 更容易做到并提供支持.

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.

其次,您没有正确访问 vars,并且可能过早地尝试访问 vars.在尝试访问它之前,您需要等待应用程序的 creationComplete 事件.有一个非常好的我刚刚在 Adob​​e 帮助中说的所有内容的教程.

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.

这篇关于Flex - 如何将参数传递给 swf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆