actionscript-3 - getDefinitionByName() 和类可见性

标签 actionscript-3 apache-flex

我的主应用程序包含ModuleManager。该应用程序加载不同的模块。主应用程序和加载的模块都使用我的自定义 RSL。我需要在 RSL 中获取 Class 对象,该对象是在模块之一中定义的。我正在尝试使用 getDefinitionByName 函数,但由于我的类未在 RSL 中定义,因此出现异常(尽管已加载具有所需类的模块)。是否可以使模块类对 RSL 代码可见并在运行时获取其实例而不更改项目结构?谢谢

最佳答案

如果您在类类型的模块(或其接口(interface))上公开属性,则可以注入(inject)类的定义,类似于将类定义注入(inject)到按钮中以制作图标的方式。

所以,你的模块可能有这样的代码:

protected var _classToMake:Class;

public function get classToMake():Class {
   return _classToMAke;
}

public function set classToMake(value:Class):void {
   if (value != _classTomake) {
      if (value != null) {
         //test to make sure we're making the right thing
         var testClass:SomeType = new value() as SomeType;
         if (testClass != null) {
            _classToMake = value
         } else {
            trace('classToMake must be a definition that makes a class of SomeType');
         }
      }
   }
}

关于actionscript-3 - getDefinitionByName() 和类可见性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9412188/

相关文章:

apache-flex - 柔性 : How to know when a dialog created throw PopUpManager Closes

apache-flex - Flash Builder 4 现在是否使用 AIR 2?

闪光时间拉伸(stretch)

flash - 安全错误: Error #2122: Security sandbox violation

javascript - 外部接口(interface)回调没有监听?

用于 Java 桌面应用程序的 JavaFX、Swing 或 Flex

actionscript-3 - Flash Player 命令行参数为 "Create Projector"

actionscript-3 - 当我运行 Flash 游戏时,图形分辨率会降低

apache-flex - Spring MVC 和 Flex 通过 BlazeDS 集成?

apache-flex - 在 Flex 移动应用程序中从命令行打包时,.apk 文件的大小更大