flex-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tintin <1955.mille.mig...@googlemail.com>
Subject Model View Presenter Event Handling
Date Tue, 14 Oct 2014 20:19:26 GMT

How should a parent component handle an event raised by a child component?

I have a custom mxml component (let's call it parent_view) containing 2
further child custom components (child1_view and child2_view). Each of these
components have their own ActionScript Presenter class.

child1_view has a button and I want to change the currentState of
parent_view when it is clicked.

In my mind the 'views' know of their respective 'presenters' who's job it is
to pass data back to the Model and handle events raised by the Model to
change their property values to which the 'views' are bound to (causing the
'views' to update. The 'presenters' know nothing of their respective
'views', the Model knows nothing about the 'presenters' or the 'views'.

I imagined that my child1_view button.click event would call a function in
child1_presenter. child1_presenter function would dispatch a custom event
such as child1ButtonClicked. parent_presenter would have an event handler
listening for the child1ButtonClicked event and change the currentState of
the parent_view. What I can't figure out is how I get a reference to the
child1_presenter class within my parent_presenter in order to add the

Currently the way I have got it working is as follows: Following child1_view
button.click the function in child1_presenter gets a reference to the
currentTarget of the event argument passed. From this reference I can obtain
the parent and simply set the currentState, no events necessary. I don't
think this is very good practice though!

I'm sure the answer is simple, but I can't see it.



View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Model-View-Presenter-Event-Handling-tp8416.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

View raw message