views:

106

answers:

1

Hi, I have a WMP player object and I'm trying to add an event listener to intercept ScriptCommands that are sent to the player. Instead of being attached to the WMP object, my callback is being called right away, and then the ScriptCommands aren't being intercepted.

function init() {
      var WMPlayer = document.getElementById("WMPlayer");
      WMPlayer.addEventListener("ScriptCommand", MyScriptCommand(), false);
  alert('init');
  }

  function MyScriptCommand() {
      alert('script');
  }

When I run this, I get the script alert before the init alert.... Does anyone know why this might be happening?

+1  A: 
WMPlayer.addEventListener("ScriptCommand", MyScriptCommand(), false);

needs to be

WMPlayer.addEventListener("ScriptCommand", MyScriptCommand, false);

without the parantheses. With the paranthese, you are calling the function and passing its return value as the listener, rather than the reference to the actual function.

geowa4