Reflect a property change from one view to another View using a class as an intermediate

I presented a stream that was (after reading it again) completely wrong. This is actually what I wanted to know:

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

Is there any way to define the following: whenever ViewProp changes (in View.mxml), ClassProp also changes in ClassManager, which, in turn, reflects its changes in Secondview.mxml in the SecondProp property ?!

Hope this time it is correctly described!

Thanks in advance

+2
source share
2 answers

This is a little different from your first question.

Viewing classes MUST NOT directly access model classes, and because of this, the View class must send an event to change the model class.

1.) You must define some 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 change the ViewProp in View.mxml, you should send an event

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

3.) In EventMap you must handle the event

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

4.) In ModelMap, you should already bind Secondview.SecondProp to ClassManager.ClassProp

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

How about this:

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

0
source

Source: https://habr.com/ru/post/1784368/


All Articles