簡體   English   中英

swf加載完成后將數據傳遞給子swf

[英]pass data to child swf after swf loading completed

我正在使用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";
}

有2個選項。

  1. 如果只需要簡單的啟動值,則可以在加載程序字符串中傳遞參數,並讓TestFile2在啟動時獲取它們。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM