Start/Stop a sound with MouseWithin and MouseLeave

Visuals, audio, animation. Blended, not stirred. If LiveCode is part of your rich media production toolbox, this is the forum for you.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ETphonehome
Posts: 11
Joined: Sun Nov 10, 2013 11:53 am

Start/Stop a sound with MouseWithin and MouseLeave

Post by ETphonehome » Sun Nov 10, 2013 12:24 pm

Hello from France,
Great software LiveCode ! I'm using the 6.5 version on windows 7

I would like to start a sound when I put the mouse on an image and stop it immediatly when the mouse is out of the image.

I did this first step and there's yet a problem :

On MouseWithin
play audioClip "C:\TEST\hello.wav"
end MouseWithin

=> When the mouse is on the image, the sound starts. But not one time ! It starts again and again quickly and the sound is never entirely heard (it's a 5 seconds sound that is heard during maybe 0,10 seconds only !).
Is it a bug ? I want it to start it just one time.
It doesn't mean that I don't want to hear it many times after it stars one time ! (for example using "looping").

If I do this next :

On MouseWithin
play audioClip "C:\TEST\hello.wav"
wait until the sound is done
end MouseWithin
On MouseLeave
play stop
end MouseLeave

=> when the mouse is on the image the sound starts one time (no perpetual repeats) but it doesn't stop when I leave the image !

I tried many many things like using "if" loop but there's alaways something that doesn't do what I want.
Any idea ?

Thank you very much. Stéphane.

Klaus
Posts: 13866
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Start/Stop a sound with MouseWithin and MouseLeave

Post by Klaus » Sun Nov 10, 2013 12:35 pm

Bonjour Stéphane,

1. welcome to the forum! :D

2. Do not use "mousewithin"! This is being sent continously WHILE the mouse is within the object!
Use "mouseenter", I am sure that is what you are looking for.

This message is sent ONCE when the mouse ENTERs (HOVER in HTML/CSS) an object:

Code: Select all

On MouseEnter
  ## LC uses the UNIX SLASH / as the internal path delimiter!
  ##  play audioClip "C:\TEST\hello.wav" 
  play audioClip "C:/TEST/hello.wav" 
end MouseEnter
Best

Klaus

ETphonehome
Posts: 11
Joined: Sun Nov 10, 2013 11:53 am

Re: Start/Stop a sound with MouseWithin and MouseLeave

Post by ETphonehome » Sun Nov 10, 2013 10:31 pm

Thank you very much Klauss for :
1) Your welcomming
2) your very quick answer
3) the perfectly right answer : it works !

So the code in order to do what I wanted is :
On MouseEnter
play audioClip "C:/TEST/hello.wav" looping
end MouseEnter

On MouseLeave
play stop
end MouseLeave

In fact it seems that the "dictionnary" of LiveCode is a bit confusing for me. I didn't understand what MouseEnter was supposed to do... I made other interpretation of what they say... ! Also the not thematic classification (nothing about "mouse events") is a kind of difficulty for me. Anyway : thank you again for your help. :-)

Stéphane

Post Reply

Return to “Multimedia”