[flexcoders] Module Interface Problems

2007-01-17 Thread kristian_wright2002
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:

currentState='Results';
modMyModule2.url='myResults.swf;

and the states look like:

mx:states
mx:State name=Results
mx:AddChild
mx:ModuleLoader id=modMyModule2 ready=readyModule(event)
error=modErrorHandler(event) /
/mx:AddChild
/mx:State
/mx:states

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:

package
{
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?

Cheers,
K. 



RE: [flexcoders] Module Interface Problems

2007-01-17 Thread Roger Gonzalez
For what its worth, it appears at first glance that your code should
work.
 
Have you tried strong typing rather than using *?
 
var results:IResults= IResults(modMyModule2.child)
 
Not sure why it isn't working though, sorry.
 
-rg




From: flexcoders@yahoogroups.com
[mailto:[EMAIL PROTECTED] On Behalf Of kristian_wright2002
Sent: Wednesday, January 17, 2007 6:36 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Module Interface Problems




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:

currentState='Results';
modMyModule2.url='myResults.swf;

and the states look like:

mx:states
mx:State name=Results
mx:AddChild
mx:ModuleLoader id=modMyModule2 ready=readyModule(event)
error=modErrorHandler(event) /
/mx:AddChild
/mx:State
/mx:states

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:

package
{
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?

Cheers,
K.