getDefinitionByName() 和类可见性
我有包含 ModuleManager
的主应用程序。该应用程序加载不同的模块。主应用程序和加载的模块都使用我的自定义 RSL。我需要在 RSL 中获取 Class 对象,该对象是在模块之一中定义的。我正在尝试使用 getDefinitionByName 函数,但由于我的类未在 RSL 中定义,因此出现异常(尽管已加载具有所需类的模块)。是否可以使模块类对 RSL 代码可见并在运行时获取其实例而不更改项目结构?谢谢
I have main application which contains ModuleManager
. Different modules are loaded by this application. Both main application and loaded modules use my custom RSL. I need to get Class object in my RSL, which is defined in one of the modules. I'm trying to use getDefinitionByName
function, but since my class is not defined in RSL, I get an exception (though module with needed class is loaded). Is it possible to make module classes visible to RSL code and to get the instance of it at runtime without changing project structure? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在类类型的模块(或其接口)上公开属性,则可以注入类的定义,类似于将类定义注入到按钮中以制作图标的方式。
所以,你的模块可能有这样的代码:
You can inject the definition of the Class if you expose a property on the Module (or its Interface) of type Class, similar to how Class definitions are injected into buttons to make the icons.
So, your Module might have code like this:
当加载新模块时,指定应用程序域。正如文档所述:
加载 SWF 时,您可以指定一个应用程序域作为加载程序上下文的一部分。
http://help.adobe.com/en_US /FlashPlatform/reference/actionscript/3/flash/system/ApplicationDomain.html
一旦您获得了模块加载到的应用程序域的引用,您就可以调用
getDefinition()
应用程序域的方法来获取定义,其方式与getDefinitionByName()
大致相同http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/ApplicationDomain.html#getDefinition()
另请参阅以下文档“使用应用程序域”,详细描述了它们的工作原理。
http://help.adobe.com/en_US/as3/dev/WSd75bf4610ec9e22f43855da312214da1d8f-8000.html
这是示例的复制粘贴,以防万一丢失:
When you load a new module, specify an Application Domain. As the document says:
You specify an Application Domain as part of the Loader Context when you load the SWF.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/ApplicationDomain.html
Once you have a reference to the Application Domain that the module is loaded in to, you can call the
getDefinition()
method of the Application Domain to get the definition, in much the same way asgetDefinitionByName()
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/ApplicationDomain.html#getDefinition()
Also see the following document, "Working with Application Domains," for a great description of exactly how they work.
http://help.adobe.com/en_US/as3/dev/WSd75bf4610ec9e22f43855da312214da1d8f-8000.html
And here's a copy paste of the example, just incase is wanders off: