Gabe-

I got this idea from you to use classes and packages so I had the AI chatgpt 
help me build it.

I think it is cool. 

I will look at your 2nd proposed solution too.

Thank you so much. j.

Please see below....

<?xml version="1.0" encoding="UTF-8"?>
<j:Application xmlns:j="library://ns.apache.org/royale/jewel"
               xmlns:fx="http://ns.adobe.com/mxml/2009";
               width="100%" height="100%" applicationComplete="initApp()">
    
    <fx:Script>
        <![CDATA[
            import testpkg.Stateful;

            public var winState:Stateful = new Stateful('homeScreen');
            
            // Initialize the app view after everything is loaded
            private function initApp():void {
                // Pass references to the groups
                winState.setHomeScreenGroup(homeScreenGroup);
                winState.setAboutScreenGroup(aboutScreenGroup);
                winState.updateView();
            }
        ]]>
    </fx:Script>

    <j:initialView>
        <j:View style="padding: 10px;">
            <j:beads>
                <j:VerticalLayout gap="8"/>
            </j:beads>
            
            <!-- Group for home screen -->
            <j:Group id="homeScreenGroup" visible="true" width="100%" 
height="100%">
                <j:Label text="Welcome to the Home Screen!" width="100%" 
height="100%" />
                <j:Button text="Go to About Screen" 
click="winState.goToAboutScreen()"/>
            </j:Group>

            <!-- Group for about screen -->
            <j:Group id="aboutScreenGroup" visible="false" width="100%" 
height="100%">
                <j:Label text="This is the About Screen" width="100%" 
height="100%" />
                <j:Button text="Back to Home" 
click="winState.goToHomeScreen()"/>
            </j:Group>

        </j:View>
    </j:initialView>

</j:Application>

ackage testpkg {

    public class Stateful {

        private var cs:String;
        private var currentState:String;
        private var homeScreenGroup:Object;
        private var aboutScreenGroup:Object;

        // Constructor
        public function Stateful(cs:String):void {
            this.cs = 'homeScreen';
            this.currentState = cs;
        }

        // Setter methods to accept references from the MXML file
        public function setHomeScreenGroup(group:Object):void {
            this.homeScreenGroup = group;
        }

        public function setAboutScreenGroup(group:Object):void {
            this.aboutScreenGroup = group;
        }

        // Methods to navigate between screens
        public function goToAboutScreen():void {
            this.currentState = 'aboutScreen';
            updateView();
        }

        public function goToHomeScreen():void {
            this.currentState = 'homeScreen';
            updateView();
        }

        // Update the visibility of the groups based on the current state
        public function updateView():void {
            if (this.homeScreenGroup) {
                this.homeScreenGroup.visible = (this.currentState == 
'homeScreen');
            }
            if (this.aboutScreenGroup) {
                this.aboutScreenGroup.visible = (this.currentState == 
'aboutScreen');
            }
        }

        // Initialize the app view
        public function initApp():void {
            updateView();
        }
    }
}






Sent with Proton Mail secure email.

Reply via email to