Reflect property change from one View into another View using a Class as intermediate

拥有回忆 提交于 2019-12-11 02:22:29

问题


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


回答1:


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>



回答2:


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.



来源:https://stackoverflow.com/questions/4644379/reflect-property-change-from-one-view-into-another-view-using-a-class-as-interme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!