Hi,
I did a basic search on this topic and read a few posts, but I
think my case seems to be a little different here. I have a fairly
large application that I am designing to be broken into one main
application that loads multiple modules as required.
My main application implements an IMyApp interface with one method
right now:
getModule(modName:String):*
All my modules implement a generic IAppModule interface which includes
2 methods:
-initModule() Called after loading and creation of module
-handleEvent(evt:Event): Called whenever an event such as MenuEvent
etc need to be passed to the module.
Each of the modules implement a specific interface, for eg. Module1
implements IModule1 which extends IAppModule, and Module2 implements
IModule2 which also extends IAppModule to expose specific
functionality within each of the module.
So I have the following package structure and classes with their
interfaces:
1) class a.MyApp implements a.mod.common.IMyApp (My main app)
2) interface a.mod.common.IModule1 extends interface
a.mod.common.IAppModule
3) interface a.mod.common.IModule2 extends interface
a.mod.common.IAppModule
4) class a.mod.mod1.Module1 implements
a.mod.common.IModule1 (Module 1 compiles to Module1.swf)
5) class a.mod.mod2.Module 2 implements
a.mod.common.IModule2 (Module 2 compiles to Module2.swf)
My main application handles the logic of loading all the modules at
starting and as required as runtime and any module requiring access to
another module asks the main application (through the IMyApp
interface) for a handle to the other module.
Here is my problem. I am trying to access IModule2 from within
Module1. I use IMyApp.getModule("Module2") to get a handle to the
second module, but when I try to downcast it to IModule2, it throws me
an error saying it encountered error with the type coercion. In the
error detail it says that it cannot convert
a.mod.mod2.Module2 to a.mod.common.IModule2 which
stumps me as the class implements that specific interface.
If I include all methods from IModule1 and IModule2 into the base
interface IAppModule, remove IModule2 entirely and try to cast the
IMyApp.getModule("Module2") to IAppModule, it works fine, but this is
not what I was looking for. I will end up with one monolithic
IAppModule with every method from every module interface. I am not
sure what I am missing here. Is there a problem with interface
inheritance and modules? When I run a link report for the modules, I
am not sure if I am reading the report right, but I do not see
IModule2 interface as part of the definitions within script Module2.
Can someone please point me in the right direction for this problem?
Thank you for your help,
Purush