Over 10 years of community discussion and knowledge are maintained here as a read-only archive.
<?xml version="1.0" encoding="utf-8"?><mx:ViewStack xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:view="com.me.myapp.view.components.*" selectedIndex="{currentView}"> <mx:Script> <![CDATA[ public static const GALLERY:String = 0; public static const EDITOR:String = 1; public static const PROFILE:String = 2; [Bindable] public var currentViewSelector:String = GALLERY; ]]> </mx:Script> <view:GalleryView/> <view:EditorView/> <view:ProfileView/></mx:ViewStack>
<?xml version="1.0" encoding="utf-8"?><mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:view="com.me.myapp.view.components.*" > <mx:MetaData> [Event('showGallery')] [Event('showProfile')] [Event('showEditor')] </mx:MetaData> <mx:Script> <![CDATA[ public static const GALLERY:String = 0; public static const EDITOR:String = 1; public static const PROFILE:String = 2; public static const SHOW_GALLERY:String = 'showGallery'; public static const SHOW_EDITOR:String = 'showEditor'; public static const SHOW_PROFILE:String = 'showProfile'; [Bindable] public var currentViewSelector:String = GALLERY; public var activeView:Object; ]]> </mx:Script> <mx:Binding source="myStack.selectedChild" destination="activeView"/> <mx:ViewStack id="myStack" selectedIndex="{currentViewSelector}"> <view:GalleryView/> <view:EditorView/> <view:ProfileView/> </mx:ViewStack> <mx:HBox> <mx:Button label="Gallery" enabled="{myStack.selectedIndex != GALLERY}" click="dispatchEvent(new Event(SHOW_GALLERY, true))"/> <mx:Button label="Editor" enabled="{myStack.selectedIndex != EDITOR}" click="dispatchEvent(new Event(SHOW_EDITOR, true))"/> <mx:Button label="Profile" enabled="{myStack.selectedIndex != PROFILE}" click="dispatchEvent(new Event(SHOW_PROFILE, true))"/> </mx:HBox></mx:VBox>
package com.me.myapp.view{ import com.me.myapp.view.components.MainDisplay; import org.puremvc.as3.interfaces.INotification; import org.puremvc.as3.patterns.mediator.Mediator; public class MainDisplayMediator extends Mediator { public static const NAME:String = 'MainDisplayMediator'; public function MainDisplayMediator( viewComponent:MainDisplay ) { super( NAME, viewComponent ); mainDisplay.addEventListener( MainDisplay.SHOW_GALLERY, onShowGallery ); mainDisplay.addEventListener( MainDisplay.SHOW_EDITOR, onShowEditor ); mainDisplay.addEventListener( MainDisplay.SHOW_PROFILE, onShowProfile ); checkForMediator( MainDisplay.currentViewSelector, mainDisplay.activeView ); } protected function get MainDisplay():MainDisplay { return viewComponent as MainDisplay; } protected function onShowEditor(event:Event):void { mainDisplay.currentViewSelector = MainDisplay.EDITOR; checkForMediator( MainDisplay.EDITOR, mainDisplay.activeView ); sendNotification( ApplicationFacade.EDITOR_MODE ); } protected function showGallery(event:Event ):void { mainDisplay.currentViewSelector= MainDisplay.GALLERY; checkForMediator( MainDisplay.GALLERY, mainDisplay.activeView ); sendNotification( ApplicationFacade.GALLERY_MODE ); } protected function showProfile(event:Event ):void { mainDisplay.currentViewSelector = MainDisplay.PROFILE; checkForMediator( MainDisplay.PROFILE, mainDisplay.activeView ); sendNotification( ApplicationFacade.PROFILE_MODE ); } protected function checkForMediator( childSelector:String, child:Object ):void { switch (childSelector) { case MainDisplay.PROFILE: if ( retrieveMediator( ProfileViewMediator.NAME ) == null ) facade.registerMediator(new ProfileViewMediator( child )); break; case MainDisplay.GALLERY: if ( retrieveMediator( GalleryViewMediator.NAME ) == null ) facade.registerMediator(new GalleryViewMediator( child )); break; case MainDisplay.EDITOR: if ( retrieveMediator( EditorViewMediator.NAME ) == null ) facade.registerMediator(new EditorViewMediator( child )); break; } } }}
super(NAME,viewComponent);trace("app : "+app); // traces the get method for giving back casted viewcomponenttrace("app nav : "+app.toolBar); // traces the first simple navigation componenttrace("currentView : "+app.currentViewSelector);trace("activeView : "+app.activeView);checkForMediator(app.currentViewSelector,app.activeView);