<?xml version="1.0" encoding="utf-8"?>
<mx:ViewStack xmlns:fx="http://ns.adobe.com/mxml/2009"
              xmlns:s="library://ns.adobe.com/flex/spark"
              xmlns:mx="library://ns.adobe.com/flex/mx"
              width="100%"
              height="100%"
              implements="ptaylor.bdd.screens.IScreen">
    <fx:Script>
        <![CDATA[
            import mx.core.INavigatorContent;
            
            import ptaylor.bdd.grid.components.GridScreen;
            import ptaylor.bdd.main.components.MainScreen;
            import ptaylor.bdd.screens.IScreen;
            import ptaylor.bdd.screens.events.ScreenChangedSignal;
            
            public static const MAIN_SCREEN:IScreen = new MainScreen();
            public static const GRID_SCREEN:IScreen = new GridScreen();
            
            public function set selectedScreen(screen:IScreen):void
            {
                if(!(screen is INavigatorContent))
                {
                    return;
                }
                
                // If you call getChildIndex with a DisplayObject that isn't
                // parented by this ViewStack, the Flash Player throws an error
                // (instead of returning -1).
                // 
                // This checks to see if the new screen is already child of this
                // ViewStack. If it isn't, add it as a child. 
                
                if(getChildren().some(function(child:DisplayObject, ... args):Boolean{
                    return child == screen;
                }) == false)
                {
                    addChild(screen as DisplayObject);
                }
                
                selectedChild = screen as INavigatorContent;
            }
            
            private const signal:ScreenChangedSignal = new ScreenChangedSignal();
            
            public function get screenChangedSignal():ScreenChangedSignal
            {
                return signal;
            }
        ]]>
    </fx:Script>

</mx:ViewStack>