Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7620345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:55:05+00:00 2026-05-31T03:55:05+00:00

I just started programming OOP and I’m running into a scope problem. In the

  • 0

I just started programming OOP and I’m running into a scope problem.
In the following project, I have a masterClass called App. The App-class has Screens:Screen-class and a Navigation-class as it’s children. From the navigation class I want to control which screens will be displayed. I don’t know how to do this…

Please check the code to fully understand my intentions

Your help is really appreciated, I’d love to really learn programming and not just a dirty solution 🙂 but all suggestions are welcome!

// Main Class //
public class App extends Sprite
{
    private var screens:Array;
        private var screen1:Screen;
        private var screen2:Screen;
        private var screen3:Screen;
        private var screen4:Screen;

    public var currentScreen:String;
    //



    private var navigation:Navigation;

    public function App()
    {
        init();
    }

    private function init():void {
        buildScreens();

        buildNavigation();
    }

    private function buildScreens():void {
        screen1 = new Screen();
        screen1.name = 'startScreen';
        currentScreen = screen1.name;
        addChild(screen1);

        screen2 = new Screen();
        screen2.name = 'irrelevantA';

        screen3 = new Screen();
        screen3.name = 'irrelevantB';

        screen4 = new Screen();
        screen4.name = 'irrelevantC';


        screens = new Array(screen1, screen2, screen3, screen4);


    }

    private function buildNavigation():void {
        navigation = new Navigation(screens);
    }
}

// Screen Class //
public class Screen extends Sprite
{
    public function Screen()
    {
        // creates a new screen
    }
}


// Navigation Class //
public class Navigation extends Sprite
{
    private var buttons:Array;

    public function Navigation(screens:Array)
    {
        addButtons(screens);
    }

    private function addButtons(screens:Array):void {
        buttons = new Array();

        for each(var screen:Screen in screens) {
            var button:Button = new Button();
            button.link = screen.name;
            button.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
            buttons.push(button);
        }
    }

    private function mouseDown(e:MouseEvent):void {
        // THIS IS WHAT MY QUESTION IS ABOUT: How should I talk to the parent class in an OOP correct way?
        // and how can I add and remove a screen in the App class from here?

        // Here some of my tries
        // I don't think using parent to get there is a good way because next time it might be; parent.parent.parent
        trace(e.target.parent.parent.currentScreen);
        this.parent.currentScreen;
        stage.App.currentScreen;
        App.currentScreen;


        //---------------------------------
    }
}

// Button Class //
public class Button extends Sprite
{
    public var link:String;

    public function Button()
    {
        // creates a new button
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:55:06+00:00Added an answer on May 31, 2026 at 3:55 am

    If you directly access parent classes from child objects, you create strong coupling – which is exactly what you don’t want in a well-built system. It is best not to access the application object directly, but to use event listeners and custom events to promote changes from e.g. the navigation.

    Here’s an example. First, create a custom event:

    public class MyCustomEvent extends Event {
    
        public static const MENU_ITEM_SELECTED : String = "MENU_ITEM_SELECTED";
        public var selectedItem:String;
    }
    

    Then, let the navigation dispatch it, when a button is clicked:

    public class Navigation extends Sprite () {
        // ...
        private function onButtonClicked(ev:Event) : void {
            ev.stopPropagation();
            var custEvent:MyCustomEvent = new MyCustomEvent(MyCustomEvent.MENU_ITEM_SELECTED);
            custEvent.selectedItem = ev.target.name;
            this.dispatchEvent (custEvent);
        }
        // ...
    }
    

    Finally, let the application handle the custom event and bring up a different screen:

    public class App {
        // ...
        public function createNavigation () : void {
            navigation = new Navigation ();
            navigation.addEventListener (MyCustomEvent.MENU_ITEM_SELECTED, onMenuItemSelected);
            // ... more stuff happening
        }
        // ...
    
        private function onMenuItemSelected (ev:MyCustomEvent) : void {
            switchToScreen (ev.selectedItem);
        }
    
        private function switchToScreen (name:String) : void {
            // choose screen by name, etc.
        }
    }
    

    For all of this, neither the screen, nor the navigation have to know anything about any other objects involved, so you can easily replace each one without breaking the rest of the system.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been doing python programming for my project and I have just started.
I have just started delving into the world of functional programming. A lot of
I have just started programming and have made a few small applications in C
I have just started reading Modern C++ Design Generic programming and Design Patterns Applied
I have just started the Assembly language programming and in the first lecture our
My problem is perhaps pretty simple, but I just started programming in C#. My
I have just started with Gui Programming in netbeans (Using the template Java Desktop
I'm a real noob who just started learning 3d programming and i have a
Just started learning Groovy, got the PragProg book Programming Groovy and had a problem
I have just started programming in C++ and I was playing around with templates.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.