Me again.

 

You are on the correct track with componentized apps, and there are MANY
ways to communicate between components.  First, are you using "Modules"
with a capital "M"?  that is, Flex 2.0.1 mx:Module tag?  If so, you will
have to adjust what I say, since I have not used that approach yet.  If
you are using the word "module" more generically, then read on.

 

The "best practice" approach to inter-component communication is to use
events.  This "loose coupling" permits much more flexibility in reusing,
changing, maintaining components.  But it is a little harder to
understand and implement.  If you want to undertake this we can.

 

If are in a bit of a hurry to get your app working within a reasonably
componentized architecture, and understand that you are creating hard
coded dependencies between the components thae are simpler ways.

 

Obviously, there are  two directions of communication, parent access of
child members, and child access of parent members.  The simplest is
parent to child.  If you give the child component an id, then you can
access any of its public member properties through that id reference.
For example, if your HTTPService code was in a component named
Thumbnail, you could do this:

<Thumbnail id="myThumbnail" .../>

Private function getData():void {

  myThumbnail.srv.url = [EMAIL PROTECTED]; //assuming that xml node
was in this scope

  myThumbnail.srv.send();

 

So you are halfway there, right?

 

Access of the parent scope from within a child is only a bit more
difficult.

 

I am fond of passing references into components.  When you do this, you
can access all of the public members as though they were local.  You can
set or retrieve values and call methods.  (But remember, it locks in a
dependency.)

 

For example, say a display only component, that needs to talk the the
Application, and to the Thumbnail component:

public var dataSourceUrl:String = "http://myserver/mydatasource";

<MyDisplayComponent ... app="{this}"  dataSource="{}" .../>

 

And in that component:

...

[Bindable]public var app:MyApplicationFileName;  //tightly scoping this
is best

[Bindable]public var dataSource:Thumbnail;           //tightly scoping
this is best

 

Private function initApp():void  {

 var sDataSourceUrl:String = app. dataSourceUrl;

  dataSource.srv.url = [EMAIL PROTECTED]; //assuming that xml node
was in this scope

  dataSource.srv.send();

 

This is simple, easy to implement and debug.  But again, keep in mind it
limits component flexibility.

 

Tracy

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of shawn.gibson
Sent: Thursday, March 15, 2007 5:10 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Unbelievably embarassing question - making
components talk (and modules) amongst

 

Thanks to Tracy's earlier help, I was able to get at least the ugly 
(i.e., my) version of HTTPService going (and I'll revisit it to 
Tracy's specs one I figure this here problem out), but in order for 
me to do it, I had to de-compartmentalize all my code. In other 
words, I have originally been using an approach where each 
major 'page' was a module loaded into a state of my main app, and 
each major chunk of a module was made of a custom component (the 
entire Tree, it's code, the little stuff; or the entire thumbnail 
with all it's itemrendering in a HorizontalList...etc)- nice 
separation of code, easy to understand in 6 months, and no 6,000 line 
files. Also offered me a fighting chance in the future to figure out 
model, control, and view separation.

But for me to get (for example) the tree component I made to 
communicate with the thumbnail component, both housed in the 
galleries module, I had to hardcode the components back into the 
module (i.e., they are no longer components), so the module is now 
one big-ass file that has no components, they are right in the file. 

I can't go on like this, it's just too ugly. As a designer and a poet 
wannabe, that sucks LOL.

But I can't for the life of me get things to talk amongst themselves, 
say my module has 3 custom components doing their things...how do I 
access something in one component from another component?

I became very afraid when I realized there doesn't seem to be any 
kind of AS2/Flash dummy-movie approach - loadMovie ('thisthing') into 
dummyclip instance 'whatever' and suddenly you just say 
whatever.thisthing.stuff, and you've gained access to everything. In 
other words, you can jump up and down as long as you know the scope. 
I haven't a clue what the equivalent is in Flex 2.

It's very embarassing. I refuse to get through this weekend without 
figuring it out. I'm not botching my gallery project by having 5-6 
modules (as I DO want) but with thousands of hardcoded chunks within 
them, when each module should by rights have nice piecemealed (sorry 
for the word) custom components doing their thing from their own file 
and from there communicating with each other. I need to use 
components in the modules for my own sanity, and even worse, how do I 
get one module to talk to another module's objects, functions, etc.?

In a word, you can't go from:

[EMAIL PROTECTED];
srv.send();

...strip it out into a component and then call the id of the parent, 
i.e.:

[EMAIL PROTECTED];
thumbloader.srv.send();

...you get "Access of undefined property thumbloader" for your 
troubles...

You can't back up a generation like you could with Flash. Or if you 
can, I'm missing big bits of the puzzle.

Any suggestions, other than take a chill-pill?

Thanks guys,

Shawn

 

Reply via email to