--- In flexcoders@yahoogroups.com, Martyn Bowis <mar...@...> wrote:
>
> Hi Jules,
> 
> Object Oriented programming in my mind is about making use of 
references 
> to objects.  With this in mind, here is a way I use to centralise 
common 
> functionality (functions) that I can access throughout my 
application:
> 
> 1. Create an object in the Application mxml file - this will be 
> referenced throughout your application components
> eg: objApp:Object = new Object();
> 
> 2. Create functions inside a script block in the Application mxml 
file
> eg:
> public function myUsefulFunction(): void {
> ...
> }
> 
> 3. Add references to my functions to objApp object - no () after 
the 
> function name as it is a reference to it, not a call to it
> eg: objApp.myUsefulFunction = myUsefulFunction;
> 
> I can also include function classes here and make reference to 
their 
> functions
> 
> 4. Pass objApp as a reference to each component - I must be sure 
that 
> the deepest component is chained back to the Application mxml by 
passing 
> this reference through all its parents
> eg: <comp:mypanel id="" objApp="{objApp}" .... />
> 
> 5. Inside each component, bind objApp

This seems to me to be an ideal recipe for making your application 
tightly coupled.  Before you commit to changing your architecture in 
this way, please check out these links:

http://www.adobe.com/devnet/flex/articles/loose_coupling.html 
http://www.adobe.com/devnet/flex/articles/graduating_pt1.html

A more standard way to handle this type of thing is to use events to 
notify the application that it needs to do something--and letting the 
application figure out what that something is.

HTH;

Amy

Reply via email to