R – Access Modules in Flex

actionscript-3apache-flexflashmodule

I have build a module in Flex that I call myModule, this module has a method myMethod. Now I use the ModuleManager to load this module.

mod = ModuleManager.getModule("myModule.swf");
mod.addEventListener(ModuleEvent.READY, modEventHandler);
mod.load();

now I want to access the method

(customComp as myModule).myMethod()

where customComp is the DisplayObject created by the factore.create() method of the module info. This code will not compile as myModule is not a defined property. Can someone help me with that? What do I have to import? The myModule.swf is not an asset, it lies in the bin directory of my project.

Thanks in advance

Sebastian

Best Answer

I'm not entirely sure how the module manager works. But generally I use a module loader to display my modules. However there were only 2 ways I have seen to access a modules functions.

You can access the function directly by:

mod.child.myMethod();

Or you need to create an interface for that module.

var ichild:* = mod.child as IMyModule;
ichild.myMethod();

More info can be found here

I believe accessing the module directly like in the first example should work however I always use an interface.

Hope this helps.

Related Topic