Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Avoid having your Dialog know about the Main screen class. Tightly-coupling makes debugging more difficult, and isn't truly representative of your intention -- your class should <em>only</em> have access to what it needs to accomplish its task. Anything additional is at best extra debugging overhead, and at worst, confusing for anyone else who has to read the code. </p> <p>If you are worried about the performance implications of the AS3 event dispatching system (which you shouldn't be, unless you are dispatching hundreds of events per second), then use a delegate pattern instead. Since they use hard references, they will be very fast (easily comparable to just passing in your Main screen directly) and still provide the loose-coupling mojo. Your Dialog will have no idea what class it is sending messages to. The drawback when compared to the observer/listener pattern is that you only get a single "listener". Here's the pattern example:</p> <p>IDialogDelegate.as</p> <pre><code>package { public interface IDialogDelegate { function submitSelected():void; } } </code></pre> <p>MainScreen.as</p> <pre><code>package { public class MainScreen extends Sprite implements IDialogDelegate { private var _dialog:Dialog; public function MainScreen() { super(); _dialog = new Dialog(); _dialog.delegate = this; addChild(_dialog); } public function submitSelected():void { trace("handled!"); } } } </code></pre> <p>Dialog.as</p> <pre><code>package { public class Dialog extends Sprite { private var _delegate:IDialogDelegate private var _submitButton:Button; public function Dialog() { _submitButton = new Button(); _anExampleActionButton.label = "Submit"; _anExampleActionButton.addEventListener(MouseEvent.CLICK, onExampleActionSelected, false, 0, true); addChild(_anExampleActionButton); } public function set delegate(value:IDialogDelegate):void { _delegate = value; } private function onExampleActionSelected(event:MouseEvent):void { if(delegate != null) { delegate.submitSelected(); } } } </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.
    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.
    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