Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess a parent class in an OOP correct way
    primarykey
    data
    text
    <p>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...</p> <p>Please check the code to fully understand my intentions</p> <p>Your help is really appreciated, I'd love to really learn programming and not just a dirty solution :) but all suggestions are welcome!</p> <pre><code>// 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 } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload