I have a problem that I simply can’t find a good
solution for. Does anyone know how can I reuse a custom form
control as an editor for one or more VOs and detect when user
interaction changes the values and not programmatic actions? The
use case and my attempted solution are described below.
* The user is given a list of VOs that they can choose from.
* When they choose a VO, values for all associated fields are
displayed in a custom form
* If the user edits the value of one or more fields, a
“dirty flag” is displayed to indicate that data has
* The user is prompted to save or discard changes before they
are allowed to select another VO or leave the form
The solution I implemented basically binds the values of the
VO directly to the associated data fields. So far so good. But how
do we know when the data has changed? I then set up another one way
binding from the UIComponents to a VO that is wrapped in a
ObjectProxy. I attached a property change listener to the
ObjectProxy. Every time values in the UI widgets changed to a
different value, a property change event is fired. Therefore,
whenever the user changes a value in the form, my listener hears
about it and can set the dirty flag. Great so far, but here is the
Each time I select a new VO, some or all of the UI values
change based upon the values stored in the selected VO. These
changes cause propertyChange events for fire as expected. The basic
problem is how do I know when the expected property change events
have completed, and when property change events from user
interaction begin? What I have observed is that events are received
at different rates depending upon the UI widget (e.g. TextInput vs
ComboBox). Events are received even after the new VO is set which
suggests to me that they are dispatched in one or more other
threads. Unlike my native Java language, I have no threading
constructs to synchronize on in ActionScript 3.0.
I hope I have explained the problem well enough. The bottom
line is, how can I reuse a custom form as an editor for multiple
VOs and detect when user interaction changes the values and not the
programmatic action of setting the values of a new VO? Any advice
would be appreciated. Thanks!!
For the TextInput elements, you can use the "textInput"
event. This only fires when the user types data in the text input.
For the ComboBox elements, you can use the "itemClick" event.
This only fires when the user selects an item ind the ComboBox.
Each Form element has events that only fire with user
interaction. You will need to identify those, and use that event
instead of the "change" event, which fires anytime there is a
change user or otherwise.