I do it a different way than you which you may like to try... private function onReady(e:ModuleEvent):void { var ml:ModuleLoader = e.target as ModuleLoader; // cast the module (the child property of the ModuleLoader) to the // ITest interface. If the child implements this interface // ichild will not be null. var ichild:* = ml.child as ITest; if(ichild != null) { // Pass data to module via interface ichild.somedataiwanttopass = this.thedataiwanttopass; } }
Using this I have never found the child to be null (Although I do check). --- In flexcoders@yahoogroups.com, Philip Smith <loudjazz@...> wrote: > > > >>> var test:ITest ITest(this._moduleLoader.child); // null > > The module implements ITest. Regardless, before the module is cast to an interface, this._moduleLoader.child is null. I read on another thread that the module 'ready' event may be dispatched before it's ready... > > > To: flexcoders@yahoogroups.com > From: valdhorlists@... > Date: Fri, 4 Nov 2011 16:10:22 +0000 > Subject: [flexcoders] Re: ModuleLoader.child is null > > > > > > > > > > > > > > > > > > > > > > > > > > > > > In your module code I don't see where it implements com.storefront.interfaces.controller.ITest. If there is no implementation of the interface, the child will be null. > > > > --- In flexcoders@yahoogroups.com, "method_air" loudjazz@ wrote: > > > > > > Can anyone explain why ModuleLoader.child is null in the module event 'ready' event listener: > > > > > > this._moduleLoader = new ModuleLoader(); > > > this._moduleLoader.url = "ImageComparisonModule.swf"; // > > > this._moduleLoader.addEventListener(ModuleEvent.READY, onReady); > > > > > > private function onReady(e:ModuleEvent):void > > > { > > > var test:ITest ITest(this._moduleLoader.child); // null > > > } > > > > > > Module code: > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > <s:Module xmlns:fx="http://ns.adobe.com/mxml/2009" > > > xmlns:s="library://ns.adobe.com/flex/spark" > > > xmlns:mx="library://ns.adobe.com/flex/mx" > > > implements="com.storefront.interfaces.controller.ITest" > > > > > > > <fx:Declarations> > > > <!-- Place non-visual elements (e.g., services, value objects) here --> > > > </fx:Declarations> > > > > > > <s:VGroup width="100%" /> > > > </s:Module> > > > > > > Cheers, > > > > > > Philip > > > >