Drag 'n' Drop

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Matt9537
Posts: 8
Joined: Tue Oct 02, 2007 4:41 pm

Drag 'n' Drop

Post by Matt9537 » Wed Oct 03, 2007 10:08 am

For school coursework we have to use Revolution Media to make an interractive program. In this we need to use a drag and drop feature. Through many attempts to do this we are unsuccesful, can anyone give us a pointer? We are aware of the 'grab me' command.

I'm sure you're all aware of the drag games where you drag a picture or text over an answer and you get points or womehting happens. For example, matching the pictures with words or rearranging text/pictures into order and getting feedback...

Thanks in advance

Regards

Matt

PS: I have searched through help files and tuturials etc but no succes...please help!

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Wed Oct 03, 2007 11:13 am

Hi Matt,

this code snippet in a button or (locked) field or image will check the location WHERE the "dropping" occured and lets you trigger an action if the location is correct, you get the idea :-)

Code: Select all

local my_old_position
## If you want to "restore" the original position of the "dragged" object

on mouseDown
    set the layer of me to the num of objects
    ## this way the object will alwys be "on top" of all other 
    ## objects on the card

    put the loc of me into my_old_position
   ## store the original loc for a later "snap back" of this object
    grab me
end mouseDown

on mouseUp
    if within(img "the correct answer",the loc of me) then 
     ## do something here in case this is the correct thing
    else
     ## not correct, PUNISH the User :-)
  end if
  ## set the loc of me to my_old_position
  ## or to use a more damatic effect:
  move me to my_old_position in 500 millisecs
end mouseUp
Hope that helps, of course this is only ONE possible approach, but a working and understandable one ;-)


Best from germany

Klaus

Matt9537
Posts: 8
Joined: Tue Oct 02, 2007 4:41 pm

Post by Matt9537 » Wed Oct 03, 2007 12:55 pm

:D Just what i was looking for! Thank you very much.

Though the layer code didn't seem to work (got an error) but thats the least of my worries :). It would be intresting, though, to see other approches.

Thanks again Klaus so easy to follow and I understand it all!

regards

matt

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Wed Oct 03, 2007 1:04 pm

Hi Matt,

sorry, a little typo!

It should read:
...
set the layer of me to the num of CONTROLS
...


Glad I could help :-)


Best

Klaus

Post Reply