:: The story of a lone developer's quest to build an online world
:: MMO programming, design, and industry commentary
[The Imperial Realm :: Miranda] [Blog] [Gallery] [About]

The One Man MMO Project: Javascript is Tedious

By Robert Basler on 2012-05-15 14:50:42
Homepage: www.onemanmmo.com email:one at onemanmmo dot com

In Chrome, if you try to use event.dataTransfer.getData("Text") in the dragend event handler, it returns "undefined". In the drop event it works fine. Huh?

Workaround: replace event.dataTransfer.* with dataTransferString as follows. This has the added benefit of also working in all other drag events.


var dataTransferString;

function onDragStart(event) {
dataTransferString = this.id;
...

function onDragEnd(event) {
var sourceId = dataTransferString;
...

function onDrop(event) {
var sourceId = dataTransferString;
...

By Robert Basler on 2012-05-15 18:08:28
Homepage: www.onemanmmo.com email:one at onemanmmo dot com
The original code worked fine in Firefox. Turns out the new code which works in Chrome, doesn't work in Berkelium (also Chrome) which has a broken HTML5 Drag and Drop. You can drag, but not drop, the cursor doesn't change and the drag image doesn't get rendered. It looks like I'll be hacking together my own Javascript drag and drop system. :(

Add New Comment to this Topic

Admin Log In