Playing sound with mouse down

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Location: Kent, UK
Contact:

Playing sound with mouse down

Post by gyroscope » Sat Mar 06, 2010 9:02 pm

Hi, I've an image, and when I drag a link to it, I would want it, amongst other things, to make a sound if the mouse is down, i.e if the mouse is "holding" the link. I can't work out why the following doesn't work though.

Code: Select all

on mouseEnter
   if the mouse is "down" then
   play audioclip "Bird-chirp (Red Lories) animals120.wav"
-----
------- etc
end if
end mouseEnter
Any help appreciated!

:)

Regulae
Posts: 136
Joined: Tue Oct 20, 2009 6:05 am
Location: Australia

Re: Playing sound with mouse down

Post by Regulae » Sun Mar 07, 2010 7:26 am

When the mouse is down, mouseEnter messages are not sent to underlying objects. In the Rev dictionary for “mouseEnter”:
“If the mouse button is down when the mouse pointer enters the control, no mouseEnter message is sent unless the mouse button is released while the pointer is still in the control.”
You can get your sound played with dragEnter instead:

Code: Select all

on dragEnter
      play audioclip "Bird-chirp (Red Lories) animals120.wav"
-----
------- etc
end dragEnter
... in the script of your image. For the dragEnter message to be sent, a drag and drop must be first initiated by setting the dragData property. If the user selects text in an unlocked field, then click/drags it, the dragData is set to the selected text. For locked fields, or other controls e.g. buttons, set the dragData in the mouseDown of their scripts, e.g. if you put the following in the script of a button:

Code: Select all

on mouseDown
   set the dragData["Text"] to "Hello"
end mouseDown
... click the button and drag the mouse into your image, it would receive a dragEnter message, and play the audioclip. The section “Initiating a Drag Drop” in the Rev User Guide is a useful discussion of the range of messages sent during drag drops. It’s not a feature I’ve used extensively myself, so I hope I’m being relevant to your question.

Regards,

Michael

gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Location: Kent, UK
Contact:

Re: Playing sound with mouse down

Post by gyroscope » Sun Mar 07, 2010 12:58 pm

Thank you Michael, exactly what's needed!

:)

thatkeith
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 346
Joined: Mon Mar 01, 2010 7:13 pm
Location: London, UK
Contact:

Re: Playing sound with mouse down

Post by thatkeith » Mon Mar 08, 2010 2:42 pm

Another angle might be to work with a mouseStillDown handler.
Just a comment, as I think you're already using the best option. But it can sometimes be helpful and educational to think of different ways to get to a desired end result.

k
Technical Writer, Meta
University Lecturer
Technical Editor, MacUser (1996-2015)
360 VR media specialist

Regulae
Posts: 136
Joined: Tue Oct 20, 2009 6:05 am
Location: Australia

Re: Playing sound with mouse down

Post by Regulae » Mon Mar 08, 2010 4:27 pm

That’s a very good point, and it’s useful to have alternatives in mind. I had forgotten about mouseStillDown and it comes in handy on occasion. Sometimes you don’t want to initiate the machinery of drag and drop, with the cursors changing and so forth. Thanks for the reminder.

Regards,

Michael

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”