Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.app.screen
- {
- import com.fake.utils.TraceUtil;
- import com.fake.utils.actions.ActionDirector;
- import com.fake.utils.actions.PropertyChangeAction;
- import com.fake.utils.lso.LSObject;
- import flash.events.MouseEvent;
- import mx.containers.Canvas;
- import mx.containers.ViewStack;
- import mx.controls.Button;
- import mx.controls.LinkButton;
- import mx.controls.Text;
- import mx.core.Application;
- import mx.events.FlexEvent;
- public class ScreenContainerCtrl extends Canvas
- {
- /**
- * All ScreenComponents are stored here
- */
- public var viewstack:ViewStack;
- /**
- * Contains references to all ScreenComponents. Keyed by their label property.
- */
- public var screenMap:Object = {};
- public var btn_next:Button;
- public var btn_back:Button;
- public var btn_summary:LinkButton;
- public var txt_failure:Text;
- public var dataStore:XML = <ScreenContainerCtrl/>;
- public function ScreenContainerCtrl()
- {
- super();
- addEventListener(FlexEvent.CREATION_COMPLETE, init);
- }
- /**
- * Attaches the event handlers to the next, summary and back buttons.
- * Creates the screen map.
- */
- protected function init(event:FlexEvent):void
- {
- btn_next.addEventListener(MouseEvent.CLICK, onNextClick);
- btn_back.addEventListener(MouseEvent.CLICK, onBackClick);
- btn_summary.addEventListener(MouseEvent.CLICK, onSummaryClick);
- createScreenMap();
- TraceUtil.instance.codeBehindVariables();
- currentScreen.onScreenEnter();
- }
- /**
- * Each ScreenComponent has a corresponding abstract method
- * with the same name. It is called before the current screen
- * is changed. The ScreenContainer then grabs the nextScreen property
- * of the currentScreen and changes the current screen. The abstract
- * onScreenEnter method is called on the now current screen.
- *
- * @param event Click Event from the next button.
- */
- public function onNextClick(event:MouseEvent):void
- {
- failureText = currentScreen.validate();
- if(failureText == "")
- {
- currentScreen.onNextClick();
- gotoScreen(currentScreen.nextScreen);
- }
- }
- /**
- * The onNextClick method of the ScreenComponent is called before
- * the current screen is changed. The ScreenContainer then grabs
- * the summaryScreen property of the currentScreen and changes the
- * onScreenEnter method is called on the now current screen.
- *
- * @param event Click Event from the summary link button.
- */
- public function onSummaryClick(event:MouseEvent):void
- {
- failureText = currentScreen.validate();
- if(failureText == "")
- {
- currentScreen.onNextClick();
- gotoScreen(currentScreen.summaryScreen);
- }
- }
- /**
- * Each ScreenComponent has a corresponding abstract method
- * with the same name. It is called before the current screen
- * is changed. The currentScreen is then changed to the previous
- * screen. The onScreenEnter method is called on the now current screen.
- *
- * @param event Click Event from the back button.
- */
- public function onBackClick(event:MouseEvent):void
- {
- currentScreen.onBackClick();
- ActionDirector.undoAction();
- currentScreen.onScreenEnter(false);
- }
- /**
- * Creates an undo/redo entry and changes the currentScreen. If clear is true
- * the onClear function is called on the new currentScreen. Then calls the
- * onScreenEnter function.
- *
- * @param screenLabel What screen should become the currentScreen.
- * @param clear Determines if the onClear function of the new currentScreen is called.
- *
- */
- public function gotoScreen(screenLabel:String, clear:Boolean = false):void
- {
- PropertyChangeAction.start("uid", ["currentScreenLabel"], this);
- currentScreenLabel = screenLabel;
- PropertyChangeAction.end();
- if(clear)
- currentScreen.onClear();
- currentScreen.onScreenEnter();
- }
- /**
- * Retrieves the ScreenComponent by its label property.
- *
- * @param screenLabel Label property of the requested ScreenComponent.
- */
- public function getScreenByLabel(screenLabel:String):ScreenComponentCtrl
- {
- return screenMap[screenLabel];
- }
- /**
- * Populates a map object with all ScreenComponents within the
- * viewstack property. The map is keyed by the ScreenComponent's
- * label property.
- */
- public function createScreenMap():void
- {
- for each(var screen:Object in viewstack.getChildren())
- {
- screenMap[screen.label] = screen;
- }
- }
- /**
- * Returns the selectedChild of the viewstack. Read only.
- */
- public function get currentScreen():ScreenComponentCtrl
- {
- return viewstack.selectedChild as ScreenComponentCtrl;
- }
- /**
- * Returns the label property of the current ScreenComponent.
- */
- public function get currentScreenLabel():String
- {
- return currentScreen.label;
- }
- /**
- * Changes the selectedChild property of the viewstack.
- */
- public function set currentScreenLabel(screenLabel:String):void
- {
- viewstack.selectedChild = screenMap[screenLabel];
- }
- public function save():void {
- LSObject.instance.dataStore = dataStore;
- }
- public function load():void
- {
- if(!LSObject.instance.dataStore)
- reset();
- dataStore = LSObject.instance.dataStore;
- }
- public function reset():void {
- dataStore = <ScreenContainerCtrl/>;
- save();
- }
- /**
- * Allows the screen container to retrieved like a singleton.
- */
- public static function get instance():ScreenContainerCtrl {
- return bef(Application.application).screenContainer as ScreenContainerCtrl;
- }
- public function get failureText():String {
- return txt_failure.text;
- }
- public function set failureText(value:String):void {
- txt_failure.text = value;
- }
- }
- }
Add Comment
Please, Sign In to add comment