Basically you want to communicate down (from parent to child), passing references as arguments (as you do with an array of screens) and up (from child to parent), calling public functions.
So, in your case, something like this:
Application Class:
private function buildNavigation():void { navigation = new Navigation(this, screens); }
Navigation class:
private var app:App public function Navigation(app:App, screens:Array) { this.app = app 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 { app.changeScreens(2); } }
Obviously, change the implementation to suit your needs (for example, now that you have a link to the application class, consider whether you need to pass a separate link to an array of screens or not) - this is just an example of how you can communicate.
source share