RE: [flexcoders] passing parameters to components

2008-04-24 Thread Gordon Smith
Technically, there is no problem in AS3 with writing a setter without a
getter to implement a write-only property. But I consider write-only
properties to be poor API design. Being able to set something -- but not
ask later what it was you set -- is weird. If I need to know the value
that I set, I shouldn't have to store it myself.

 

Gordon Smith

Adobe Flex SDK Team

 



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Kevin
Sent: Thursday, April 24, 2008 6:53 AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] passing parameters to components

 

I am wondering why this is weird?  Could there be a case where someone
wanted to have a write-only property?  I agree that it is pretty
uncommon, but I am wondering if it problematic from an architecture
standpoint?

 

- Kevin

 

On Apr 22, 2008, at 8:37 PM, Gordon Smith wrote:





(BTW, setters without getters are weird.)

 

 



Re: [flexcoders] passing parameters to components

2008-04-24 Thread Kevin
I am wondering why this is weird?  Could there be a case where  
someone wanted to have a write-only property?  I agree that it is  
pretty uncommon, but I am wondering if it problematic from an  
architecture standpoint?


- Kevin

On Apr 22, 2008, at 8:37 PM, Gordon Smith wrote:


(BTW, setters without getters are weird.)




RE: [flexcoders] passing parameters to components

2008-04-23 Thread Tracy Spratt
Thanks, Gordon.  I think I knew most of that, and feel the same way
about the confusing language ("sibling"), but I have not had a chance to
edit the write up yet.

 

I will try very hard to incorporate your corrections and suggestions
before I post it again.

 

Tracy

 



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Gordon Smith
Sent: Tuesday, April 22, 2008 11:27 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] passing parameters to components

 

Hi, Tracy.

 

Nice writeup! I have a few comments...

 

1. The phrase "sibling child controls" seems confusing to me. You might
have a structure like

 









...





 

which creates myTextInput and myButton as "sibling" reference vars in
the application's scope, despite the fact that the MyTextInput and
MyButton instances aren't siblings in the DisplayObject hierarchy the
MyButton instance isn't a direct child of the application.

 

Also, saying that the controls share the same scope -- as opposed to
their reference vars being in the same scope -- could make some people
think that the scope for MyTextInput's 

RE: [flexcoders] passing parameters to components

2008-04-22 Thread Gordon Smith
Hi, Tracy.

 

Nice writeup! I have a few comments...

 

1. The phrase "sibling child controls" seems confusing to me. You might
have a structure like

 









...





 

which creates myTextInput and myButton as "sibling" reference vars in
the application's scope, despite the fact that the MyTextInput and
MyButton instances aren't siblings in the DisplayObject hierarchy the
MyButton instance isn't a direct child of the application.

 

Also, saying that the controls share the same scope -- as opposed to
their reference vars being in the same scope -- could make some people
think that the scope for MyTextInput's 

RE: [flexcoders] passing parameters to components

2008-04-22 Thread Tracy Spratt
There are many ways.  Below is a document I started, but have not
polished, but should be of some use.

Tracy

 

Communicating between Components:

 

Note: for "loose coupling" use events.  But that is another topic.

 

A non-trivial flex application is "component" based. While all of the
built-in controls are components, the question of communicating between
components most often arises when you are using a custom component. A
custom component, whether implemented in mxml or ActionScript, has its
own "scope". Within that component (Application is a component too!),
all sibling child controls share the same scope, so you can refer to
controls by their id.  If the controls(components) have public
properties or methods, you can reference those members directly through
the id:





 

Ok, so far, its a "duh" right?

 

When you use custom components in a Flex app, at run time they make a
document object model hierarchy (DOM).  Each subcomponent has its own
scope and code within that component can't *directly* reference the
member properties or methods of its sibling subcomponents.

 

So again, within a component, code can reference children  directly, as
in the example above.  But there are two other cases inherent in a
hierarchy.  You might want to reference "up", to get to public members
of the parent, grandparent, etc, or 'down", to get to a "grandchild".

 

Accessing members in the parent:

On an ordinary component DOM, you can reference the parent component
using the .parent property.  Say that a control with id="textinput1"
exists in the parent of the current component.  then you could do:



 

Accessing members in the main application:

Components can be nested, sometimes very deeply.  If the reference you
want is all the way at the top-level, main application (the one with the
 tag), you could do
{parent.parent.parent.textinput1.text}, but you would have to count the
component levels just right.  Instead, you can use
Application.application to get to that scope:



You can shoretn this style of reference by importing
mx.core.Application, and assigning Application.application to a
variable, like _app, the doing (_app.textinput1.text)

 

Accessing components of a child component ("grandchildren"):

Say that in this case, a child component has the TextInput control you
want to reference.  First, make sure the child component has an id:



Then, in the same scope (the same component/file that contains "mycc1"
above) you can say:



 

Accessing a nested component:

As mentioned above you can go "up" the hierarchy using
"parent.parent...".  You can also go "down" the hirearchy using id
references:



 

Additional notes:

If you are using SWFLoader to load an entire Application, you can
reference the immediate parent application using "parentDocument".  You
can also use Application.application to reach the main app, as shown
above.

 

Accessing members of an application loaded by SWFLoader is a bit more
complicated.  See the example here:

http://www.cflex.net/showFileDetails.cfm?ObjectID=690

 

 



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Luke Vanderfluit
Sent: Tuesday, April 22, 2008 7:08 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] passing parameters to components

 

Hi.

I have a flex application that gets called from an html link and is
passed a 
parameter. The param is personid.

I retrieve the parameter in the flex application (BrowserManager).
So I have access to it in the main application file.

I have a number of components within the main application, that do
server 
requests. In some of those requests I need to pass the personid (that I
have 
retrieved from the browser url).

My question is:

What is the accepted method of passing variables (params) between
components, 
specifically, in this case, from parent to child component?

Thanks for your responses.

Kind regards.
Luke.

-- 
Luke Vanderfluit
Analyst / Web Programmer
e3Learning.com.au
08 8221 6422

 



RE: [flexcoders] passing parameters to components

2008-04-22 Thread Gordon Smith
Any component can retrieve an application parameter as
Application.application.parameter.personid. There is no point in pushing
a parameter like this down into every component. It is stored on the
Application instance and components should access it there instead of
keeping redundant copies of this information.

 

If you really want to pass it down to SiteList, you can simply declare a
public var rather than writing a setter. (BTW, setters without getters
are weird.) And if you do write a setter, the convention is to name it
personID, not setPersonID (and to name its private storage var
_personID).

 

Gordon Smith

Adobe Flex SDK Team

 



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Luke Vanderfluit
Sent: Tuesday, April 22, 2008 4:57 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] passing parameters to components

 

Hi.

In partial answer to my own question (and not seem a complete and utter
idiot) 
here's what Im currently doing:

In my component (SiteList) I have a setter function:

private var personId:String;
public function set setPersonId(p:String):void {
personId = p;
}

In my main component:


Is this the recommended way?
What are the alternatives?

Thanks again.

Kr.
Luke.

Luke Vanderfluit wrote:
> Hi.
> 
> I have a flex application that gets called from an html link and is
passed a 
> parameter. The param is personid.
> 
> I retrieve the parameter in the flex application (BrowserManager).
> So I have access to it in the main application file.
> 
> I have a number of components within the main application, that do
server 
> requests. In some of those requests I need to pass the personid (that
I have 
> retrieved from the browser url).
> 
> My question is:
> 
> What is the accepted method of passing variables (params) between
components, 
> specifically, in this case, from parent to child component?
> 
> Thanks for your responses.
> 
> Kind regards.
> Luke.
> 

-- 
Luke Vanderfluit
Analyst / Web Programmer
e3Learning.com.au
08 8221 6422

 



Re: [flexcoders] passing parameters to components

2008-04-22 Thread Luke Vanderfluit
Hi.

In partial answer to my own question (and not seem a complete and utter idiot) 
here's what Im currently doing:

In my component (SiteList) I have a setter function:

private var personId:String;
public function set setPersonId(p:String):void {
personId = p;
}

In my main component:


Is this the recommended way?
What are the alternatives?

Thanks again.

Kr.
Luke.

Luke Vanderfluit wrote:
> Hi.
> 
> I have a flex application that gets called from an html link and is passed a 
> parameter. The param is personid.
> 
> I retrieve the parameter in the flex application (BrowserManager).
> So I have access to it in the main application file.
> 
> I have a number of components within the main application, that do server 
> requests. In some of those requests I need to pass the personid (that I have 
> retrieved from the browser url).
> 
> My question is:
> 
> What is the accepted method of passing variables (params) between components, 
> specifically, in this case, from parent to child component?
> 
> Thanks for your responses.
> 
> Kind regards.
> Luke.
> 


-- 
Luke Vanderfluit
Analyst / Web Programmer
e3Learning.com.au
08 8221 6422