Over 10 years of community discussion and knowledge are maintained here as a read-only archive.
public function FooMediator(viewComponent:Object=null) { super(NAME, viewComponent); view.dummyButton.addEventListener(....);}private function get view():FooView { return viewComponent as FooView;}
<mx:Panel ....> <mx:Button id="dummyButton" label="Close" /></mx:Panel>
FooView is a child of the "view".
: private function get view():FooView { return viewComponent as FooView;}
private function get view():FooView { return viewComponent as FooView;}
private function get view():BarView{ return viewComponent as BarView;}private function get fooView():FooView { return view.fooView as FooView;}private function get dummyButton():Button{ return fooView.dummyButton as Button;}
<mx:application...> ... <components:FooView id="FooView" /> ...</mx:application>
public function ApplicationMediator(...) { ... facade.registerMediator(new FooMediator(view.FooView));}private function get view():Application { return viewComponent as Application;}
public function ApplicationMediator(viewComponent:Object=null) { super(NAME, viewComponent); view.addEventListener(AppMain.EVT_SHOW_FOO, onShowFoo); view.addEventListener(AppMain.EVT_SHOW_BAR, onShowBar); checkForMediator(view.currentViewSelector, view.activeView); } protected function onShowFoo(e:Event):void { view.currentViewSelector = AppMain.VIEW_FOO; checkForMediator(AppMain.VIEW_FOO, view.activeView); sendNotification(ApplicationFacade.FOO_MODE); } protected function onShowBar(e:Event):void { view.currentViewSelector = AppMain.VIEW_BAR; checkForMediator(AppMain.VIEW_BAR, view.activeView); sendNotification(ApplicationFacade.BAR_MODE); } protected function checkForMediator( childSelector:int, child:Object ):void { switch (childSelector) { case AppMain.VIEW_FOO: if (facade.retrieveMediator(FooViewMediator.NAME) == null) { facade.registerMediator(new FooViewMediator(child)); } break; case AppMain.VIEW_BAR: if (facade.retrieveMediator(BarViewMediator.NAME) == null) { facade.registerMediator(new BarViewMediator(child)); } break; } }
<mx:Script> <![CDATA[ import mx.events.ItemClickEvent; import mx.rpc.events.FaultEvent; public static const EVT_SHOW_FOO:String = "showFoo"; public static const EVT_SHOW_BAR:String = "showBar"; public static const VIEW_FOO:int = 0; public static const VIEW_BAR:int = 1; [Bindable] public var currentViewSelector:int = VIEW_FOO; public var activeView:Object = viewEvents; private var facade:ApplicationFacade = ApplicationFacade.getInstance(); private function init():void { activeView = viewStack.selectedChild; facade.startup(this); } private function submit(action:String):void { dispatchEvent(new Event(action, true)); } ]]> </mx:Script> <mx:Binding source="viewStack.selectedChild" destination="activeView" /> <mx:ApplicationControlBar id="appControlBar" width="65%" dock="true"> <mx:Button id="buttonFoo" label="Foo" click="submit(EVT_SHOW_FOO)" /> <mx:Button id="buttonBar" label="Bar" click="submit(EVT_SHOW_BAR)" /> </mx:ApplicationControlBar> <mx:ViewStack id="viewStack" width="100%" height="75%" selectedIndex="{currentViewSelector}"> <components:FooView id="viewFoo" width="100%" height="100%" /> <components:BarView id="viewBar" width="100%" height="100%" /> </mx:ViewStack>
public function BarViewMediator(viewComponent:Object=null) { super(NAME, viewComponent); var data:ArrayCollection = new ArrayCollection(); for (var i:int = 0; i < 5; i++) { var q:BarVO = new BarVO (); q.name = "Bar " + (i+1); q.msg = "something random here - " + i; data.addItem(q); } view.listBarObjects.dataProvider = data; }
view.listBarObjects.dataprovider = data;
[Bindable] public var data:ArrayCollection = new ArrayCollection();......<mx:List id="listBarObjects" dataProvider={data}" />
view.data = data;
case AppMain.VIEW_PERSON: if (facade.retrieveMediator(PersonFormMediator.NAME) == null) { var personView:PersonView = child as PersonView ; facade.registerMediator(new PersonFormMediator(personView.personForm)); }
protected function checkForMediator( childSelector:int, child:Object ):void { switch (childSelector) { case AppMain.VIEW_EMPLOYEES: if (facade.retrieveMediator(EmployeeViewMediator.NAME) == null) { facade.registerMediator(new EmployeeViewMediator(child)); } break; case AppMain.VIEW_PERSON: if (facade.retrieveMediator(PersonFormMediator.NAME) == null) { var view:PersonView = child as PersonView; facade.registerMediator(new PersonFormMediator(view.personForm)); } if (facade.retrieveMediator(PersonListMediator.NAME) == null) { var view:PersonView = child as PersonView; facade.registerMediator(new PersonListMediator(view.personList)); } break; } }
personForm.addEventListener(....); // personForm is the PersonForm view
protected function checkForMediator( childSelector:int, child:Object ):void { switch (childSelector) { case AppMain.VIEW_EMPLOYEES: if (facade.retrieveMediator(EmployeeViewMediator.NAME) == null) { facade.registerMediator(new EmployeeViewMediator(child)); } break; case AppMain.VIEW_PERSON: if (facade.retrieveMediator(PersonFormMediator.NAME) == null || facade.retrieveMediator(PersonListMediator.NAME) == null) { var personView:PersonView = child as PersonView; personView.addEventListener(FlexEvent.CREATION_COMPLETE, onPersonViewCreationComplete); } break; } }private function onPersonViewCreationComplete(event:FlexEvent):void { if (facade.retrieveMediator(PersonFormMediator.NAME) == null) { var personView:PersonView = event.target as PersonView; facade.registerMediator(new PersonFormMediator(personView.personForm)); } if (facade.retrieveMediator(PersonListMediator.NAME) == null) { var personView:PersonView = event.target as PersonView; facade.registerMediator(new PersonListMediator(personView.personList)); }}
<mx:Panel ... creationComplete="notify(event)" />private function notify(event:FlexEvent):void { event.bubbles=true; dispatchEvent(event);}