Page 1 of 1

Playing sound with mouse down

Posted: Sat Mar 06, 2010 9:02 pm
by gyroscope
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!

:)

Re: Playing sound with mouse down

Posted: Sun Mar 07, 2010 7:26 am
by Regulae
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

Re: Playing sound with mouse down

Posted: Sun Mar 07, 2010 12:58 pm
by gyroscope
Thank you Michael, exactly what's needed!

:)

Re: Playing sound with mouse down

Posted: Mon Mar 08, 2010 2:42 pm
by thatkeith
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

Re: Playing sound with mouse down

Posted: Mon Mar 08, 2010 4:27 pm
by Regulae
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