:: 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. :(

New Comment

Cookie Warning

We were unable to retrieve our session cookie from your web browser. If reloading this page does not get rid of this message, please read this to learn more.

You will not be able to post until you resolve this problem.

Comment (You can use HTML, but please double-check web link URLs and HTML tags!)
Your Name
Homepage (optional, don't include http://)
Email (optional, but automatically spam protected so please do)
The moon orbits around what? (What's this?)

Admin Log In