将 flashvars 样式的参数传递给加载的 SWF [英] Passing flashvars-style parameters to a loaded SWF

查看:19
本文介绍了将 flashvars 样式的参数传递给加载的 SWF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Flex 3 应用程序(播放器 v9),它加载 Flash SWF(AS3,也是播放器 v9)并且需要动态地向它传递运行时已知的参数集合.这些参数通常通过 HTML 页面中的 flashvars 元素传递.嵌入的电影通过 loaderInfo.parameters 对象访问这些参数.

I have a Flex 3 app (player v9) which loads a Flash SWF (AS3, also player v9) and needs to dynamically pass it a collection of parameters which are known at run-time. These are parameters that are normally passed via the flashvars element in an HTML page. The embedded movie accesses these parameters via the loaderInfo.parameters object.

我尝试过使用 SWFLoaderLoader 类,但没有成功传递参数.

I've tried using SWFLoader and Loader classes with no success in param-passing.

相关详情:

  • 它是一个本地程序,不能依赖查询字符串参数.
  • 我已经在嵌入代码中设置 loaderInfo.parameters["foo"] = "123" 搞砸了,但参数似乎永远不会出现在嵌入的电影中.
  • 我不能在嵌入的电影中放置额外的参数传递机制,因为它们是由第三方创建的.
  • It's a local program, and cannot rely on query string parameters.
  • I've mucked with setting loaderInfo.parameters["foo"] = "123" from the embedding code, but the parameter never seems to wind up in the embedded movie.
  • I cannot place extra parameter-passing machinery in the embedded movie(s), as they are created by third parties.

推荐答案

在 URL 中传递这个参数无济于事,因为它们是在 html-wrapper 中使用 javascript 代码获取的.'flashVars' 参数是使用 Application.application.parameters 获取的,因此,您必须在您的情况下手动设置这些参数.

Passing this params in URL won't help, because they're taken using javascript code in the html-wrapper. The 'flashVars' params are taken using the Application.application.parameters, so, you have to set these params manually in your case.

如果您使用 SWFLoader 加载另一个应用程序,则应创建对象,该对象将代表加载的应用程序并应用您需要的所有内容:

If you are using SWFLoader to load another app, you should create the object, that will represent the application loaded and apply all you need:

<mx:Script>
    <![CDATA[
        import mx.managers.SystemManager;
        import mx.controls.Alert;
        import mx.events.FlexEvent;

        private var loadedApp:Application;

        private function onLoadComplete(event:Event):void {
            var smAppLoaded:SystemManager = SystemManager(event.target.content);
            smAppLoaded.addEventListener(FlexEvent.APPLICATION_COMPLETE, onLoadedAppComplete);
        }

        private function onLoadedAppComplete(event:FlexEvent):void {
            try {
                loadedApp = Application(event.target.application);
                if(!loadedApp) throw new Error();

                loadedApp.parameters["param1"] = "value1";
            } catch (e:Error) {
                Alert.show("Failed to get application loaded.", "Error", Alert.OK); 
            }
        }

        private function onLoadError():void {
            Alert.show("Failed to load an application.", "Error", Alert.OK);
        }

    ]]>
</mx:Script>

<mx:SWFLoader 
    width="100%" height="100%"
    source="./AppToLoad.swf" 
    complete="onLoadComplete(event)" 
    ioError="onLoadError()" securityError="onLoadError()" />

这篇关于将 flashvars 样式的参数传递给加载的 SWF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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