【问题标题】:as3 / flex interface incompatibility when loading external swf加载外部 swf 时 as3 / flex 接口不兼容
【发布时间】:2012-10-19 12:55:17
【问题描述】:

我有一个主项目,我想将另一个项目的 swf 加载到其中:

//loader code in Main class of main project
var url:URLRequest = new URLRequest("../src/components/TextTool.swf");      
var ttWrapper:UIComponent = new UIComponent();
var ldr:SWFLoader = new SWFLoader(); 
var context:LoaderContext   = new LoaderContext();
if (Security.sandboxType == Security.LOCAL_TRUSTED) {
context.applicationDomain   = new ApplicationDomain(ApplicationDomain.currentDomain);
    }         ldr.source = "../src/components/TextTool.swf";
        ldr.loaderContext = context;
        ldr.addEventListener(Event.COMPLETE, onLoadComplete);
        ldr.load();     
        can.addElement(ldr);

这是第二个项目的Main类的代码:

<?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:stark="stark.*" name="textModule" >    
        <stark:TextTool name="myTF" id="myTF"></stark:TextTool>
    </s:Application>

现在两个项目都包含一个接口文件:IModule,具有相同的代码,以及第二个项目(正在加载的那个)的一个元素,它是我的自定义类“TextTool”的一个实例,它扩展了 s:分组并实现 IModule:

<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/mx" width="400"
        xmlns:com="src"
        height="130" creationComplete = "initText()" implements="IModule"></s:Group>

现在,一旦我加载了 swf,我就想访问该 TextTool 实例,该实例的 ID 为“myTF”:

//Code in the main class of the main project
    trace(getQualifiedClassName(mySwf.getChildByName('textModule')['myTF']));
    trace(mySwf.getChildByName('textModule')['myTF'] is IModule);
    //output:

    //stark::TextTool
    //false

正如我上面提到的,我在两个项目中都有接口,相同的代码,相对于主类具有相同的路径,并且 myTF 确实扩展了 IModule。加载 swf 后,我得到了正确的元素,但在验证它是否实现 IModule 时我仍然得到错误。 为什么?

【问题讨论】:

  • 'textModule' 是否表明它实现了任何东西?我想知道编译器是否重命名了一个或两个以防止内存冲突。
  • 'textModule' 没有实现 IModule,你希望编译器重命名什么?

标签: actionscript-3 apache-flex flash external


【解决方案1】:

您正在测试 Application 的实施

trace(mySwf.getChildByName('textModule') is IModule);

我想你忘了加['myTF']

trace(mySwf.getChildByName('textModule')['myTF'] is IModule);

【讨论】:

  • 我的错。看起来我在将 ["myTF"] 复制/粘贴到消息之前进行测试时删除了它。固定。
  • 我做了一个小例子(我使用 FlashDevelop),[au.optimum-web.com:8080/pub/alex/loader_test.rar] 这是 zip,如果你能花几分钟看看我做错了什么? (添加加载的 swf 时单击 stage,您将看到 trace)。
【解决方案2】:

您将两者都加载到不同的应用程序域中,因此先加载者获胜。尝试将它们加载到同一个 ApplicationDomain 中。

【讨论】:

  • 我已将 if (Security.sandboxType == Security.LOCAL_TRUSTED) { 更改为 context.applicationDomain = ApplicationDomain.currentDomain; 以将当前应用程序域提供给加载程序的上下文,但仍然没有成功。你还有别的意思吗?
  • 我说的是这一行 var context:LoaderContext = new LoaderContext();如果您摆脱它并且不使用该参数,会发生什么?
  • 仍然返回 false。我已经用这个senocular's tutorial 尝试了一切。但我让它工作了。我合并了两个项目,所以它们将使用 1 个接口文件,而不是两个单独的文件,尽管它们具有相同的包、名称和代码。尽管如此,用这样的结构做一个项目还是很不舒服,如果有人用我的界面制作一个模块,然后只给我发 swf 怎么办?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-02-03
  • 2011-09-05
  • 1970-01-01
  • 2012-03-31
  • 1970-01-01
  • 1970-01-01
  • 2011-07-17
相关资源
最近更新 更多