将 flashvars 样式参数传递给加载的 SWF

发布于 2024-07-10 07:57:30 字数 435 浏览 7 评论 0原文

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

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

相关细节:

  • 它是本地程序,不能依赖查询字符串参数。
  • 我已经在嵌入代码中设置了 loaderInfo.parameters["foo"] = "123" ,但该参数似乎永远不会出现在嵌入的电影中。
  • 我无法在嵌入式电影中放置额外的参数传递机制,因为它们是由第三方创建的。

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.

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

Relevant details:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

·深蓝 2024-07-17 07:57:30

在 URL 中传递此参数没有帮助,因为它们是在 html 包装器中使用 javascript 代码获取的。
“flashVars”参数是使用 Application.application.parameters 获取的,因此,您必须根据您的情况手动设置这些参数。

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

<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()" />

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.

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()" />

眼前雾蒙蒙 2024-07-17 07:57:30

原因很简单。
我今天发现了这一点。

在通过 SWFloader 加载的组件中,将 parentApplicationAplication.application 设置为顶级应用程序(此女巫通过 SWFLoader 加载组件)。
加载的组件可以看到 flashvars 设置为顶级应用程序。
这可能是在SWFLoader中设置参数没有任何影响的原因。

我已经在我的顶级应用程序上设置了正确的 flashvars,并且它们也可以在加载的应用程序中看到:-)。

The reason is simple.
I've discovered this today.

In the component loaded via SWFloader has parentApplication or Aplication.application set to the top level application (this witch loads component via SWFLoader).
And the loaded component can see flashvars set to the top level application.
This is probably the cause that setting parameters in SWFLoader does not have any impact.

I've set proper flashvars on my toplevel application and they are also seen in the loaded one :-).

哆兒滾 2024-07-17 07:57:30

在网页上嵌入 SWF 时,您可以将 flashvars 作为 URL 上的参数传递给 SWF,也许同样的方法也适用于您的情况? 如果 SWF 位于 file:///some/path/to/a.swf ,请尝试使用 file:///some/path/to/a.swf?hello=world& ;foo=bar。 它可能会起作用。

When embedding a SWF on a web page you can pass flashvars as parameters on the URL to the SWF, perhaps the same could work in your case? If the SWF is located at file:///some/path/to/a.swf try using file:///some/path/to/a.swf?hello=world&foo=bar. It might work.

-柠檬树下少年和吉他 2024-07-17 07:57:30

如果我首先找到这个答案,今天会节省我很多时间: AS3 Pass FlashVars加载 swf

本质上:从 Flash Player 10.2 开始,可以通过将 flashvar 设置为 LoaderContext 上的参数来传递它们。

Would have saved myself a lot of time today if I had found this answer first: AS3 Pass FlashVars to loaded swf.

Essentially: since Flash Player 10.2 it has been possible to pass flashvars along by setting them as parameters on the LoaderContext.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文