/    Sign up×
Community /Pin to ProfileBookmark

onmouseover event

hi everyone,
i am trying to assign the sounds to my buttons. it works when the mouse is over them. the problem is that i do not want the sound to play when i touch the same button again.
please help, i am a beginner with js

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@FangMar 13.2009 — onmouseover="playSound();" onmouseout="this.onmouseover=null;"
Copy linkTweet thisAlerts:
@jayapalchandranMar 13.2009 — i haven't tried like the above reply... that should work well too i hope... anyway here is one silly example

<script>

var soundflag=1;

</script>

onmouseover="if(soundflag){playsound();soundflag=0;}"

the above will work one time so the sound plays one time...
Copy linkTweet thisAlerts:
@wolandtauthorMar 13.2009 — thanks a lot, i'm running to try it ?
Copy linkTweet thisAlerts:
@wolandtauthorMar 14.2009 — i have another issue:

what if i want to play the sound again but not two times in raw? i mean to play the sound again i need to play different sound touching another button before. is there any easy way to do it?
Copy linkTweet thisAlerts:
@FangMar 15.2009 — Then the second button has to add the event to the first button.
Copy linkTweet thisAlerts:
@jayapalchandranMar 15.2009 — Firstly, let me tell you what i understood from your query.

you have a page where you have 'n' buttons. Once a button say 'i' has been clicked then for the next click it should not work. So once it is clicked until you reload the page it should not be clicked again. and you want to apply this for all buttons which will play sound.

for that here is another silly answer

you can have as many as flag variables for each buttons like psbtn1, psbtn2, etc... and repeat the same code by changing the variable names... like the following...

<script>

var psbtnv1=psbtnv2=psbtnv3=1;

</script>

//input name='psbtn1'

onmouseover="if(psbtnv1){playsound();psbtnv1=0;}"

//input name='psbtn1'

onmouseover="if(psbtnv2){playsound();psbtnv2=0;}"

//input name='psbtn1'

onmouseover="if(psbtnv3){playsound();psbtnv3=0;}"

and then you can use your intelligence to create a robust way of using it by creating objects...

if the above code does not match your need then ping again.

[COLOR="Red"][B]above all here is one idea



<input type='button' name='psbtn1' value='play one' onclick='this.disabled=true'>

[/B]
[/COLOR]



or if you want the button to be disabled after a few seconds then use timers

...
Copy linkTweet thisAlerts:
@wolandtauthorMar 15.2009 — thanks for response, but i wasn's clear with my query.

here is a script i have:
[code=html]
<script type="text/javascript">
function mouseOver1() {
document.getElementById("b1").src ="images/tree2bb.jpg";
soundManager.play('mo');
changeimage(myimages[1]);
}
function mouseOver2() {
document.getElementById("b2").src ="images/tree2cb.jpg";
soundManager.play('mo');
changeimage(myimages[2]);
}
function mouseOver3() {
document.getElementById("b3").src ="images/tree2db.jpg";
soundManager.play('mo');
changeimage(myimages[3]);
}
</script>
[/code]

and i have 3 buttons with onmouseover events:

mouseOver1()

mouseOver2()

mouseOver3()

and now:

when i mouse over button 1 and the sound is played i want to disable it (soundManager.play('mo') function for button 1) for a while - until the sound from any of the other buttons (2 or 3) is played. so for instance when the soundManager.play('mo') of the button 2 is played i can again use this function for the button 1 without reloading the page.

hope this time it's clear (i'm just a beginner)

can u halp???
Copy linkTweet thisAlerts:
@jayapalchandranMar 17.2009 — [CODE]
<script>
var psbtn=0

function a()
{
if(psbtn==1)return;

// your code
alert('i am playing a');

psbtn=1;
}

function b()
{

if(psbtn==2)return;

// your code
alert('i am playing b');

psbtn=2;

}

function c()
{
if(psbtn==3)return;

// your code
alert('i am playing c');

psbtn=3;

}

</script>

<input type="button" value="A" onclick="a()" />
<input type="button" value="B" onclick="b()" />
<input type="button" value="C" onclick="c()" />

[/CODE]


we can have another example but that includes another function and some process so i hope this will do.

so with your code it would be like this...

[CODE]
<script type="text/javascript">
var psbtn=0;
function mouseOver1() {
if(psbtn==1)return;
document.getElementById("b1").src ="images/tree2bb.jpg";
soundManager.play('mo');
changeimage(myimages[1]);
psbtn=1;
}
function mouseOver2() {
if(psbtn==2)return;
document.getElementById("b2").src ="images/tree2cb.jpg";
soundManager.play('mo');
changeimage(myimages[2]);
psbtn=2;
}
function mouseOver3() {
if(psbtn==3)return;
document.getElementById("b3").src ="images/tree2db.jpg";
soundManager.play('mo');
changeimage(myimages[3]);
psbtn=3;
}
</script>
[/CODE]


if you want more then reply here

...
Copy linkTweet thisAlerts:
@wolandtauthorMar 17.2009 — that works!!! thanks a lottt
×

Success!

Help @wolandt spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...