RE: [flexcoders] Need primer on Events, from the List Gurus -

2007-01-17 Thread Mike Anderson
Thank you Dimitrios!
 
Now it all makes sense to me - the key is using the Getters and Setters as the 
method for handling all the value assignments.  Once you do that, you have all 
the CollectionEvents at your disposal.
 
So I guess in some odd way, we are still using Event Broadcasting to accomplish 
my goals, but just not in the way that I envisioned doing it.
 
Very nice :)
 
Again, thanks for the wonderful advice -
 
Mike



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of 
Dimitrios Gianninas
Sent: Sunday, January 14, 2007 11:29 AM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Need primer on Events, from the List Gurus -


Ok here is how I would do it. Say the ArrayCollection held notes as an example.
 
// in command
ModelLocator.getInstance().notes.addItem( mynewnote );
 
// view is binded
bla:MYView notes={ModelLocator.getInstance().notes}/
 
// inside the view
public function set notes( values:ArrayCollection ):void {
   mygrid.dataProvider = values;
   values.addEventListener( CollectionEvent.COLLECTION_CHANGE, 
onCollectionChange );
}
 
Now what will happen is the minute you add a new note to your model, the 
onCollectionChange method will be called and that will allow you to do any 
added operations you wish, hope that helps.
 
Dimitrios Gianninas
RIA Developer
Optimal Payments Inc.
 



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Mike 
Anderson
Sent: Friday, January 12, 2007 11:03 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Need primer on Events, from the List Gurus -



Hello Dimitrios,
 
I was trying to keep my post as generic as possible - which is why I didn't 
post specifics.
 
In this particular instance however, I want to broadcast a Custom Event to a 
DataGrid residing on a Panel Control - to Scroll to the very top, whenever I 
add a new record to an ArrayCollection (residing in the ModelLocater).  This 
can happen ONLY when I add a new record - and this is why I want to create a 
Custom Event for this.  I am pushing for a Custom Event, because I don't think 
there is a built-in Event native to the DataGrid, that I can count on 100% of 
the time, to fire off ONLY when New Records are being added.
 
The catch is, I can't dispatch the Event until I get my onResult response from 
the ColdFusion Server - indicating that the Database Insert was in fact 
successful, and that it's now okay to update the Model's ArrayCollection with 
the new ValueObject.
 
Since the onResult logic resides in a Cairngorm Command Class, this is where I 
need to dispatch the Event from.  Or at least initiate the command to dispatch 
the Event, which can reside in the ModelLocater - and dispatch it from there.
 
Since all of my primary Views containing the Model-bound Controls, have a 
reference to the ModelLocater, I am thinking that there must be a way to 
dispatch these Events from the Model - and have a way for these Views to 
respond accordingly.
 
If you could help me out in this regard, I really would be truly grateful.  My 
application development, has literally come to a screeching HALT, because of me 
not knowing how to handle all these issues.
 
I am tracking down every Event Broadcaster and Listener Tutorial I can get my 
hands on, so that I can learn more about how all this works.  But in all of the 
examples I download and dissect, they ALL have a common View, that centralizes 
the code - in which it's quite easy to tie everything together.
 
In my case, I have Views and Controls scattered all over the place - and they 
can be instantiated (or not be for that matter) at any given moment.  I just 
don't know how to write code to broadcast Events in such a manner, so that each 
component has no prior knowledge of any other component.
 
I hope I'm explaining all this properly...
 
Thanks in advance,
 
Mike



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of 
Dimitrios Gianninas
Sent: Friday, January 12, 2007 3:01 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Need primer on Events, from the List Gurus -


what other thing do u want to do? give an example and we can take it from 
there.
 
Dimitrios Gianninas
RIA Developer
Optimal Payments Inc.
 



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Mike 
Anderson
Sent: Friday, January 12, 2007 1:53 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Need primer on Events, from the List Gurus -



Hello All,

This thread, directly relates to all the other ones I've posted recently
- as I think one of my root problems, is truly understanding on how
Events get propagated within an application.

They say the Event model is so great, due to all the components being so
loosely coupled. So either I am missing something really rudimentary
here, or the Event model doesn't work the way I thought

RE: [flexcoders] Need primer on Events, from the List Gurus -

2007-01-14 Thread Dimitrios Gianninas
Ok here is how I would do it. Say the ArrayCollection held notes as an example.
 
// in command
ModelLocator.getInstance().notes.addItem( mynewnote );
 
// view is binded
bla:MYView notes={ModelLocator.getInstance().notes}/
 
// inside the view
public function set notes( values:ArrayCollection ):void {
   mygrid.dataProvider = values;
   values.addEventListener( CollectionEvent.COLLECTION_CHANGE, 
onCollectionChange );
}
 
Now what will happen is the minute you add a new note to your model, the 
onCollectionChange method will be called and that will allow you to do any 
added operations you wish, hope that helps.
 
Dimitrios Gianninas
RIA Developer
Optimal Payments Inc.
 



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Mike 
Anderson
Sent: Friday, January 12, 2007 11:03 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Need primer on Events, from the List Gurus -



Hello Dimitrios,
 
I was trying to keep my post as generic as possible - which is why I didn't 
post specifics.
 
In this particular instance however, I want to broadcast a Custom Event to a 
DataGrid residing on a Panel Control - to Scroll to the very top, whenever I 
add a new record to an ArrayCollection (residing in the ModelLocater).  This 
can happen ONLY when I add a new record - and this is why I want to create a 
Custom Event for this.  I am pushing for a Custom Event, because I don't think 
there is a built-in Event native to the DataGrid, that I can count on 100% of 
the time, to fire off ONLY when New Records are being added.
 
The catch is, I can't dispatch the Event until I get my onResult response from 
the ColdFusion Server - indicating that the Database Insert was in fact 
successful, and that it's now okay to update the Model's ArrayCollection with 
the new ValueObject.
 
Since the onResult logic resides in a Cairngorm Command Class, this is where I 
need to dispatch the Event from.  Or at least initiate the command to dispatch 
the Event, which can reside in the ModelLocater - and dispatch it from there.
 
Since all of my primary Views containing the Model-bound Controls, have a 
reference to the ModelLocater, I am thinking that there must be a way to 
dispatch these Events from the Model - and have a way for these Views to 
respond accordingly.
 
If you could help me out in this regard, I really would be truly grateful.  My 
application development, has literally come to a screeching HALT, because of me 
not knowing how to handle all these issues.
 
I am tracking down every Event Broadcaster and Listener Tutorial I can get my 
hands on, so that I can learn more about how all this works.  But in all of the 
examples I download and dissect, they ALL have a common View, that centralizes 
the code - in which it's quite easy to tie everything together.
 
In my case, I have Views and Controls scattered all over the place - and they 
can be instantiated (or not be for that matter) at any given moment.  I just 
don't know how to write code to broadcast Events in such a manner, so that each 
component has no prior knowledge of any other component.
 
I hope I'm explaining all this properly...
 
Thanks in advance,
 
Mike



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of 
Dimitrios Gianninas
Sent: Friday, January 12, 2007 3:01 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Need primer on Events, from the List Gurus -


what other thing do u want to do? give an example and we can take it from 
there.
 
Dimitrios Gianninas
RIA Developer
Optimal Payments Inc.
 



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Mike 
Anderson
Sent: Friday, January 12, 2007 1:53 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Need primer on Events, from the List Gurus -



Hello All,

This thread, directly relates to all the other ones I've posted recently
- as I think one of my root problems, is truly understanding on how
Events get propagated within an application.

They say the Event model is so great, due to all the components being so
loosely coupled. So either I am missing something really rudimentary
here, or the Event model doesn't work the way I thought it did.

In every example I've seen, for an Event Listener and Broadcaster setup
to work properly, there must be a common link (like a container) between
the 2 components - and then, there are the 3 key things which must be in
place: The Event Listener, the Broadcaster, and the Function that gets
run whenever the Event gets triggered.

But what about the times, where I won't know for sure beforehand, which
component I will be using at the time? Especially in a Cairngorm
Application, where the Commands (which is where I desperately need to
broadcast my Custom Events from) literally NEVER know where their Result
Events are going to be sent. Of course, this is where the true power of
Cairngorm-based

Re: [flexcoders] Need primer on Events, from the List Gurus -

2007-01-13 Thread Ralf Bokelberg

Hi Mike,

one point of MVC is, that the model is not aware of any views.
If you want to trigger some view function from the Model, you have to set
some property of the model and bind the view to it.
One nice way to do this, is AC's Observe tag. See
http://weblogs.macromedia.com/auhlmann/archives/2006/09/using_binding_s.cfm#more
for the details.

Cheers,
Ralf.

On 1/13/07, Mike Anderson [EMAIL PROTECTED] wrote:


  With what you said, it pretty much backs up what I already knew to be
true.

When it comes to the basics, I am pretty well-versed with Data Binding -
and of course, writing some pretty extensive Cairngorm-based RIA, I have
a pretty good handle on the flow of things.

I guess what is making me second guess what I know about Events, is the
fact that I can't get this damn thing to work. I am scratching my head
on this, and can't figure out what I am missing.

Take this simple example:

Main Application
View1
View2

In View1, I have a basic Panel with a DataGrid. I have a Bindable
public var (myArrayCollection), and assigned it as the dataSource for my
Grid. In my AS Code, I created a var referencing my ModelLocater. Then
I set local myArrayCollection var equal to model.myArrayCollection.
This takes care of all the var declarations, as well as properly
dataBinding it to the Model.

Everything is great - data updates perfect, yada yada yada...

Now I want to add 1 more piece of functionality - broadcast an event, to
make my Grid scroll to the top, after a new record is added. Sounds
easy enough...

Here is what I added to make this happen:

1) Added an eventListener to View1, that listens for scrollGrid -
which gets attached to the appropriate function (scrolling the Grid to
the very top).

2) Added extra logic to my Cairngorm getDataCommand Command - which I
put in the onResult Event Function. The code to call the function
(because the function resides in my ModelLocater) is
model.fireOffScrollEvent. The function simply dispatches a generic
Event (with the Event String being scrollGrid).

Now here is where I get confused:

Other than the simple variable reference in View1 to ModelLocater, there
is nothing else tying these 2 Classes together. I say Classes, because
Controls in essence are simply Classes, in addition to the fact that
ModelLocater really doesn't extend anything.

So now, when I dispatch the scrollGrid Event from inside of
ModelLocater, nothing happens on View1. See, this is where my
understanding of Events, falls terribly short.

See, in the times like this, I am not sure how the Application
propagates these Events. When an Event gets dispatched, does Flex
systematically broadcast it to each and every component??

What confuses me too, is all the scoping stuff - which was a really big
deal in Flash. In Flex, you don't use any dot-notation to specify
where the Event should go (like
Application.application.View1.myDataGrid) - it just goes somewhere out
there - like a black hole some place. When they mention bubbling, I
thought this meant just that -

Since this isn't working for me, I am obviously doing something wrong.
So the question is, what extra code must I add, to make the ModelLocater
aware of View1 and vice versa?

Thanks in advance for your time on this -

Mike

-Original Message-
From: flexcoders@yahoogroups.com flexcoders%40yahoogroups.com [mailto:
flexcoders@yahoogroups.com flexcoders%40yahoogroups.com] On
Behalf Of Brian
Sent: Friday, January 12, 2007 11:10 PM
To: flexcoders@yahoogroups.com flexcoders%40yahoogroups.com
Subject: Re: [flexcoders] Need primer on Events, from the List Gurus -

Maybe the following will help.

Data Binding is really just a short hand version of an event broadcast,
and listener and function to be executed.

Take the example:

[Bindable]
private var lastname:String;

mx:Text text={lastname}/

mx:Button click=lastname='My last Name'/

--
When the button is click the variable lastname value is updated to 'my
last name'.

Since lastname is Bindable, it dispatches an event (broadcaster) that
the value has changed. Any control listening to the change event,
receives the event and runs a function to updates the property text to
the new value. This of course, invalidates the display which then the
display gets updated.

The Bindable metatag creates a dispatch change event (Broadcaster)

The {lastname} creates a listener for the text control to listen to the
lastname change event

A function is created that updates the property, text in this case, to
the new value of last name.

I am sure it is more complicated than this (A function can also be
Bindable, how does the function know when it changes value?).

You can implement data binding using the event model. It might be a
good exercise, but you would not want to do it this way in an
application.

I know the above helped me greatly in understanding the events model. I
hope it helps.

To answer your question
But what about the times, where I won't know for sure beforehand, which
component I

[flexcoders] Need primer on Events, from the List Gurus -

2007-01-12 Thread Mike Anderson
Hello All,

This thread, directly relates to all the other ones I've posted recently
- as I think one of my root problems, is truly understanding on how
Events get propagated within an application.

They say the Event model is so great, due to all the components being so
loosely coupled.  So either I am missing something really rudimentary
here, or the Event model doesn't work the way I thought it did.

In every example I've seen, for an Event Listener and Broadcaster setup
to work properly, there must be a common link (like a container) between
the 2 components - and then, there are the 3 key things which must be in
place: The Event Listener, the Broadcaster, and the Function that gets
run whenever the Event gets triggered.

But what about the times, where I won't know for sure beforehand, which
component I will be using at the time?  Especially in a Cairngorm
Application, where the Commands (which is where I desperately need to
broadcast my Custom Events from) literally NEVER know where their Result
Events are going to be sent.  Of course, this is where the true power of
Cairngorm-based Applications comes into play.

All the Commands do really, is update the ModelLocater with their
updated results - and because of Data Binding, the Components in the
Application show the updated results.  For me unfortunately, there is
always much more that needs to be done, after a Result is brought back -
and I need to find a way to tell my Application Components, to perform
their next task (based on a Custom Event, that I broadcast).

Can anybody show me how to Broadcast Events in such a manner, that they
get disseminated Application-wide???  This way, I don't need to know
beforehand, which Components will be Receiving the Events.

This is the final thing on my plate that I must figure out, then I can
FINALLY finish my app and find some peace in my life

Thanks in advance,

Mike




RE: [flexcoders] Need primer on Events, from the List Gurus -

2007-01-12 Thread Dimitrios Gianninas
what other thing do u want to do? give an example and we can take it from 
there.
 
Dimitrios Gianninas
RIA Developer
Optimal Payments Inc.
 



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Mike 
Anderson
Sent: Friday, January 12, 2007 1:53 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Need primer on Events, from the List Gurus -



Hello All,

This thread, directly relates to all the other ones I've posted recently
- as I think one of my root problems, is truly understanding on how
Events get propagated within an application.

They say the Event model is so great, due to all the components being so
loosely coupled. So either I am missing something really rudimentary
here, or the Event model doesn't work the way I thought it did.

In every example I've seen, for an Event Listener and Broadcaster setup
to work properly, there must be a common link (like a container) between
the 2 components - and then, there are the 3 key things which must be in
place: The Event Listener, the Broadcaster, and the Function that gets
run whenever the Event gets triggered.

But what about the times, where I won't know for sure beforehand, which
component I will be using at the time? Especially in a Cairngorm
Application, where the Commands (which is where I desperately need to
broadcast my Custom Events from) literally NEVER know where their Result
Events are going to be sent. Of course, this is where the true power of
Cairngorm-based Applications comes into play.

All the Commands do really, is update the ModelLocater with their
updated results - and because of Data Binding, the Components in the
Application show the updated results. For me unfortunately, there is
always much more that needs to be done, after a Result is brought back -
and I need to find a way to tell my Application Components, to perform
their next task (based on a Custom Event, that I broadcast).

Can anybody show me how to Broadcast Events in such a manner, that they
get disseminated Application-wide??? This way, I don't need to know
beforehand, which Components will be Receiving the Events.

This is the final thing on my plate that I must figure out, then I can
FINALLY finish my app and find some peace in my life

Thanks in advance,

Mike



 

-- 
WARNING
---
This electronic message and its attachments may contain confidential, 
proprietary or legally privileged information, which is solely for the use of 
the intended recipient.  No privilege or other rights are waived by any 
unintended transmission or unauthorized retransmission of this message.  If you 
are not the intended recipient of this message, or if you have received it in 
error, you should immediately stop reading this message and delete it and all 
attachments from your system.  The reading, distribution, copying or other use 
of this message or its attachments by unintended recipients is unauthorized and 
may be unlawful.  If you have received this e-mail in error, please notify the 
sender.

AVIS IMPORTANT
--
Ce message électronique et ses pièces jointes peuvent contenir des 
renseignements confidentiels, exclusifs ou légalement privilégiés destinés au 
seul usage du destinataire visé.  L'expéditeur original ne renonce à aucun 
privilège ou à aucun autre droit si le présent message a été transmis 
involontairement ou s'il est retransmis sans son autorisation.  Si vous n'êtes 
pas le destinataire visé du présent message ou si vous l'avez reçu par erreur, 
veuillez cesser immédiatement de le lire et le supprimer, ainsi que toutes ses 
pièces jointes, de votre système.  La lecture, la distribution, la copie ou 
tout autre usage du présent message ou de ses pièces jointes par des personnes 
autres que le destinataire visé ne sont pas autorisés et pourraient être 
illégaux.  Si vous avez reçu ce courrier électronique par erreur, veuillez en 
aviser l'expéditeur.



RE: [flexcoders] Need primer on Events, from the List Gurus -

2007-01-12 Thread Mike Anderson
Hello Dimitrios,
 
I was trying to keep my post as generic as possible - which is why I didn't 
post specifics.
 
In this particular instance however, I want to broadcast a Custom Event to a 
DataGrid residing on a Panel Control - to Scroll to the very top, whenever I 
add a new record to an ArrayCollection (residing in the ModelLocater).  This 
can happen ONLY when I add a new record - and this is why I want to create a 
Custom Event for this.  I am pushing for a Custom Event, because I don't think 
there is a built-in Event native to the DataGrid, that I can count on 100% of 
the time, to fire off ONLY when New Records are being added.
 
The catch is, I can't dispatch the Event until I get my onResult response from 
the ColdFusion Server - indicating that the Database Insert was in fact 
successful, and that it's now okay to update the Model's ArrayCollection with 
the new ValueObject.
 
Since the onResult logic resides in a Cairngorm Command Class, this is where I 
need to dispatch the Event from.  Or at least initiate the command to dispatch 
the Event, which can reside in the ModelLocater - and dispatch it from there.
 
Since all of my primary Views containing the Model-bound Controls, have a 
reference to the ModelLocater, I am thinking that there must be a way to 
dispatch these Events from the Model - and have a way for these Views to 
respond accordingly.
 
If you could help me out in this regard, I really would be truly grateful.  My 
application development, has literally come to a screeching HALT, because of me 
not knowing how to handle all these issues.
 
I am tracking down every Event Broadcaster and Listener Tutorial I can get my 
hands on, so that I can learn more about how all this works.  But in all of the 
examples I download and dissect, they ALL have a common View, that centralizes 
the code - in which it's quite easy to tie everything together.
 
In my case, I have Views and Controls scattered all over the place - and they 
can be instantiated (or not be for that matter) at any given moment.  I just 
don't know how to write code to broadcast Events in such a manner, so that each 
component has no prior knowledge of any other component.
 
I hope I'm explaining all this properly...
 
Thanks in advance,
 
Mike



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of 
Dimitrios Gianninas
Sent: Friday, January 12, 2007 3:01 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Need primer on Events, from the List Gurus -


what other thing do u want to do? give an example and we can take it from 
there.
 
Dimitrios Gianninas
RIA Developer
Optimal Payments Inc.
 



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Mike 
Anderson
Sent: Friday, January 12, 2007 1:53 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Need primer on Events, from the List Gurus -



Hello All,

This thread, directly relates to all the other ones I've posted recently
- as I think one of my root problems, is truly understanding on how
Events get propagated within an application.

They say the Event model is so great, due to all the components being so
loosely coupled. So either I am missing something really rudimentary
here, or the Event model doesn't work the way I thought it did.

In every example I've seen, for an Event Listener and Broadcaster setup
to work properly, there must be a common link (like a container) between
the 2 components - and then, there are the 3 key things which must be in
place: The Event Listener, the Broadcaster, and the Function that gets
run whenever the Event gets triggered.

But what about the times, where I won't know for sure beforehand, which
component I will be using at the time? Especially in a Cairngorm
Application, where the Commands (which is where I desperately need to
broadcast my Custom Events from) literally NEVER know where their Result
Events are going to be sent. Of course, this is where the true power of
Cairngorm-based Applications comes into play.

All the Commands do really, is update the ModelLocater with their
updated results - and because of Data Binding, the Components in the
Application show the updated results. For me unfortunately, there is
always much more that needs to be done, after a Result is brought back -
and I need to find a way to tell my Application Components, to perform
their next task (based on a Custom Event, that I broadcast).

Can anybody show me how to Broadcast Events in such a manner, that they
get disseminated Application-wide??? This way, I don't need to know
beforehand, which Components will be Receiving the Events.

This is the final thing on my plate that I must figure out, then I can
FINALLY finish my app and find some peace in my life

Thanks in advance,

Mike



AVIS IMPORTANT

WARNING

Ce message électronique et ses pièces jointes peuvent contenir des 
renseignements confidentiels, exclusifs ou légalement

Re: [flexcoders] Need primer on Events, from the List Gurus -

2007-01-12 Thread Brian
Maybe the following will help.

Data Binding is really just a short hand version of an event broadcast, and 
listener and function to be executed.

Take the example:

[Bindable]
private var lastname:String;

mx:Text text={lastname}/

mx:Button click=lastname='My last Name'/

--
When the button is click the variable lastname value is updated to 'my last 
name'.

Since lastname is Bindable, it dispatches an event (broadcaster) that the value 
has changed. Any control listening to the change event, receives the event and 
runs a function to updates the property text to the new value. This of course, 
invalidates the display which then the display gets updated. 

The Bindable metatag creates a dispatch change event  (Broadcaster)

The {lastname} creates a listener for the text control to listen to the 
lastname change event 

A function is created that updates the property, text in this case, to the new 
value of last name.

I am sure it is more complicated than this (A function can also be Bindable, 
how does the function know when it changes value?). 

You can implement data binding using the event model.  It might be a good 
exercise, but you would not want to do it this way in an application. 

I know the above helped me greatly in understanding the events model. I hope it 
helps.

To answer your question 
But what about the times, where I won't know for sure beforehand, which 
component I will be using at the time?  

Using the above data binding example, data binding has no knowledge of what 
component will be using data binding. Data binding can be used on just about 
any component property. Again, data binding is a short hand of an event model 
and each component doesn't care what component will be used. 


The event model loosely couples the components, but both components must know 
about the event model.  Any component that creates an event listener and the 
function that should be executed when that event is triggered. The component 
must know about the event structure. The component that dispatches the event 
must also know the event structure. The event becomes an API, so to speak. Any 
component can listen or dispatch to that api. In other words, the event itself 
is communication between the two components and both components must know how 
to speak and listen to the event.


---


On Fri, 12 Jan 2007 12:53:14 -0600, Mike Anderson wrote:
 Hello All,

 This thread, directly relates to all the other ones I've posted recently
 - as I think one of my root problems, is truly understanding on how
 Events get propagated within an application.

 They say the Event model is so great, due to all the components being so
 loosely coupled.  So either I am missing something really rudimentary
 here, or the Event model doesn't work the way I thought it did.

 In every example I've seen, for an Event Listener and Broadcaster setup
 to work properly, there must be a common link (like a container) between
 the 2 components - and then, there are the 3 key things which must be in
 place: The Event Listener, the Broadcaster, and the Function that gets
 run whenever the Event gets triggered.

 But what about the times, where I won't know for sure beforehand, which
 component I will be using at the time?  Especially in a Cairngorm
 Application, where the Commands (which is where I desperately need to
 broadcast my Custom Events from) literally NEVER know where their Result
 Events are going to be sent.  Of course, this is where the true power of
 Cairngorm-based Applications comes into play.

 All the Commands do really, is update the ModelLocater with their
 updated results - and because of Data Binding, the Components in the
 Application show the updated results.  For me unfortunately, there is
 always much more that needs to be done, after a Result is brought back -
 and I need to find a way to tell my Application Components, to perform
 their next task (based on a Custom Event, that I broadcast).

 Can anybody show me how to Broadcast Events in such a manner, that they
 get disseminated Application-wide???  This way, I don't need to know
 beforehand, which Components will be Receiving the Events.

 This is the final thing on my plate that I must figure out, then I can
 FINALLY finish my app and find some peace in my life

 Thanks in advance,

 Mike



RE: [flexcoders] Need primer on Events, from the List Gurus -

2007-01-12 Thread Mike Anderson
With what you said, it pretty much backs up what I already knew to be
true.

When it comes to the basics, I am pretty well-versed with Data Binding -
and of course, writing some pretty extensive Cairngorm-based RIA, I have
a pretty good handle on the flow of things.

I guess what is making me second guess what I know about Events, is the
fact that I can't get this damn thing to work.  I am scratching my head
on this, and can't figure out what I am missing.

Take this simple example:

Main Application
  View1
  View2

In View1, I have a basic Panel with a DataGrid.  I have a Bindable
public var (myArrayCollection), and assigned it as the dataSource for my
Grid.  In my AS Code, I created a var referencing my ModelLocater.  Then
I set local myArrayCollection var equal to model.myArrayCollection.
This takes care of all the var declarations, as well as properly
dataBinding it to the Model.

Everything is great - data updates perfect, yada yada yada...

Now I want to add 1 more piece of functionality - broadcast an event, to
make my Grid scroll to the top, after a new record is added.  Sounds
easy enough...

Here is what I added to make this happen:

1) Added an eventListener to View1, that listens for scrollGrid -
which gets attached to the appropriate function (scrolling the Grid to
the very top).

2) Added extra logic to my Cairngorm getDataCommand Command - which I
put in the onResult Event Function.  The code to call the function
(because the function resides in my ModelLocater) is
model.fireOffScrollEvent.  The function simply dispatches a generic
Event (with the Event String being scrollGrid).

Now here is where I get confused:

Other than the simple variable reference in View1 to ModelLocater, there
is nothing else tying these 2 Classes together.  I say Classes, because
Controls in essence are simply Classes, in addition to the fact that
ModelLocater really doesn't extend anything.

So now, when I dispatch the scrollGrid Event from inside of
ModelLocater, nothing happens on View1.  See, this is where my
understanding of Events, falls terribly short.

See, in the times like this, I am not sure how the Application
propagates these Events.  When an Event gets dispatched, does Flex
systematically broadcast it to each and every component??

What confuses me too, is all the scoping stuff - which was a really big
deal in Flash.  In Flex, you don't use any dot-notation to specify
where the Event should go (like
Application.application.View1.myDataGrid) - it just goes somewhere out
there - like a black hole some place.  When they mention bubbling, I
thought this meant just that - 

Since this isn't working for me, I am obviously doing something wrong.
So the question is, what extra code must I add, to make the ModelLocater
aware of View1 and vice versa?

Thanks in advance for your time on this -

Mike


-Original Message-
From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Brian
Sent: Friday, January 12, 2007 11:10 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Need primer on Events, from the List Gurus -

Maybe the following will help.

Data Binding is really just a short hand version of an event broadcast,
and listener and function to be executed.

Take the example:

[Bindable]
private var lastname:String;

mx:Text text={lastname}/

mx:Button click=lastname='My last Name'/

--
When the button is click the variable lastname value is updated to 'my
last name'.

Since lastname is Bindable, it dispatches an event (broadcaster) that
the value has changed. Any control listening to the change event,
receives the event and runs a function to updates the property text to
the new value. This of course, invalidates the display which then the
display gets updated. 

The Bindable metatag creates a dispatch change event  (Broadcaster)

The {lastname} creates a listener for the text control to listen to the
lastname change event 

A function is created that updates the property, text in this case, to
the new value of last name.

I am sure it is more complicated than this (A function can also be
Bindable, how does the function know when it changes value?). 

You can implement data binding using the event model.  It might be a
good exercise, but you would not want to do it this way in an
application. 

I know the above helped me greatly in understanding the events model. I
hope it helps.

To answer your question
But what about the times, where I won't know for sure beforehand, which
component I will be using at the time?  

Using the above data binding example, data binding has no knowledge of
what component will be using data binding. Data binding can be used on
just about any component property. Again, data binding is a short hand
of an event model and each component doesn't care what component will be
used. 


The event model loosely couples the components, but both components must
know about the event model.  Any component that creates an event
listener and the function that should