TinyMCE: Cannot call method ‘add’ of undefined

As I was implementing TinyMCE 4.0.5 on a site I got a funny error in my console in chrome:

Uncaught TypeError: Cannot call method ‘add’ of undefined

My implementation looked something like this:

	tinyMCE.init(
	{
		selector: ".WritingArea",
		plugins: "link lists preview anchor spellchecker emoticons textcolor paste",
		toolbar1: "bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | styleselect formatselect fontselect fontsizeselect",
		toolbar2: "cut copy paste | bullist numlist | undo redo | link unlink | forcolor backcolor",
		menubar: false,
        toolbar_items_size: 'small',
		height: "100%",
		resize: false,
		setup: function(ed)
		{
			ed.onInit.add(function(ed)
			{
				tinyMCE.get(ed.target.id).hide();				
			});
		}
	});

The problem turned out to be the change in event handler management. The event onInit isn’t used anymore, instead you bind it like this:

...
		setup: function(ed)
		{
			ed.on("init", function(ed)
			{
				tinyMCE.get(ed.target.id).hide();
			});
		}
...

The documentation is, as I’m writing this, a bit weak on this point but now you know 🙂