Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you directly access parent classes from child objects, you create strong coupling - which is exactly what you <em>don't</em> 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.</p> <p>Here's an example. First, create a custom event:</p> <pre><code>public class MyCustomEvent extends Event { public static const MENU_ITEM_SELECTED : String = "MENU_ITEM_SELECTED"; public var selectedItem:String; } </code></pre> <p>Then, let the navigation dispatch it, when a button is clicked:</p> <pre><code>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); } // ... } </code></pre> <p>Finally, let the application handle the custom event and bring up a different screen: </p> <pre><code>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. } } </code></pre> <p>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.</p>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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