HI everyone, I am facing a problem while down casting the flex module. I have created two flex modules called FlexModule1.mxml and FlexModule2.mxml. These both modules contain the same code.
I have placed FlexModule1.mxml under modules folder(modules/FlexModule1.mxml) and FlexModule2.mxlm @ application root. Here is code for FlexModul1.mxlml (and FlexModule2.mxml as both modules have identical code) <?xml version="1.0" encoding="utf-8"?> <mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300"> <mx:Script> <![CDATA[ public function Foo( pstr:String ):String { trace( "In Method Foo" ); return "Foo" + pstr ; } ]]> </mx:Script> <mx:Panel width="100%" height="100%"> <mx:Label id="MY_LABEL" text="I AM MODULE-1" fontSize="20" color="green"/> </mx:Panel> </mx:Module> And here is Main class code. <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="{loadModule()}"> <mx:Script> <![CDATA[ import mx.modules.ModuleManager; import mx.modules.IModuleInfo; import modules.FlexModule1; import mx.events.FlexEvent; import mx.events.ModuleEvent; import mx.modules.ModuleLoader; public var moduleLoader:ModuleLoader; public var moduleInfo:IModuleInfo; public function loadModule( ):void { moduleLoader = new ModuleLoader(); moduleLoader.addEventListener( ModuleEvent.READY , moduleReadyEventHandler ); //moduleLoader.url = "FlexModule2.swf"; //This is fine module loaded moduleLoader.url = "modules\\FlexModule1.swf"; //this fine too moduleLoader.loadModule(); } public function moduleReadyEventHandler( evt:ModuleEvent ):void { trace( "Module Ready Event Handler" ); this.addChild( moduleLoader ); //(moduleLoader.child as FlexModule2).Foo( '' ) ; // this if fine method Foo() called (moduleLoader.child as FlexModule1).Foo( '' ) ; // Null pointer Exception } ]]> </mx:Script> </mx:Application> Both modules are loading without any problem but the error occurs when I try to downcast FlexModule1.mxml. There is no down casting problem with FLexModule2.mxlm. I think the problem is with different folder i have used for FlexModule1.mxml , may b i am wrong. Please let me know where is the problem.