2

I searched the docs and the official forum but I could not find an answer.

In Blockly, I'd like to detect the following things:

  • when a block is connected to another one;
  • when a block is removed from workspace;
  • when workspace is empty;
  • when a user is dragging a block;
  • when a user is releasing a block;

Is it possible? I only found an init and an onchange event.

Karl-Johan Sjögren
  • 16,544
  • 7
  • 59
  • 68

1 Answers1

2

Try this:

    onchange: function(event) {
        if(Blockly.Events.CHANGE === event.type) {
            // do something
        }
    }

Instead CHANGE you can use one of the any accessible events, such as MOVE, DELETE e.t.c. For more details see https://developers.google.com/blockly/guides/configure/web/events

Anm
  • 3,291
  • 2
  • 29
  • 40
isnullxbh
  • 807
  • 13
  • 20
  • 1
    This is the right answer. Change was the first event, originally used for validation before we added the other event types years later. Block connections fall under MOVE. Check for an empty workspace after each DELETE. I don't think we have an event for the start of DRAG. – Anm Feb 27 '18 at 21:32
  • @Ian Bell just to update this answer, some event types are deprecated, for example DELETE now is BLOCK_DELETE and so on... – Eric Dec 09 '18 at 06:59