topical media & game development

talk show tell print

mobile-game-ch09-event-test.htm / htm



  <!DOCTYPE HTML>
  <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title></title>
  
      <script src='mobile-game-ch09-jquery.min.js'></script>
      <script src='mobile-game-ch09-underscore.js'></script>
      <script src='mobile-game-ch09-quintus.js'></script>
    </head>
    <body>
      <script>
        var EventTest = Quintus();
  
        var player = new EventTest.Evented();
        player.name = 'Frank';
        player.sceneOver = function() {
          console.log(this.name + " sceneOver method");
        };
  
        var scene = new EventTest.Evented();
  
        scene.bind('start',player,function() {
          console.log(this.name + " listening to start event");
        });
  
        scene.bind('end',player,'sceneOver');
  
        console.log("======== triggering start and end ========");
        console.log(": Should see two listeners trigger");
        // Should see both console.log calls
        scene.trigger('start');
        scene.trigger('end');
  
        scene.unbind('start',player);
  
        console.log("======== triggering start and end ========");
        console.log(": Should see only end listener");
        // Should see only the end event
        scene.trigger('start');
        scene.trigger('end');
  
        player.debind();
  
        console.log("======== triggering start and end ========");
        console.log(": Should see no listeners");
        // Should see no events
        scene.trigger('start');
        scene.trigger('end');
  
      </script>
  
    </body>
  </html>
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.