Static Listeners in Action Script 3

  • strict warning: Non-static method view::load() should not be called statically in /nfs/c04/h02/mnt/64527/domains/ on line 842.
  • strict warning: Declaration of content_handler_field::options() should be compatible with views_object::options() in /nfs/c04/h02/mnt/64527/domains/ on line 208.
  • strict warning: Declaration of views_handler_filter::options_validate() should be compatible with views_handler::options_validate($form, &$form_state) in /nfs/c04/h02/mnt/64527/domains/ on line 589.
  • strict warning: Declaration of views_handler_filter::options_submit() should be compatible with views_handler::options_submit($form, &$form_state) in /nfs/c04/h02/mnt/64527/domains/ on line 589.
  • strict warning: Declaration of views_plugin_style_default::options() should be compatible with views_object::options() in /nfs/c04/h02/mnt/64527/domains/ on line 25.
  • strict warning: Declaration of views_plugin_row::options_validate() should be compatible with views_plugin::options_validate(&$form, &$form_state) in /nfs/c04/h02/mnt/64527/domains/ on line 135.
  • strict warning: Declaration of views_plugin_row::options_submit() should be compatible with views_plugin::options_submit(&$form, &$form_state) in /nfs/c04/h02/mnt/64527/domains/ on line 135.

Hypothetical sitatuion: Let's say you have a Flash/Flex AS3 video player and a play button which are nested inside separate parents. Your play button listens to when your player is PLAYING so that it can update it's display accordingly (shows a play icon when the player is paused and shows a pause icon when the player is playing).

Let's assume that the play button is getting constructed before the player. When you try to add a listener to your player singleton, you get an error because the player singleton hasn't been constructed yet. How do you combat this in a systematic, yet elegant matter? I'm sure there are several ways, but here's how I do it using static functions.

This strategy is straight forward and simple to understand. You simply store the listener (or event) on the class where it waits until the your singleton is constructed before introducing it's self. I've given an example below of what this code looks like:

Viola. You can use this strategy in numerous ways. I recently used it to dispatch ready listeners on a singleton that didn't exist yet.

You might ask, "Why wouldn't I just call a function to the other object or something simple like that?" Well, I can reply nothing more than my strategy is for those, who like myself, have a twisted love for the function name 'addEventListener'. The End.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <p> <pre>
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or "class="OPTIONS" title="the title".
  • Lines and paragraphs break automatically.
  • E-Mail addresses are hidden with reCAPTCHA Mailhide.

More information about formatting options

Complete this form and then pat yourself on the back.