Loading ...
Sorry, an error occurred while loading the content.

CustomEvent with YAHOO.util.EventProvider

Expand Messages
  • ugly_kid_joe_a
    Hi all, I m afraid I haven t completely understood how to listen to custom events by the means of YAHOO.util.EventProvider . I have created a Listener and a
    Message 1 of 1 , Apr 30, 2008
    • 0 Attachment
      Hi all,

      I'm afraid I haven't completely understood how to listen to custom
      events by the means of "YAHOO.util.EventProvider". I have created
      a "Listener" and a "Notifier" object. The listener shall react on
      the "myEvent" custom event fired by the notifier.

      Can anyone here please tell me what I'm missing?
      Thanks very much in advance,
      Joe

      ---------------------------------------------------------------

      <html>
      <head>
      <script type="text/javascript"
      src="http://yui.yahooapis.com/2.5.1/build/yahoo-dom-event/yahoo-dom-event.js"></script>

      <script type="text/javascript">
      Listener = function() {
      this.subscribe("myEvent", function() {
      alert("Notified");
      });
      };

      YAHOO.lang.extend(Listener, YAHOO.util.EventProvider, {
      });

      Notifier = function() {
      var event = this.createEvent("myEvent");
      };

      YAHOO.lang.extend(Notifier, YAHOO.util.EventProvider, {
      notify: function() {
      this.fireEvent("myEvent", {});
      alert("Fire");
      }
      });

      var l = new Listener();
      var n = new Notifier();
      </script>
      </head>
      <body>
      <button onclick="n.notify()">Click me</button>
      </body>
      </html>
    Your message has been successfully submitted and would be delivered to recipients shortly.