swf加载完成后将数据传递给子swf [英] pass data to child swf after swf loading completed

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

问题描述

我正在使用swfloader加载一个主SWF文件中的一个SWF文件,我想将参数传递给已加载的SWF文件.我如何获取已加载的子引用以传递数据. 我的示例代码如下

I am loading one swf file inside a main swf by using swfloader and i want to pass the parameters to the loaded swf. How can i get the loaded child reference to pass data. My sample code is as follows

TestFile1.mxml

TestFile1.mxml

public var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, myFun);
loader.load(new URLRequest("/view/flex/TestFile2.swf"), new LoaderContext(false, ApplicationDomain.currentDomain));
viewId.addChild(loader);        

public function myFun(event:Event):void{
    Alert.show("loader.content-"+loader.content); // here alert coming like this [object_TestFile2_mx_managers_SystemManager]
    var testfile2:TestFile2 = loader.content as TestFile2; // here testfile2 is null
    testfile2.param1 = "val1";
}

推荐答案

有2个选项.

  1. 如果只需要简单的启动值,则可以在加载程序字符串中传递参数,并让TestFile2在启动时获取它们.

  1. If you just need simple startup values, you can pass arguments in the loader string and have TestFile2 grab them on start.

新的URLRequest("/view/flex/TestFile2.swf?param1 = val1")

new URLRequest("/view/flex/TestFile2.swf?param1=val1")

如果需要与孩子互动,则需要在应用程序完成事件之后获取对它的引用. Event.COMPLETE仅在加载加载程序时触发.在Event.COMPLETE事件中,添加一个内容准备就绪时触发的事件.

If you need to interact with the child, you need to grab a reference to it after the application complete event. Event.COMPLETE only fires when the loader is loaded. In the Event.COMPLETE event, add an event to fire when the content is ready.

public function myFun(event:Event):void{
    Alert.show("loader.content-"+loader.content); // here alert coming like this [object_TestFile2_mx_managers_SystemManager]
    loader.content.addEventListener(FlexEvent.APPLICATION_COMPLETE, appCreationComplete);
}
private function appCreationComplete(event:FlexEvent):void
{
    var testfile2:TestFile2 = loader.content["application"] as  TestFile2; // here testfile2 is not null
    testfile2.param1 = "val1";
}

这篇关于swf加载完成后将数据传递给子swf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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