2

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

Community
  • 1
  • 1
Savvas Sopiadis
  • 8,213
  • 10
  • 34
  • 53

2 Answers2

0

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.

michael
  • 1,160
  • 7
  • 19
  • Wouldn't this violate the principles of using MATE? Shouldn't everything kept centrally? (in the map file)? Just asking... i 'm new to Flex and MATE – Savvas Sopiadis Jan 10 '11 at 08:16
0

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>
Kiril Kirilov
  • 11,167
  • 5
  • 49
  • 74
  • So if understand correct using two Injectors would be wrong!? Yes? Is it feasible anyway? What makes me suspicious is this: using map files one does separate (or bind - it depends how you see it) properties of each other (for me it means that they are not aware of each other). Did i understand this correctly? – Savvas Sopiadis Jan 10 '11 at 16:17
  • There are several problems with binding one view component to other view component. For example, if you try to inject the property of class that is currently not created(if Secondview is created first, Mate will try to bind View.ViewProp to Secondview.econdProp, but View will be null). Also changing the Model class directly by some View is against MVC principles. – Kiril Kirilov Jan 10 '11 at 17:39
  • About 'two injectors' - if you have injector from View to Model class: first, it is against MVC principles, second this will not work when the view is null and possible unbinding will follow. – Kiril Kirilov Jan 10 '11 at 17:42