【问题标题】:pass data to child swf after swf loading completedswf 加载完成后将数据传递给子 swf
【发布时间】:2018-06-29 12:06:55
【问题描述】:

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

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

【问题讨论】:

    标签: actionscript-3 apache-flex mxml


    【解决方案1】:

    有 2 个选项。

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

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

    2. 如果您需要与孩子进行交互,您需要在应用程序完成事件之后获取对它的引用。 Event.COMPLETE 仅在加载程序加载时触发。在Event.COMPLETE 事件中,添加一个在内容准备好时触发的事件。

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

    【讨论】:

    • 非常感谢。我们需要第二个,它对我有用。
    猜你喜欢
    • 1970-01-01
    • 2012-12-06
    • 1970-01-01
    • 1970-01-01
    • 2010-10-03
    • 1970-01-01
    • 2011-05-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多