Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{}...

109
® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. Mate Flex Framework Using Flex Frameworks to Build Data- Driven Applications 1

Transcript of Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{}...

Page 1: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Mate Flex Framework

Using Flex Frameworks to Build Data-Driven Applications

1

Page 2: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 2

What is Mate?

<MXML>

Event Handling

Dependency Injection

Page 3: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Sample Projects

InsyncMate1

Exact copy of original app with a model and central event handling

InsyncMate2

Logic moved to ContactManager

InsyncMate3

Better architecture with Presentation Model pattern

Modularized application

InsyncMate4

Modularized application

3

Page 4: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 4

Before & After

Contact List

Page 5: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

ContactList.mxml

5

Toolbar.mxml

ContactList.mxml

Page 6: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 6

<mx:DataGrid id="dg" dataProvider="{ contacts }" doubleClick="dispatchEvent(

new ContactEvent( ContactEvent.EDIT, dg.selectedItem as Contact) )" ... />

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Script> [Bindable] public var contacts:ArrayCollection; private var lastSearchStr:String;

<mx:RemoteObject id="service" destination="contacts" endpoint="http://localhost:8400/messagebroker/amf"> <mx:method name="getContactsByName" result="getContacts_result(event)"/></mx:RemoteObject>

private function getContacts_result(event:ResultEvent):void {contacts = event.result as ArrayCollection;

}

</mx:Canvas>

</mx:Script>

public function search(searchStr:String):void { service.getContactsByName(searchStr);

lastSearchStr = searchStr;}

ContactList.mxml - Plain version

Page 7: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 6

<mx:DataGrid id="dg" dataProvider="{ contacts }" doubleClick="dispatchEvent(

new ContactEvent( ContactEvent.EDIT, dg.selectedItem as Contact) )" ... />

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Script> [Bindable] public var contacts:ArrayCollection; private var lastSearchStr:String;

<mx:RemoteObject id="service" destination="contacts" endpoint="http://localhost:8400/messagebroker/amf"> <mx:method name="getContactsByName" result="getContacts_result(event)"/></mx:RemoteObject>

private function getContacts_result(event:ResultEvent):void {contacts = event.result as ArrayCollection;

}

</mx:Canvas>

</mx:Script>

public function search(searchStr:String):void { service.getContactsByName(searchStr);

lastSearchStr = searchStr;}

ContactList.mxml - Plain version

Page 8: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 6

<mx:DataGrid id="dg" dataProvider="{ contacts }" doubleClick="dispatchEvent(

new ContactEvent( ContactEvent.EDIT, dg.selectedItem as Contact) )" ... />

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Script> [Bindable] public var contacts:ArrayCollection; private var lastSearchStr:String;

<mx:RemoteObject id="service" destination="contacts" endpoint="http://localhost:8400/messagebroker/amf"> <mx:method name="getContactsByName" result="getContacts_result(event)"/></mx:RemoteObject>

private function getContacts_result(event:ResultEvent):void {contacts = event.result as ArrayCollection;

}

</mx:Canvas>

</mx:Script>

public function search(searchStr:String):void { service.getContactsByName(searchStr);

lastSearchStr = searchStr;}

ContactList.mxml - Plain version

called by parentexecutes service call

Page 9: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 6

<mx:DataGrid id="dg" dataProvider="{ contacts }" doubleClick="dispatchEvent(

new ContactEvent( ContactEvent.EDIT, dg.selectedItem as Contact) )" ... />

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Script> [Bindable] public var contacts:ArrayCollection; private var lastSearchStr:String;

<mx:RemoteObject id="service" destination="contacts" endpoint="http://localhost:8400/messagebroker/amf"> <mx:method name="getContactsByName" result="getContacts_result(event)"/></mx:RemoteObject>

private function getContacts_result(event:ResultEvent):void {contacts = event.result as ArrayCollection;

}

</mx:Canvas>

</mx:Script>

public function search(searchStr:String):void { service.getContactsByName(searchStr);

lastSearchStr = searchStr;}

ContactList.mxml - Plain version

Page 10: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 6

<mx:DataGrid id="dg" dataProvider="{ contacts }" doubleClick="dispatchEvent(

new ContactEvent( ContactEvent.EDIT, dg.selectedItem as Contact) )" ... />

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Script> [Bindable] public var contacts:ArrayCollection; private var lastSearchStr:String;

<mx:RemoteObject id="service" destination="contacts" endpoint="http://localhost:8400/messagebroker/amf"> <mx:method name="getContactsByName" result="getContacts_result(event)"/></mx:RemoteObject>

private function getContacts_result(event:ResultEvent):void {contacts = event.result as ArrayCollection;

}

</mx:Canvas>

</mx:Script>

public function search(searchStr:String):void { service.getContactsByName(searchStr);

lastSearchStr = searchStr;}

ContactList.mxml - Plain version

Page 11: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 6

<mx:DataGrid id="dg" dataProvider="{ contacts }" doubleClick="dispatchEvent(

new ContactEvent( ContactEvent.EDIT, dg.selectedItem as Contact) )" ... />

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Script> [Bindable] public var contacts:ArrayCollection; private var lastSearchStr:String;

<mx:RemoteObject id="service" destination="contacts" endpoint="http://localhost:8400/messagebroker/amf"> <mx:method name="getContactsByName" result="getContacts_result(event)"/></mx:RemoteObject>

private function getContacts_result(event:ResultEvent):void {contacts = event.result as ArrayCollection;

}

</mx:Canvas>

</mx:Script>

public function search(searchStr:String):void { service.getContactsByName(searchStr);

lastSearchStr = searchStr;}

ContactList.mxml - Plain version

Page 12: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Plain version

7

services

business logic

view

ContactList

MainViewcalls search

Toolbar

Page 13: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Open file (InsyncMate1):

8

src

mate

ui

insync

views

ContactList.mxml

Page 14: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

ContactList.mxml - Mate version 1

9

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%">

<mx:Metadata> [Event(name="editContact", type="insync.mate.events.ContactEvent")] </mx:Metadata> <mx:Script>

import mx.collections.ArrayCollection; import insync.mate.model.Contact; import insync.mate.events.ContactEvent;

[Bindable] public var contacts:ArrayCollection; </mx:Script> <mx:DataGrid id="dg" dataProvider="{ contacts }" top="0" left="0" right="0" bottom="0" doubleClickEnabled="true" doubleClick="dispatchEvent( new ContactEvent( ContactEvent.EDIT, dg.selectedItem as Contact) )"> <mx:columns> <mx:DataGridColumn dataField="firstName" headerText="First Name"/> <mx:DataGridColumn dataField="lastName" headerText="Last Name"/> <mx:DataGridColumn dataField="phone" headerText="Phone"/> </mx:columns> </mx:DataGrid></mx:Canvas>

Page 15: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

ContactList.mxml - Mate version 1

9

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%">

<mx:Metadata> [Event(name="editContact", type="insync.mate.events.ContactEvent")] </mx:Metadata> <mx:Script>

import mx.collections.ArrayCollection; import insync.mate.model.Contact; import insync.mate.events.ContactEvent;

[Bindable] public var contacts:ArrayCollection; </mx:Script> <mx:DataGrid id="dg" dataProvider="{ contacts }" top="0" left="0" right="0" bottom="0" doubleClickEnabled="true" doubleClick="dispatchEvent( new ContactEvent( ContactEvent.EDIT, dg.selectedItem as Contact) )"> <mx:columns> <mx:DataGridColumn dataField="firstName" headerText="First Name"/> <mx:DataGridColumn dataField="lastName" headerText="Last Name"/> <mx:DataGridColumn dataField="phone" headerText="Phone"/> </mx:columns> </mx:DataGrid></mx:Canvas>

provided by injection

Page 16: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

ContactList.mxml - Mate version 1

9

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%">

<mx:Metadata> [Event(name="editContact", type="insync.mate.events.ContactEvent")] </mx:Metadata> <mx:Script>

import mx.collections.ArrayCollection; import insync.mate.model.Contact; import insync.mate.events.ContactEvent;

[Bindable] public var contacts:ArrayCollection; </mx:Script> <mx:DataGrid id="dg" dataProvider="{ contacts }" top="0" left="0" right="0" bottom="0" doubleClickEnabled="true" doubleClick="dispatchEvent( new ContactEvent( ContactEvent.EDIT, dg.selectedItem as Contact) )"> <mx:columns> <mx:DataGridColumn dataField="firstName" headerText="First Name"/> <mx:DataGridColumn dataField="lastName" headerText="Last Name"/> <mx:DataGridColumn dataField="phone" headerText="Phone"/> </mx:columns> </mx:DataGrid></mx:Canvas>

no business logic

not dependent on service

independent from Mate

Page 17: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Open file (InsyncMate1):

10

src

mate

services

insync

Services.mxml

Page 18: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Services.mxml - Mate version 1

11

<Object xmlns="*" xmlns:mx="http://www.adobe.com/2006/mxml">

</Object>centralized services

<mx:RemoteObject id="contacts" destination="contacts" endpoint="http://localhost:8400/messagebroker/amf" />

Page 19: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Services.mxml - Mate version 1

11

<Object xmlns="*" xmlns:mx="http://www.adobe.com/2006/mxml">

</Object>

<MockRemoteObject id="contacts" mockGenerator="{ MockContactService }" delay="3"> <methods> <MockMethod name="search" dataUrl="assets/xml/contacts.xml"/> </methods></MockRemoteObject>

Page 20: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Open file (InsyncMate1):

12

src

mate

managers

insync

ContactsManager.as

Page 21: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

ContactsManager.as - Mate version 1

13

public class ContactsManager extends EventDispatcher {

// property to store the last search keyword public var lastSearch:String = "";

// Read-only public variable used to access the current contacts to show in list private var _contacts:ArrayCollection; [Bindable(event="contactsChanged")] public function get contacts():ArrayCollection { return _contacts; }

// Stores given contacts and the current search keyword public function saveContacts( list:ArrayCollection, searchKey:String ):void { _contacts = list;

//trigger binding by dispatching change event dispatchEvent( new Event( "contactsChanged" ) ); lastSearch = searchKey; }}

Page 22: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

ContactsManager.as - Mate version 1

13

public class ContactsManager extends EventDispatcher {

// property to store the last search keyword public var lastSearch:String = "";

// Read-only public variable used to access the current contacts to show in list private var _contacts:ArrayCollection; [Bindable(event="contactsChanged")] public function get contacts():ArrayCollection { return _contacts; }

// Stores given contacts and the current search keyword public function saveContacts( list:ArrayCollection, searchKey:String ):void { _contacts = list;

//trigger binding by dispatching change event dispatchEvent( new Event( "contactsChanged" ) ); lastSearch = searchKey; }}

Page 23: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

ContactsManager.as - Mate version 1

13

public class ContactsManager extends EventDispatcher {

// property to store the last search keyword public var lastSearch:String = "";

// Read-only public variable used to access the current contacts to show in list private var _contacts:ArrayCollection; [Bindable(event="contactsChanged")] public function get contacts():ArrayCollection { return _contacts; }

// Stores given contacts and the current search keyword public function saveContacts( list:ArrayCollection, searchKey:String ):void { _contacts = list;

//trigger binding by dispatching change event dispatchEvent( new Event( "contactsChanged" ) ); lastSearch = searchKey; }}

independent from services

easy to mock and test

Page 24: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Open file (InsyncMate1):

14

src

mate

ui

insync

views

Toolbar.mxml

Page 25: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Toolbar.mxml - Mate version 1

15

<?xml version="1.0" encoding="utf-8"?><mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%">

<mx:Metadata> [Event(name="search", type="insync.plain.events.SearchEvent")] [Event(name="addContact", type="insync.plain.events.ContactEvent")] </mx:Metadata>

<mx:Script> <![CDATA[ import insync.plain.events.SearchEvent; import insync.plain.events.ContactEvent; ]]> </mx:Script> <mx:Button toolTip="Add Contact" click="dispatchEvent(new ContactEvent(ContactEvent.ADD))"/>

<mx:Label text="Search:" /> <mx:TextInput id="searchBox" change="dispatchEvent(new SearchEvent(SearchEvent.SEARCH, searchBox.text))"/></mx:Canvas>

Page 26: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Open file (InsyncMate1):

16

src

mate

maps

insync

MainMap.mxml

Page 27: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

MainMap.mxml - Mate version 1

17

<EventHandlers type="{ SearchEvent.SEARCH }">

<RemoteObjectInvoker instance="{ services.contacts }" method="getContactsByName" arguments="{ event.searchStr }"> <resultHandlers> <MethodInvoker generator="{ ContactsManager }" method="saveContacts" arguments="{ [resultObject, event.searchStr] }"/> </resultHandlers> </RemoteObjectInvoker>

</EventHandlers>

<EventMap xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="http://mate.asfusion.com/" xmlns:services="insync.mate.services.*">

<services:Services id="services" />

</EventMap>

Page 28: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

MainMap.mxml - Mate version 1

17

<EventHandlers type="{ SearchEvent.SEARCH }">

<RemoteObjectInvoker instance="{ services.contacts }" method="getContactsByName" arguments="{ event.searchStr }"> <resultHandlers> <MethodInvoker generator="{ ContactsManager }" method="saveContacts" arguments="{ [resultObject, event.searchStr] }"/> </resultHandlers> </RemoteObjectInvoker>

</EventHandlers>

<EventMap xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="http://mate.asfusion.com/" xmlns:services="insync.mate.services.*">

<services:Services id="services" />

</EventMap>

Page 29: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

MainMap.mxml - Mate version 1

17

<EventHandlers type="{ SearchEvent.SEARCH }">

<RemoteObjectInvoker instance="{ services.contacts }" method="getContactsByName" arguments="{ event.searchStr }"> <resultHandlers> <MethodInvoker generator="{ ContactsManager }" method="saveContacts" arguments="{ [resultObject, event.searchStr] }"/> </resultHandlers> </RemoteObjectInvoker>

</EventHandlers>

<EventMap xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="http://mate.asfusion.com/" xmlns:services="insync.mate.services.*">

<services:Services id="services" />

</EventMap>

Page 30: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

MainMap.mxml - Mate version 1

17

<EventHandlers type="{ SearchEvent.SEARCH }">

<RemoteObjectInvoker instance="{ services.contacts }" method="getContactsByName" arguments="{ event.searchStr }"> <resultHandlers> <MethodInvoker generator="{ ContactsManager }" method="saveContacts" arguments="{ [resultObject, event.searchStr] }"/> </resultHandlers> </RemoteObjectInvoker>

</EventHandlers>

<EventMap xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="http://mate.asfusion.com/" xmlns:services="insync.mate.services.*">

<services:Services id="services" />

</EventMap>

Page 31: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

MainMap.mxml - Mate version 1

17

<EventHandlers type="{ SearchEvent.SEARCH }">

<RemoteObjectInvoker instance="{ services.contacts }" method="getContactsByName" arguments="{ event.searchStr }"> <resultHandlers> <MethodInvoker generator="{ ContactsManager }" method="saveContacts" arguments="{ [resultObject, event.searchStr] }"/> </resultHandlers> </RemoteObjectInvoker>

</EventHandlers>

<EventMap xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="http://mate.asfusion.com/" xmlns:services="insync.mate.services.*">

<services:Services id="services" />

</EventMap>

Page 32: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

MainMap.mxml - Mate version 1

17

<EventHandlers type="{ SearchEvent.SEARCH }">

<RemoteObjectInvoker instance="{ services.contacts }" method="getContactsByName" arguments="{ event.searchStr }"> <resultHandlers> <MethodInvoker generator="{ ContactsManager }" method="saveContacts" arguments="{ [resultObject, event.searchStr] }"/> </resultHandlers> </RemoteObjectInvoker>

</EventHandlers>

<EventMap xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="http://mate.asfusion.com/" xmlns:services="insync.mate.services.*">

<services:Services id="services" />

</EventMap>

Page 33: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

MainMap.mxml - Mate version 1

17

<EventHandlers type="{ SearchEvent.SEARCH }">

<RemoteObjectInvoker instance="{ services.contacts }" method="getContactsByName" arguments="{ event.searchStr }"> <resultHandlers> <MethodInvoker generator="{ ContactsManager }" method="saveContacts" arguments="{ [resultObject, event.searchStr] }"/> </resultHandlers> </RemoteObjectInvoker>

</EventHandlers>

<EventMap xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="http://mate.asfusion.com/" xmlns:services="insync.mate.services.*">

<services:Services id="services" />

service methods separated from view and business logic

</EventMap>

Page 34: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Open file (InsyncMate1):

18

src

InsyncMate1.mxml

Page 35: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

InsyncMate1.mxml (version 1)

19

<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:views="insync.mate.ui.views.*" xmlns:maps="insync.mate.maps.*" xmlns:mate="http://mate.asfusion.com/"> <!-- Styles ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <mx:Style source="assets/styles/styles.css" /> <!-- EventMaps ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <maps:MainMap /> <!-- UI ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <views:MainView/> <!-- Debugger ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <mate:Debugger level="{Debugger.ALL}" /></mx:Application>

Page 36: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

InsyncMate1.mxml (version 1)

19

<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:views="insync.mate.ui.views.*" xmlns:maps="insync.mate.maps.*" xmlns:mate="http://mate.asfusion.com/"> <!-- Styles ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <mx:Style source="assets/styles/styles.css" /> <!-- EventMaps ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <maps:MainMap /> <!-- UI ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <views:MainView/> <!-- Debugger ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <mate:Debugger level="{Debugger.ALL}" /></mx:Application>

Page 37: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

InsyncMate1.mxml (version 1)

19

<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:views="insync.mate.ui.views.*" xmlns:maps="insync.mate.maps.*" xmlns:mate="http://mate.asfusion.com/"> <!-- Styles ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <mx:Style source="assets/styles/styles.css" /> <!-- EventMaps ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <maps:MainMap /> <!-- UI ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <views:MainView/> <!-- Debugger ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <mate:Debugger level="{Debugger.ALL}" /></mx:Application>

Page 38: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Debugging Output

<EventHandlers (started) type="SearchEvent.SEARCH" (search) priority="0" useCapture="false" useWeakReference="true" dispatcherType="inherit" scope="[object Scope]">

<RemoteObjectInvoker instance="[RemoteObject destination="contacts" channelSet="[ChannelSet null ]"]" arguments="Pam" showBusyCursor="false" makeObjectsBindable="true" method="getContactsByName" requestTimeout="0" debug="false"/>

</EventHandlers (end) type="SearchEvent.SEARCH" (search)>

Page 39: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Debugging Output

<EventHandlers (started) type="SearchEvent.SEARCH" (search) priority="0" useCapture="false" useWeakReference="true" dispatcherType="inherit" scope="[object Scope]">

<RemoteObjectInvoker instance="[RemoteObject destination="contacts" channelSet="[ChannelSet null ]"]" arguments="Pam" showBusyCursor="false" makeObjectsBindable="true" method="getContactsByName" requestTimeout="0" debug="false"/>

</EventHandlers (end) type="SearchEvent.SEARCH" (search)>

<RemoteObjectInvoker instance="{ services.contacts }" method="getContactsByName" debug="true" arguments="{ event.searchStr }">

Page 40: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Debugging Output

<EventHandlers (started) type="SearchEvent.SEARCH" (search) priority="0" useCapture="false" useWeakReference="true" dispatcherType="inherit" scope="[object Scope]">

<RemoteObjectInvoker instance="[RemoteObject destination="contacts" channelSet="[ChannelSet null ]"]" arguments="Pam" showBusyCursor="false" makeObjectsBindable="true" method="getContactsByName" requestTimeout="0" debug="false"/>

</EventHandlers (end) type="SearchEvent.SEARCH" (search)>

<ServiceHandlers (started) type="SearchEvent.SEARCH" (search) token="[object AsyncToken]" priority="0" useCapture="false" useWeakReference="true" scope="[object ServiceScope]" dispatcherType="local">

<MethodInvoker method="saveContacts" arguments="[ [object Contact], Pam ]" generator="[class ContactsManager]" cache="inherit" registerTarget="true"/>

</ServiceHandlers (end) type="SearchEvent.SEARCH" (search)>

<RemoteObjectInvoker instance="{ services.contacts }" method="getContactsByName" debug="true" arguments="{ event.searchStr }">

Page 41: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 21

Event Bus

View(ContactList.mxml)

EventMap

Remote Object(Services.mxml)

Model(ContactManager.as)

binding via Injection

Event Handling

Toolbar

Page 42: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Open file (InsyncMate1):

22

src

mate

maps

insync

MainMap.mxml

Page 43: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

MainMap.mxml - Mate version 1

23

<EventMap xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="http://mate.asfusion.com/">

<Injectors target="{ ContactList }"> <PropertyInjector targetKey="contacts" source="{ ContactsManager }" sourceKey="contacts"/> </Injectors>

</EventMap>

Takes advantage of bindings

Page 44: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 24

Event Bus

ContactList

Injection

Page 45: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 24

Event Bus

ContactList

creationCompletedispatched

1

Injection

Page 46: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 24

Event Bus

ContactList

EventMap

creationCompletedispatched

1

Injection

Page 47: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 24

Event Bus

ContactList

EventMapContactManager

creationCompletedispatched

1

Injection

Page 48: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 24

Event Bus

ContactList

EventMapContactManager

creationCompletedispatched

1

creates binding between model and view

2

Injection

Page 49: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 24

Event Bus

ContactList

EventMapContactManager

creationCompletedispatched

1

creates binding between model and view

2

bindingupdates

3

Injection

Page 50: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 24

Event Bus

ContactList

ContactManager

bindingupdates

3

Injection

Page 51: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 25

Version 1

Contact Form

Page 52: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 26

ContactEvent.DELETE ContactEvent.SAVE

Page 53: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Open file (InsyncMate2):

27

src

mate

ui

insync

views

ContactForm.mxml

Page 54: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 28

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" label="{contact.id>0?contact.fullName:'New Contact'}">

<mx:Script> <![CDATA[ [Bindable] public var contact:Contact; private function save():void { contact.firstName = firstName.text; contact.lastName = lastName.text; contact.email = email.text; contact.phone = phone.text; contact.address = address.text; contact.city = city.text; contact.state = state.text; contact.zip = zip.text; contact.pic = picture.source;

dispatchEvent( new ContactEvent( ContactEvent.SAVE, contact ) ); } private function remove():void { dispatchEvent( new ContactEvent( ContactEvent.DELETE, contact ) ); } public function save_result( ):void { status.text = "Contact saved successfully"; } ]]> </mx:Script>

Page 55: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 28

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" label="{contact.id>0?contact.fullName:'New Contact'}">

<mx:Script> <![CDATA[ [Bindable] public var contact:Contact; private function save():void { contact.firstName = firstName.text; contact.lastName = lastName.text; contact.email = email.text; contact.phone = phone.text; contact.address = address.text; contact.city = city.text; contact.state = state.text; contact.zip = zip.text; contact.pic = picture.source;

dispatchEvent( new ContactEvent( ContactEvent.SAVE, contact ) ); } private function remove():void { dispatchEvent( new ContactEvent( ContactEvent.DELETE, contact ) ); } public function save_result( ):void { status.text = "Contact saved successfully"; } ]]> </mx:Script>

Page 56: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 29

<mx:Form> <mx:FormItem label="Id"> <mx:TextInput text="{contact.id}" enabled="false"/> </mx:FormItem> <mx:FormItem label="First Name"> <mx:TextInput id="firstName" text="{contact.firstName}"/> </mx:FormItem> <mx:FormItem label="Last Name"> <mx:TextInput id="lastName" text="{contact.lastName}"/> </mx:FormItem> <mx:FormItem label="Email"> <mx:TextInput id="email" text="{contact.email}"/> </mx:FormItem> <-- all of the other fields here -->

</mx:Form>

<controls:PictureInput id="picture" source="{contact.pic}"/> <mx:Button label="Save" click="save()"/> <mx:Button label="Delete" click="remove()"/>

<mx:Label id="status" /></mx:Canvas>

Page 57: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 29

<mx:Form> <mx:FormItem label="Id"> <mx:TextInput text="{contact.id}" enabled="false"/> </mx:FormItem> <mx:FormItem label="First Name"> <mx:TextInput id="firstName" text="{contact.firstName}"/> </mx:FormItem> <mx:FormItem label="Last Name"> <mx:TextInput id="lastName" text="{contact.lastName}"/> </mx:FormItem> <mx:FormItem label="Email"> <mx:TextInput id="email" text="{contact.email}"/> </mx:FormItem> <-- all of the other fields here -->

</mx:Form>

<controls:PictureInput id="picture" source="{contact.pic}"/> <mx:Button label="Save" click="save()"/> <mx:Button label="Delete" click="remove()"/>

<mx:Label id="status" /></mx:Canvas>

Page 58: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 29

<mx:Form> <mx:FormItem label="Id"> <mx:TextInput text="{contact.id}" enabled="false"/> </mx:FormItem> <mx:FormItem label="First Name"> <mx:TextInput id="firstName" text="{contact.firstName}"/> </mx:FormItem> <mx:FormItem label="Last Name"> <mx:TextInput id="lastName" text="{contact.lastName}"/> </mx:FormItem> <mx:FormItem label="Email"> <mx:TextInput id="email" text="{contact.email}"/> </mx:FormItem> <-- all of the other fields here -->

</mx:Form>

<controls:PictureInput id="picture" source="{contact.pic}"/> <mx:Button label="Save" click="save()"/> <mx:Button label="Delete" click="remove()"/>

<mx:Label id="status" /></mx:Canvas>

Page 59: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 30

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" label="{contact.id>0?contact.fullName:'New Contact'}">

<mx:Script> <![CDATA[ [Bindable] public var contact:Contact; private function save():void { contact.firstName = firstName.text; contact.lastName = lastName.text; contact.email = email.text; contact.phone = phone.text; contact.address = address.text; contact.city = city.text; contact.state = state.text; contact.zip = zip.text; contact.pic = picture.source;

dispatchEvent( new ContactEvent( ContactEvent.SAVE, contact ) ); } private function remove():void { dispatchEvent( new ContactEvent( ContactEvent.DELETE, contact ) ); } public function save_result( ):void { status.text = "Contact saved successfully"; } ]]> </mx:Script>

Page 60: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 30

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" label="{contact.id>0?contact.fullName:'New Contact'}">

<mx:Script> <![CDATA[ [Bindable] public var contact:Contact; private function save():void { contact.firstName = firstName.text; contact.lastName = lastName.text; contact.email = email.text; contact.phone = phone.text; contact.address = address.text; contact.city = city.text; contact.state = state.text; contact.zip = zip.text; contact.pic = picture.source;

dispatchEvent( new ContactEvent( ContactEvent.SAVE, contact ) ); } private function remove():void { dispatchEvent( new ContactEvent( ContactEvent.DELETE, contact ) ); } public function save_result( ):void { status.text = "Contact saved successfully"; } ]]> </mx:Script>

Page 61: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 30

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" label="{contact.id>0?contact.fullName:'New Contact'}">

<mx:Script> <![CDATA[ [Bindable] public var contact:Contact; private function save():void { contact.firstName = firstName.text; contact.lastName = lastName.text; contact.email = email.text; contact.phone = phone.text; contact.address = address.text; contact.city = city.text; contact.state = state.text; contact.zip = zip.text; contact.pic = picture.source;

dispatchEvent( new ContactEvent( ContactEvent.SAVE, contact ) ); } private function remove():void { dispatchEvent( new ContactEvent( ContactEvent.DELETE, contact ) ); } public function save_result( ):void { status.text = "Contact saved successfully"; } ]]> </mx:Script>

Page 62: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Open file (InsyncMate1):

31

src

mate

maps

insync

MainMap.mxml

Page 63: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

<EventHandlers type="{ ContactEvent.SAVE }"> <RemoteObjectInvoker instance="{ services.contacts }" method="save" arguments="{ event.contact }"> <resultHandlers>

<CallBack method="save_result"/>

<EventAnnouncer generator="{ SearchEvent }" type="{ SearchEvent.SEARCH }"> <Property targetKey="searchStr" source="{ ContactsManager }"

sourceKey="lastSearch"/> </EventAnnouncer>

</resultHandlers> </RemoteObjectInvoker>

</EventHandlers>

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 32

<EventMap>

</EventMap>

Page 64: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

<EventHandlers type="{ ContactEvent.SAVE }"> <RemoteObjectInvoker instance="{ services.contacts }" method="save" arguments="{ event.contact }"> <resultHandlers>

<CallBack method="save_result"/>

<EventAnnouncer generator="{ SearchEvent }" type="{ SearchEvent.SEARCH }"> <Property targetKey="searchStr" source="{ ContactsManager }"

sourceKey="lastSearch"/> </EventAnnouncer>

</resultHandlers> </RemoteObjectInvoker>

</EventHandlers>

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 32

<EventMap>

</EventMap>

Page 65: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

<EventHandlers type="{ ContactEvent.SAVE }"> <RemoteObjectInvoker instance="{ services.contacts }" method="save" arguments="{ event.contact }"> <resultHandlers>

<CallBack method="save_result"/>

<EventAnnouncer generator="{ SearchEvent }" type="{ SearchEvent.SEARCH }"> <Property targetKey="searchStr" source="{ ContactsManager }"

sourceKey="lastSearch"/> </EventAnnouncer>

</resultHandlers> </RemoteObjectInvoker>

</EventHandlers>

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 32

<EventMap>

</EventMap>

Page 66: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

<EventHandlers type="{ ContactEvent.SAVE }"> <RemoteObjectInvoker instance="{ services.contacts }" method="save" arguments="{ event.contact }"> <resultHandlers>

<CallBack method="save_result"/>

<EventAnnouncer generator="{ SearchEvent }" type="{ SearchEvent.SEARCH }"> <Property targetKey="searchStr" source="{ ContactsManager }"

sourceKey="lastSearch"/> </EventAnnouncer>

</resultHandlers> </RemoteObjectInvoker>

</EventHandlers>

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 32

<EventMap>

</EventMap>

Page 67: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

<EventHandlers type="{ ContactEvent.SAVE }"> <RemoteObjectInvoker instance="{ services.contacts }" method="save" arguments="{ event.contact }"> <resultHandlers>

<CallBack method="save_result"/>

<EventAnnouncer generator="{ SearchEvent }" type="{ SearchEvent.SEARCH }"> <Property targetKey="searchStr" source="{ ContactsManager }"

sourceKey="lastSearch"/> </EventAnnouncer>

</resultHandlers> </RemoteObjectInvoker>

</EventHandlers>

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 32

<EventMap>

</EventMap>

Page 68: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

<EventHandlers type="{ ContactEvent.SAVE }"> <RemoteObjectInvoker instance="{ services.contacts }" method="save" arguments="{ event.contact }"> <resultHandlers>

<CallBack method="save_result"/>

<EventAnnouncer generator="{ SearchEvent }" type="{ SearchEvent.SEARCH }"> <Property targetKey="searchStr" source="{ ContactsManager }"

sourceKey="lastSearch"/> </EventAnnouncer>

</resultHandlers> </RemoteObjectInvoker>

</EventHandlers>

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 32

<EventMap>

</EventMap>

Page 69: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Open file (InsyncMate1):

33

src

mate

ui

insync

views

ContactForm.mxml

Page 70: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 34

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" label="{contact.id>0?contact.fullName:'New Contact'}">

<mx:Script> <![CDATA[ [Bindable] public var contact:Contact; private function save():void { contact.firstName = firstName.text; contact.lastName = lastName.text; contact.email = email.text; contact.phone = phone.text; contact.address = address.text; contact.city = city.text; contact.state = state.text; contact.zip = zip.text; contact.pic = picture.source;

dispatchEvent( new ContactEvent( ContactEvent.SAVE, contact ) ); } private function remove():void { dispatchEvent( new ContactEvent( ContactEvent.DELETE, contact ) ); } public function save_result( ):void { status.text = "Contact saved successfully"; } ]]> </mx:Script>

Page 71: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 34

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" label="{contact.id>0?contact.fullName:'New Contact'}">

<mx:Script> <![CDATA[ [Bindable] public var contact:Contact; private function save():void { contact.firstName = firstName.text; contact.lastName = lastName.text; contact.email = email.text; contact.phone = phone.text; contact.address = address.text; contact.city = city.text; contact.state = state.text; contact.zip = zip.text; contact.pic = picture.source;

dispatchEvent( new ContactEvent( ContactEvent.SAVE, contact ) ); } private function remove():void { dispatchEvent( new ContactEvent( ContactEvent.DELETE, contact ) ); } public function save_result( ):void { status.text = "Contact saved successfully"; } ]]> </mx:Script>

Page 72: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 35

Event Bus

View(ContacForm.mxml) EventMap

Remote Object(Services.mxml)

Saving a contact

Page 73: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 36

Version 3

Contact Form

Page 74: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 37

Event Bus

View(ContacForm.mxml) EventMap

Remote Object(Services.mxml)

Presentation Model

• User input & visualization• Maintains its state• Dispatches events• Receives data• Validates user input

Page 75: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 37

Event Bus

View(ContacForm.mxml) EventMap

Remote Object(Services.mxml)

Presentation Model

• User input & visualization• Maintains its state• Dispatches events• Receives data• Validates user input

Page 76: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 37

Event Bus

View(ContacForm.mxml) EventMap

Remote Object(Services.mxml)

Presentation Model

Page 77: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 37

Event Bus

View(ContacForm.mxml) EventMap

Remote Object(Services.mxml)

Presentation Model

Presentation Model

Page 78: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 37

Event Bus

View(ContacForm.mxml) EventMap

Remote Object(Services.mxml)

Presentation Model

Presentation Model

Page 79: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Open file (InsyncMate3):

38

src

mate

ui

insync

views

ContactForm.mxml

contacts

Page 80: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 39

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Script> [Bindable] public var model:ContactFormPresentationModel;

</mx:Script> <mx:Form>

<mx:FormItem label="Id"> <mx:TextInput text="{ model.contact.id }" enabled="false" /> </mx:FormItem>

<mx:FormItem label="First Name"> <mx:TextInput id="firstName" text="{ model.contact.firstName }" change="model.updateFirstName( firstName.text )"/> </mx:FormItem>

<-- all of the other fields here --> </mx:Form>

<controls:PictureInput id="picture" source="{ model.contact.pic }"/> <mx:Button bottom="26" left="12" label="Save" click="model.save()"/> <mx:Button bottom="26" left="72" label="Delete" click="model.remove()"/>

<mx:Label id="status" text="{ model.status }" /></mx:Canvas>

Page 81: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 39

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Script> [Bindable] public var model:ContactFormPresentationModel;

</mx:Script> <mx:Form>

<mx:FormItem label="Id"> <mx:TextInput text="{ model.contact.id }" enabled="false" /> </mx:FormItem>

<mx:FormItem label="First Name"> <mx:TextInput id="firstName" text="{ model.contact.firstName }" change="model.updateFirstName( firstName.text )"/> </mx:FormItem>

<-- all of the other fields here --> </mx:Form>

<controls:PictureInput id="picture" source="{ model.contact.pic }"/> <mx:Button bottom="26" left="12" label="Save" click="model.save()"/> <mx:Button bottom="26" left="72" label="Delete" click="model.remove()"/>

<mx:Label id="status" text="{ model.status }" /></mx:Canvas>

Page 82: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 39

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Script> [Bindable] public var model:ContactFormPresentationModel;

</mx:Script> <mx:Form>

<mx:FormItem label="Id"> <mx:TextInput text="{ model.contact.id }" enabled="false" /> </mx:FormItem>

<mx:FormItem label="First Name"> <mx:TextInput id="firstName" text="{ model.contact.firstName }" change="model.updateFirstName( firstName.text )"/> </mx:FormItem>

<-- all of the other fields here --> </mx:Form>

<controls:PictureInput id="picture" source="{ model.contact.pic }"/> <mx:Button bottom="26" left="12" label="Save" click="model.save()"/> <mx:Button bottom="26" left="72" label="Delete" click="model.remove()"/>

<mx:Label id="status" text="{ model.status }" /></mx:Canvas>

Page 83: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 39

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Script> [Bindable] public var model:ContactFormPresentationModel;

</mx:Script> <mx:Form>

<mx:FormItem label="Id"> <mx:TextInput text="{ model.contact.id }" enabled="false" /> </mx:FormItem>

<mx:FormItem label="First Name"> <mx:TextInput id="firstName" text="{ model.contact.firstName }" change="model.updateFirstName( firstName.text )"/> </mx:FormItem>

<-- all of the other fields here --> </mx:Form>

<controls:PictureInput id="picture" source="{ model.contact.pic }"/> <mx:Button bottom="26" left="12" label="Save" click="model.save()"/> <mx:Button bottom="26" left="72" label="Delete" click="model.remove()"/>

<mx:Label id="status" text="{ model.status }" /></mx:Canvas>

Page 84: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 39

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Script> [Bindable] public var model:ContactFormPresentationModel;

</mx:Script> <mx:Form>

<mx:FormItem label="Id"> <mx:TextInput text="{ model.contact.id }" enabled="false" /> </mx:FormItem>

<mx:FormItem label="First Name"> <mx:TextInput id="firstName" text="{ model.contact.firstName }" change="model.updateFirstName( firstName.text )"/> </mx:FormItem>

<-- all of the other fields here --> </mx:Form>

<controls:PictureInput id="picture" source="{ model.contact.pic }"/> <mx:Button bottom="26" left="12" label="Save" click="model.save()"/> <mx:Button bottom="26" left="72" label="Delete" click="model.remove()"/>

<mx:Label id="status" text="{ model.status }" /></mx:Canvas>

Page 85: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Open file (InsyncMate3):

40

src

mate

ui

insync

presenters

ContactPresentationModel.as

contacts

Page 86: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 41

public class ContactFormPresentationModel extends EventDispatcher {

// ---------------------------------- private var _title:String; [Bindable(Event="titleChange")] public function get title():String { return _title; } // ----------------------------------- private var _status:String; [Bindable(Event="statusChange")] public function get status():String { return _status; } // ----------------------------------- private var _contact:Contact; [Bindable(Event="contactChange")] public function get contact():Contact { return _contact; }

Page 87: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 41

public class ContactFormPresentationModel extends EventDispatcher {

// ---------------------------------- private var _title:String; [Bindable(Event="titleChange")] public function get title():String { return _title; } // ----------------------------------- private var _status:String; [Bindable(Event="statusChange")] public function get status():String { return _status; } // ----------------------------------- private var _contact:Contact; [Bindable(Event="contactChange")] public function get contact():Contact { return _contact; }

Page 88: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 42

// ----------------------------------- private var dispatcher:IEventDispatcher; public function ContactFormPresentationModel(dispatcher:IEventDispatcher, contact:Contact) { this.dispatcher = dispatcher; _contact = contact; _title = contact.id > 0 ? contact.fullName: 'New Contact'; } // ----------------------------------- public function save():void { dispatcher.dispatchEvent( new ContactEvent( ContactEvent.SAVE, contact ) ); } // ----------------------------------- public function remove():void { dispatcher.dispatchEvent( new ContactEvent( ContactEvent.DELETE, contact ) ); }

// ----------------------------------- public function contactSaved( event:ContactEvent ):void { if( event.contact == contact ) { _status = "Contact saved successfully"; dispatchEvent( new Event( "statusChange" ) ); } }

Page 89: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 42

// ----------------------------------- private var dispatcher:IEventDispatcher; public function ContactFormPresentationModel(dispatcher:IEventDispatcher, contact:Contact) { this.dispatcher = dispatcher; _contact = contact; _title = contact.id > 0 ? contact.fullName: 'New Contact'; } // ----------------------------------- public function save():void { dispatcher.dispatchEvent( new ContactEvent( ContactEvent.SAVE, contact ) ); } // ----------------------------------- public function remove():void { dispatcher.dispatchEvent( new ContactEvent( ContactEvent.DELETE, contact ) ); }

// ----------------------------------- public function contactSaved( event:ContactEvent ):void { if( event.contact == contact ) { _status = "Contact saved successfully"; dispatchEvent( new Event( "statusChange" ) ); } }

Page 90: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 42

// ----------------------------------- private var dispatcher:IEventDispatcher; public function ContactFormPresentationModel(dispatcher:IEventDispatcher, contact:Contact) { this.dispatcher = dispatcher; _contact = contact; _title = contact.id > 0 ? contact.fullName: 'New Contact'; } // ----------------------------------- public function save():void { dispatcher.dispatchEvent( new ContactEvent( ContactEvent.SAVE, contact ) ); } // ----------------------------------- public function remove():void { dispatcher.dispatchEvent( new ContactEvent( ContactEvent.DELETE, contact ) ); }

// ----------------------------------- public function contactSaved( event:ContactEvent ):void { if( event.contact == contact ) { _status = "Contact saved successfully"; dispatchEvent( new Event( "statusChange" ) ); } }

Page 91: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 43

// Update functions ---------------------------------------------- public function updateFirstName( firstName:String ):void { contact.firstName = firstName; } // ----------------------------------- public function updateLastName( lastName:String ):void { contact.lastName = lastName; } // ----------------------------------- public function updateEmail( email:String ):void { contact.email = email; }

// ----------------------------------- public function updatePhone( phone:String ):void { contact.phone = phone; }

Page 92: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Open file (InsyncMate3):

44

src

mate

insync

managers

ContactsManager.as

contacts

Page 93: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

ContactsManager.as (InsyncMate3)

45

public class ContactsManager extends EventDispatcher { private var editOpenContacts:Dictionary = new Dictionary( true ); private var newOpenContacts:Dictionary = new Dictionary( true ); // ------------------------------------------------------------------------ // property to store the last search keyword public var lastSearch:String = " "; // ------------------------------------------------------------------------ // Read-only public variable used to access the current contacts to show in list private var _contacts:ArrayCollection; [Bindable(event="contactsChanged")] public function get contacts():ArrayCollection { return _contacts; } // ------------------------------------------------------------------------ // Read-only public variable used to access the current contact (last selected contact) private var currentContact:Contact; public function getCurrentContact():Contact { return currentContact; } // ------------------------------------------------------------------------- // Stores given contacts and the current search keyword public function storeSearch( list:ArrayCollection, searchKey:String ):void { _contacts = list; dispatchEvent( new Event( "contactsChanged" ) ); lastSearch = searchKey; } // ------------------------------------------------------------------------- // Applies updates to a contact public function save( contact:Contact, originalContact:Contact ):void { if( originalContact.id == 0) { var form:Object; form = newOpenContacts[ originalContact ]; editOpenContacts[ contact.id ] = form; } originalContact.copyFrom( contact ); } // ------------------------------------------------------------------------- public function openNewContact( template:Class ):Object { currentContact = new Contact(); var form:Object = new template(); newOpenContacts[ currentContact ] = form; return form; } // ------------------------------------------------------------------------- public function openEditContact( contact:Contact, template:Class ):Object { var form:Object = editOpenContacts[ contact.id ]; if( !form ) { form = new template(); editOpenContacts[ contact.id ] = form; } currentContact = contact; return form; } // ------------------------------------------------------------------------- public function closeContact( contact:Contact ):Object { var form:Object; if( editOpenContacts[ contact.id ] != undefined && contact.id != 0 ) { form = editOpenContacts[ currentContact.id ]; delete editOpenContacts[ currentContact ] } else if( newOpenContacts[ currentContact ] != undefined ) { form = newOpenContacts[ currentContact ]; delete newOpenContacts[ currentContact ]; } return form; } }}

Page 94: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

ContactsManager.as (InsyncMate3)

45

public class ContactsManager extends EventDispatcher { private var editOpenContacts:Dictionary = new Dictionary( true ); private var newOpenContacts:Dictionary = new Dictionary( true ); // ------------------------------------------------------------------------ // property to store the last search keyword public var lastSearch:String = " "; // ------------------------------------------------------------------------ // Read-only public variable used to access the current contacts to show in list private var _contacts:ArrayCollection; [Bindable(event="contactsChanged")] public function get contacts():ArrayCollection { return _contacts; } // ------------------------------------------------------------------------ // Read-only public variable used to access the current contact (last selected contact) private var currentContact:Contact; public function getCurrentContact():Contact { return currentContact; } // ------------------------------------------------------------------------- // Stores given contacts and the current search keyword public function storeSearch( list:ArrayCollection, searchKey:String ):void { _contacts = list; dispatchEvent( new Event( "contactsChanged" ) ); lastSearch = searchKey; } // ------------------------------------------------------------------------- // Applies updates to a contact public function save( contact:Contact, originalContact:Contact ):void { if( originalContact.id == 0) { var form:Object; form = newOpenContacts[ originalContact ]; editOpenContacts[ contact.id ] = form; } originalContact.copyFrom( contact ); } // ------------------------------------------------------------------------- public function openNewContact( template:Class ):Object { currentContact = new Contact(); var form:Object = new template(); newOpenContacts[ currentContact ] = form; return form; } // ------------------------------------------------------------------------- public function openEditContact( contact:Contact, template:Class ):Object { var form:Object = editOpenContacts[ contact.id ]; if( !form ) { form = new template(); editOpenContacts[ contact.id ] = form; } currentContact = contact; return form; } // ------------------------------------------------------------------------- public function closeContact( contact:Contact ):Object { var form:Object; if( editOpenContacts[ contact.id ] != undefined && contact.id != 0 ) { form = editOpenContacts[ currentContact.id ]; delete editOpenContacts[ currentContact ] } else if( newOpenContacts[ currentContact ] != undefined ) { form = newOpenContacts[ currentContact ]; delete newOpenContacts[ currentContact ]; } return form; } }}

Page 95: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Open file (InsyncMate3):

46

src

mate

insync

maps

ContactMap.mxml

contacts

Page 96: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

ContactMap.mxml

47

<LocalEventMap xmlns:mx="http://www.adobe.com/2006/mxml"xmlns="http://mate.asfusion.com/"> <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <Injectors target="{ ContactForm }"> <MethodInvoker generator="{ ContactsManager }" method="getCurrentContact" /> <ObjectBuilder generator="{ ContactFormPresentationModel }" cache="none" constructorArguments="{ [ scope.dispatcher, lastReturn ] }" /> <PropertyInjector targetKey="model" source="{ lastReturn }"/> </Injectors> <Injectors target="{ ContactFormPresentationModel }"> <ListenerInjector eventType="{ ContactEvent.SAVED }" method="contactSaved" /> </Injectors></LocalEventMap>

Page 97: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

ContactMap.mxml

47

<LocalEventMap xmlns:mx="http://www.adobe.com/2006/mxml"xmlns="http://mate.asfusion.com/"> <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <Injectors target="{ ContactForm }"> <MethodInvoker generator="{ ContactsManager }" method="getCurrentContact" /> <ObjectBuilder generator="{ ContactFormPresentationModel }" cache="none" constructorArguments="{ [ scope.dispatcher, lastReturn ] }" /> <PropertyInjector targetKey="model" source="{ lastReturn }"/> </Injectors> <Injectors target="{ ContactFormPresentationModel }"> <ListenerInjector eventType="{ ContactEvent.SAVED }" method="contactSaved" /> </Injectors></LocalEventMap>

Page 98: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

ContactMap.mxml (InsyncMate3)

48

<!-- ContactEvent.SAVE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <EventHandlers type="{ ContactEvent.SAVE }"> <RemoteObjectInvoker instance="{ services.contacts }" method="save" arguments="{ event.contact }"> <resultHandlers> <MethodInvoker generator="{ ContactsManager }" method="save" arguments="{ [resultObject, event.contact] }"/> <EventAnnouncer generator="{ SearchEvent }" dispatcherType="global" type="{ ContactEvent.REFRESH }"/>

<EventAnnouncer generator="{ ContactEvent }" constructorArguments="{ [ContactEvent.SAVED, event.contact] }"/>

</resultHandlers> </RemoteObjectInvoker> </EventHandlers>

Page 99: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 49

Version 3

Modules

Page 100: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Open folder (InsyncMate3):

51

src

mate

contacts

insync

ContactModule.mxml

shared

Page 101: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

ContactModule.mxml

52

<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> public function addTab( event:NavigatorEvent ):void { try { var childIndex:int = tabNavigator.getChildIndex( event.content ); tabNavigator.selectedIndex = childIndex; } catch( e:Error) { tabNavigator.addChild( event.content ); tabNavigator.selectedChild = event.content; } } public function removeTab( event:NavigatorEvent ):void { tabNavigator.removeChild( event.content ); } </mx:Script> <!-- EventMaps --> <maps:ContactMap dispatcher="{ this }"/> <!-- UI --> <mx:HDividedBox width="100%" height="100%"> <flexLib:SuperTabNavigator id="tabNavigator" width="100%" height="100%"/> <views:ContactList id="list" width="300"/> </mx:HDividedBox></mx:Module>

Page 102: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

ContactModule.mxml

52

<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> public function addTab( event:NavigatorEvent ):void { try { var childIndex:int = tabNavigator.getChildIndex( event.content ); tabNavigator.selectedIndex = childIndex; } catch( e:Error) { tabNavigator.addChild( event.content ); tabNavigator.selectedChild = event.content; } } public function removeTab( event:NavigatorEvent ):void { tabNavigator.removeChild( event.content ); } </mx:Script> <!-- EventMaps --> <maps:ContactMap dispatcher="{ this }"/> <!-- UI --> <mx:HDividedBox width="100%" height="100%"> <flexLib:SuperTabNavigator id="tabNavigator" width="100%" height="100%"/> <views:ContactList id="list" width="300"/> </mx:HDividedBox></mx:Module>

Page 103: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

ContactModule.mxml

52

<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> public function addTab( event:NavigatorEvent ):void { try { var childIndex:int = tabNavigator.getChildIndex( event.content ); tabNavigator.selectedIndex = childIndex; } catch( e:Error) { tabNavigator.addChild( event.content ); tabNavigator.selectedChild = event.content; } } public function removeTab( event:NavigatorEvent ):void { tabNavigator.removeChild( event.content ); } </mx:Script> <!-- EventMaps --> <maps:ContactMap dispatcher="{ this }"/> <!-- UI --> <mx:HDividedBox width="100%" height="100%"> <flexLib:SuperTabNavigator id="tabNavigator" width="100%" height="100%"/> <views:ContactList id="list" width="300"/> </mx:HDividedBox></mx:Module>

Page 104: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Open file (InsyncMate3):

53

src

mate

insync

maps

ContactMap.mxml

contacts

Page 105: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

ContactMap.mxml

54

<LocalEventMap xmlns:mx="http://www.adobe.com/2006/mxml"xmlns="http://mate.asfusion.com/"> <!-- SearchEvent.SEARCH ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <EventHandlers type="{ SearchEvent.SEARCH }" dispatcherType="global"> <RemoteObjectInvoker instance="{ services.contacts }" method="getContactsByName" arguments="{ event.searchStr }"> <resultHandlers> <MethodInvoker generator="{ ContactsManager }" method="storeSearch" arguments="{ [resultObject, event.searchStr] }"/> </resultHandlers> </RemoteObjectInvoker> </EventHandlers> <!-- ContactEvent.EDIT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <EventHandlers type="{ ContactEvent.EDIT }"> <MethodInvoker generator="{ ContactsManager }" method="openEditContact" arguments="{[ event.contact, ContactForm ]}" /> <EventAnnouncer generator="{ NavigatorEvent }" type="{ NavigatorEvent.ADD_CONTENT }" > <Property targetKey="content" source="{ lastReturn }"/> </EventAnnouncer> </EventHandlers> <!-- ContactEvent.ADD ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <EventHandlers type="{ ContactEvent.ADD }" dispatcherType="global"> <MethodInvoker generator="{ ContactsManager }" method="openNewContact" arguments="{ ContactForm }"/> <EventAnnouncer generator="{ NavigatorEvent }" type="{ NavigatorEvent.ADD_CONTENT }" > <Property targetKey="content" source="{ lastReturn }"/> </EventAnnouncer> </EventHandlers>

</LocalEventMap>

Page 106: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

ContactMap.mxml

54

<LocalEventMap xmlns:mx="http://www.adobe.com/2006/mxml"xmlns="http://mate.asfusion.com/"> <!-- SearchEvent.SEARCH ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <EventHandlers type="{ SearchEvent.SEARCH }" dispatcherType="global"> <RemoteObjectInvoker instance="{ services.contacts }" method="getContactsByName" arguments="{ event.searchStr }"> <resultHandlers> <MethodInvoker generator="{ ContactsManager }" method="storeSearch" arguments="{ [resultObject, event.searchStr] }"/> </resultHandlers> </RemoteObjectInvoker> </EventHandlers> <!-- ContactEvent.EDIT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <EventHandlers type="{ ContactEvent.EDIT }"> <MethodInvoker generator="{ ContactsManager }" method="openEditContact" arguments="{[ event.contact, ContactForm ]}" /> <EventAnnouncer generator="{ NavigatorEvent }" type="{ NavigatorEvent.ADD_CONTENT }" > <Property targetKey="content" source="{ lastReturn }"/> </EventAnnouncer> </EventHandlers> <!-- ContactEvent.ADD ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <EventHandlers type="{ ContactEvent.ADD }" dispatcherType="global"> <MethodInvoker generator="{ ContactsManager }" method="openNewContact" arguments="{ ContactForm }"/> <EventAnnouncer generator="{ NavigatorEvent }" type="{ NavigatorEvent.ADD_CONTENT }" > <Property targetKey="content" source="{ lastReturn }"/> </EventAnnouncer> </EventHandlers>

</LocalEventMap>

Page 107: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

ContactMap.mxml

54

<LocalEventMap xmlns:mx="http://www.adobe.com/2006/mxml"xmlns="http://mate.asfusion.com/"> <!-- SearchEvent.SEARCH ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <EventHandlers type="{ SearchEvent.SEARCH }" dispatcherType="global"> <RemoteObjectInvoker instance="{ services.contacts }" method="getContactsByName" arguments="{ event.searchStr }"> <resultHandlers> <MethodInvoker generator="{ ContactsManager }" method="storeSearch" arguments="{ [resultObject, event.searchStr] }"/> </resultHandlers> </RemoteObjectInvoker> </EventHandlers> <!-- ContactEvent.EDIT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <EventHandlers type="{ ContactEvent.EDIT }"> <MethodInvoker generator="{ ContactsManager }" method="openEditContact" arguments="{[ event.contact, ContactForm ]}" /> <EventAnnouncer generator="{ NavigatorEvent }" type="{ NavigatorEvent.ADD_CONTENT }" > <Property targetKey="content" source="{ lastReturn }"/> </EventAnnouncer> </EventHandlers> <!-- ContactEvent.ADD ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <EventHandlers type="{ ContactEvent.ADD }" dispatcherType="global"> <MethodInvoker generator="{ ContactsManager }" method="openNewContact" arguments="{ ContactForm }"/> <EventAnnouncer generator="{ NavigatorEvent }" type="{ NavigatorEvent.ADD_CONTENT }" > <Property targetKey="content" source="{ lastReturn }"/> </EventAnnouncer> </EventHandlers>

</LocalEventMap>

Page 108: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

ContactMap.mxml

54

<LocalEventMap xmlns:mx="http://www.adobe.com/2006/mxml"xmlns="http://mate.asfusion.com/"> <!-- SearchEvent.SEARCH ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <EventHandlers type="{ SearchEvent.SEARCH }" dispatcherType="global"> <RemoteObjectInvoker instance="{ services.contacts }" method="getContactsByName" arguments="{ event.searchStr }"> <resultHandlers> <MethodInvoker generator="{ ContactsManager }" method="storeSearch" arguments="{ [resultObject, event.searchStr] }"/> </resultHandlers> </RemoteObjectInvoker> </EventHandlers> <!-- ContactEvent.EDIT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <EventHandlers type="{ ContactEvent.EDIT }"> <MethodInvoker generator="{ ContactsManager }" method="openEditContact" arguments="{[ event.contact, ContactForm ]}" /> <EventAnnouncer generator="{ NavigatorEvent }" type="{ NavigatorEvent.ADD_CONTENT }" > <Property targetKey="content" source="{ lastReturn }"/> </EventAnnouncer> </EventHandlers> <!-- ContactEvent.ADD ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <EventHandlers type="{ ContactEvent.ADD }" dispatcherType="global"> <MethodInvoker generator="{ ContactsManager }" method="openNewContact" arguments="{ ContactForm }"/> <EventAnnouncer generator="{ NavigatorEvent }" type="{ NavigatorEvent.ADD_CONTENT }" > <Property targetKey="content" source="{ lastReturn }"/> </EventAnnouncer> </EventHandlers>

</LocalEventMap>

Page 109: Mate Flex Framework · 45 public class ContactsManager extends EventDispatcher {// -----// -----{} // -----{}

®

Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential.

Learn more

57

http://mate.asfusion.com