Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As an adjunct to the answer by Christophe Herreman, and in case you were wondering, here is a way of making your own events...</p> <pre><code>package yourpackage.events { import flash.events.Event; [Event(name="EV_Notify", type="yourpackage.events.EV_Notify")] public class EV_Notify extends Event { public function EV_Notify(bubbles:Boolean=true, cancelable:Boolean=false) { super("EV_Notify", bubbles, cancelable); } } } </code></pre> <p>I have taken the liberty of setting the default value of <code>bubbles</code> to true and passing the custom event type to the super constructor by default, so you can then just say...</p> <pre><code>dispatchEvent(new EV_Notify()); </code></pre> <p>In your particular case I doubt there are times when you would not want your event to bubble.</p> <p>The prefix <code>EV_</code> on the name is my own convention for events so I can easily find them in the code completion popups, you'll obviously pick your own name.</p> <p>For the two cases you cite you can either have two events and listen for both of them, or add a property to the event which says what just happened, which is the approach which is taken by controls like <code>Alert</code>...</p> <pre><code>package yourpackage.events { import flash.events.Event; [Event(name="EV_Notify", type="yourpackage.events.EV_Notify")] public class EV_Notify extends Event { public static var BUTTON_PRESSED:int = 1; public static var ANIMATION_ENDED:int = 2; public var whatHappened:int; public function EV_Notify(whatHappened:int, bubbles:Boolean=true, cancelable:Boolean=false) { this.whatHappened = whatHappened; super("EV_Notify", bubbles, cancelable); } } } </code></pre> <p>then you call it as follows...</p> <pre><code>dispatchEvent(new EV_Notify(EV_NOTIFY.ANIMATION_ENDED)); </code></pre> <p>you can then inspect the whatHappened field in your event handler.</p> <pre><code>private function handleNotify(ev:EV_Notify):void { if (ev.whatHappened == EV_Notify.ANIMATION_ENDED) { // do something } else if (ev.whatHappened == EV_Notify.BUTTON_PRESSED) { // do something else } etc... } </code></pre> <p>HTH</p>
 

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