【问题标题】:Flex: load parent class into moduleFlex:将父类加载到模块中
【发布时间】:2013-01-28 17:54:05
【问题描述】:

我的主应用程序包含一个ClassA。然后主应用程序加载一个模块,在那个模块中我想做:

var classA:InterfaceClassA = new ClassA();

它编译得很好,但我收到了这个警告:

Warning: YourApplication is a module or application that is directly referenced. This will cause YourApplication and all of its dependencies to be linked in with module.YourModule:Module. Using an interface is the recommended practice to avoid this.

我不能使用接口来生成新实例,那么正确的方法是什么?

【问题讨论】:

    标签: apache-flex module


    【解决方案1】:

    我在Accessing the parent application from the modules 中找到了答案。我在主应用程序中创建了一个帮助类,其中包含我要访问的类的实例。然后在我使用的模块中:

    parentApplication.myModuleHelper.**myClassInstance**.myMethod();
    

    对于我使用的实例方法和静态类级方法:

    parentApplication.myModuleHelper.**MyClassInstance**.myMethod()
    

    要在模块中获取我的类的实例,我在 MyModuleHelper 中使用它

    public function getFullScreenUtil(iFullScreenUtil:IFullScreenUtil , iSystemManager:ISystemManager):FullScreenUtil {
        return new FullScreenUtil(iFullScreenUtil , iSystemManager);
    }
    

    这在 MyModule 中:

    var _fullScreenUtil:* = parentApplication.moduleHelper.getFullScreenUtil(this , systemManager);
    

    这就是我现在所需要的。我不确定如何将getFullScreenUtil(..) 的结果转换为FullScreenUtil 的实际实例,但我希望它不能在模块中完成。也许使用接口可以解决这个问题。

    【讨论】:

    • 比这更好的应该是编译主应用时使用-link-report,然后编译模块时使用-load-externs。这应该有效,但对我来说没有。 Flex 类被排除在外,但我在应用程序中的自定义类不在生成的链接报告中。
    猜你喜欢
    • 2020-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-13
    相关资源
    最近更新 更多