3 Replies Latest reply on Jan 29, 2007 3:38 AM by Kristian Wright

    Module Interface Problems

    Kristian Wright Level 1
      I'm having a problem passing variables from one module to another via an interface.

      I have an application that calls a module when it enters a specific state, which works fine. The module is loaded through <mx:ModuleLoader id="modMyModule1" url="myModule1.swf"> and it works as expected.

      Within this module, I have a button that when pressed, calls a second module via a module loader, using an interface. I need an interface, as there is a variable that I need to pass between these two modules. Clicking the button runs a couple of functions, ending with:


      and the states look like:

      <mx:State name="Results">
      <mx:ModuleLoader id="modMyModule2" ready="readyModule(event)" error="modErrorHandler(event)" />

      So when the module is ready, the following code is invoked in modMyModule1:

      private function readyModule(evt:ModuleEvent):void
      var ichild:* = modMyModule2.child as IResults;
      if(ichild != null) { ichild.searchResults = arrSearchResults; trace("NOT NULL"); }
      else { trace("NULL!"); }

      modMyModule2 contains 'implements="IResults"' in it's root module tag, and IResults is defined as follows:

      import flash.events.IEventDispatcher;
      import mx.collections.ArrayCollection;

      public interface IResults extends IEventDispatcher
      function set searchResults(arrResults:ArrayCollection):void;
      function get searchResults():ArrayCollection;

      I have corresponding getter and setter functions in my modMyModule2, but they never seem to get called! For some reason, the interface is always failing, and therefore in my readyModule() function in the first module, it always traces "NULL".

      I can access the required variable in the second module via parentApplication.modMyModule1.child.arrSearchResults, but I'd prefer to do it via the interface.

      I've gone through all the docs, but I can't see what I've done that's different from anything in them, except for the fact that I'm calling a module from a module via an interface.

      Can anyone shed some light on this at all?