与 SWF 加载程序交互 [英] Interact with SWF Loader

查看:21
本文介绍了与 SWF 加载程序交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中嵌入了一个 swf 文件

<mx:SWFLoader source="@Embed(source='mod/VideoModule.swf')" width="50" height="50" id="loader" creationComplete="initLoader()"/>

现在在 flex 文档的帮助下,我想通过创建 SystemManager 与我加载的 swf 进行交互

[可绑定]公共变量加载SM:系统管理器;私有函数 initLoader() : void {跟踪(装载机内容);LoadedSM = SystemManager(loader.content);var b: Button = loadedSM.application["button1"] as Button;b.addEventListener(MouseEvent.CLICK, test);}

但是在启动应用程序时出现错误#1034,并说 Main__embed_mxml_mod_VideoModule_swf_856293516@33f53c1 无法转换为 mx.managers.SystemManager

有什么想法吗?

提前致谢

塞巴斯蒂安

解决方案

所以首先我会使用 SWF 加载器的 complete 事件,并且在创建 swf 加载器时将触发 creationComplete 事件,而不是在其内容已加载时触发.

>

<mx:SWFLoader source="@Embed(source='mod/VideoModule.swf')" width="50" height="50" id="loader" complete="loaderCompleteHandler(event)"/>

然后我也会在事件触发时传递 FlexEvent 参数.该事件使您可以访问 SWFLoader 的实例.SwfLoader 然后有一个名为 content 的属性,它可以让您访问加载的 swf.如果 swf 然后公开一个名为 button1 的属性,您可以执行以下操作:

私有函数 loaderCompleteHandler(event : FlexEvent) : void{var swfLaoder : SWFLoader = SWFLoader(event.target);swfLaoder.content["button1"].addEventListener(MouseEvent.CLICK, test);}

I embedded a swf file in my application

<mx:SWFLoader source="@Embed(source='mod/VideoModule.swf')" width="50" height="50" id="loader" creationComplete="initLoader()" />

now with the help of the flex documentation I wanted to interact with my loaded swf by creating a SystemManager

[Bindable]
    public var loadedSM:SystemManager;

    private function initLoader() : void {
        trace(loader.content);
        loadedSM = SystemManager(loader.content);
        var b: Button = loadedSM.application["button1"] as Button;
        b.addEventListener(MouseEvent.CLICK, test);
    }

But when starting the application the error#1034 occurs and says that Main__embed_mxml_mod_VideoModule_swf_856293516@33f53c1 could not be converted into mx.managers.SystemManager

any ideas?

thanks in advance

Sebastian

解决方案

So firstly i'd use the complete event of SWF loader ad the creationComplete event will fire when swf loader is created, not with it's contents have loaded.

<mx:SWFLoader source="@Embed(source='mod/VideoModule.swf')" width="50" height="50" id="loader" complete="loaderCompleteHandler(event)" />

Then i would also pass the FlexEvent argument when the event fires. That event gives you access to the instance of SWFLoader. SwfLoader then has a property called content which will give you access to the loaded swf. If the swf then exposes a property named button1 you could do something like:

private function loaderCompleteHandler(event : FlexEvent) : void 
{
    var swfLaoder : SWFLoader = SWFLoader(event.target);
    swfLaoder.content["button1"].addEventListener(MouseEvent.CLICK, test);
}

这篇关于与 SWF 加载程序交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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