Question

I did submit a thread which was (after reading it again) totally wrong formulated. This is actually what i wanted to know:

In a Flex application using MATE suppose we have a view called View.mxml with a property called ViewProp and a class called ClassManager with a property ClassProp. Suppose we have another view called SecondView.mxml with a property SecondProp.

Is it possible to define somehow the following: whenever the ViewProp changes (in View.mxml) the ClassProp is also changed in ClassManager, which in turn reflects its changes in Secondview.mxml in property SecondProp?!

I hope this time to have described it correctly!

Thanks in advance

Was it helpful?

Solution

This is a bit different from your first question.

View classes MUST not access the model classes directly, and because of that the View class must dispatch an event to change the model class.

1.)You must define some kind of new event

public class ViewPropIsChangedEvent extends Event
{

  public static const SET_NEW_VALUE:String = "theNewValue";
  private var _value:Object;

  public ViewPropIsChangedEvent(type:String, value:Object, bubbling:Boolean=true, cancelable:Boolean=false)
  {
    super(type,bubbling,cancelable);
    _value = value;
  }
   public function get value():Object
  {
    return _value;
  }
}

2.) When you changed the ViewProp in View.mxml, you must dispatch an event

dispatchEvent(new ViewPropIsChangedEvent(ViewPropIsChangedEvent.SET_NEW_VALUE, theNewValue))

3.) In the EventMap you must handle the event

</EventHandlers type="{ViewPropIsChangedEvent.SET_NEW_VALUE}"> 
  <PropertySetter generator="{ClassManager}" 
                  targetKey="ClassProp" 
                  source="{event.value}"/>
</EventHandlers>

4.) In the ModelMap you must already bind the Secondview.SecondProp to ClassManager.ClassProp

<Injectors target="{Secondview}">
   <PropertyInjector targetKey="SecondProp" 
                     source="{ClassManager}"
                     sourceKey="ClassProp"/>
</Injectors>

OTHER TIPS

How about in this way:

When the ViewProp or ClassProp change, this property dispatch an event and an eventlistener is added in Secondview.mxml to modify the property SecondProp.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top