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

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

问题描述

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

这里是html代码:

 < noscript> 
< param name =movievalue =tpc.swf/>
< param name =qualityvalue =high/>
< param name =bgcolorvalue =#ffffff/>
< param name =allowScriptAccessvalue =sameDomain/>
< param name =allowFullScreenvalue =true/>
< param name = FlashVars value =myVariable = Hello%20World& mySecondVariable = Goodbye>

<! - [if!IE]> - >
< object type =application / x-shockwave-flashdata =tpc.swfwidth =100%height =100%>
< param name =qualityvalue =high/>
< param name =bgcolorvalue =#ffffff/>
< param name =allowScriptAccessvalue =sameDomain/>
< param name =allowFullScreenvalue =true/>
**< param name = FlashVars value =myVariable = Hello%20World& mySecondVariable = Goodbye> **

<! - <![endif] - >
<! - [if gte IE 6]> - >
< p>
脚本和活动内容不允许运行,或者未安装Adobe Flash Player版本
10.0.0或更高版本。
< / p>
<! - <![endif] - >
< a href =http://www.adobe.com/go/getflashplayer>
< img src =http://www.adobe.com/images/shared/download_buttons/get_flash_player.gifalt =Get Adob​​e Flash Player/>
< / a>
<! - [if!IE]> - >
< / object>
<! - <![endif] - >
< / object>
< / noscript>

这里是.mxml文件代码:

  var keyStr:String; 
var valueStr:String;

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

var length:int = 0;

(paramObj中的keyStr){
length ++;


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

$ b $(paramObj中的keyStr){
valueStr = String(paramObj [keyStr]);
ta.appendText(\ t+ keyStr +:\ t+ valueStr +\\\
);


解决方案

首先,不要使用那个HTML。使用 swfobject 将您的Flash swf嵌入到您的html中。第二,你没有正确地访问变量,可能试图访问变量太快了。在尝试访问应用程序的creationComplete事件之前,您需要等待。我刚刚在Adobe帮助中提到的所有内容都有一个很好的教程。 。


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

解决方案

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.

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

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