本文介绍了在 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.

new 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 14:35