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 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
>

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links




--
Ralf Bokelberg <[EMAIL PROTECTED]>
Flex & Flash Consultant based in Cologne/Germany
Phone +49 (0) 221 530 15 35

Reply via email to