Quantcast
Channel: LiveCode Forums
Viewing all articles
Browse latest Browse all 821

Getting Started with LiveCode - Complete Beginners • Drag & Drop?

$
0
0
Hi everyone,

I have a simple stack that I want to be able to drag and drop a text file (and only a text file) from the desktop (or other location) onto the stack interface and have it put the contents of the text file into a text field. Here is my code (which is in the stack script) but it's not working (nothing happens):

CODE:

on dragEnter   -- Check if the dropped item is a file   if "file" is among the items of the dragData["type"] then      set the dragAction to "copy" -- Visual feedback for dragging   end ifend dragEnteron dragDrop   -- Check if the dropped item is a file   if "file" is among the items of the dragData["type"] then      -- Get the file path from the drag data      put the dragData["files"] into tFilePath            -- Ensure only one file is processed (if multiple files are dragged)      put line 1 of tFilePath into tFilePath      -- Validate that the file is a text file      if char -4 to -1 of tFilePath is ".txt" then         -- Read the contents of the file         put URL ("file:" & tFilePath) into tFileContents         -- Place the file contents into the "Specs" field         put tFileContents into field "Specs"      else         -- Notify user if the file is not a text file         answer "Please drop a valid text file." with "OK"      end if   end ifend dragDrop
Any ideas? This is my first attempt ever at doing drag & drop with LiveCode so be gentle :wink:

Thank you and best regards,
Jon :)

Statistics: Posted by cmhjon — Tue Nov 19, 2024 11:37 pm



Viewing all articles
Browse latest Browse all 821

Trending Articles