Skip to main content
Inspiring
May 5, 2007
Answered

Audio On Roll Over

  • May 5, 2007
  • 7 replies
  • 870 views
This page has a great effect where the audio of the Flash movie only plays while the mouse is over the flash player. I figure they did this with a button and a rollover action but can't seem to replicate it. Any ideas?
This topic has been closed for replies.
Correct answer Sketchsta
you need to specify a SOUND OBJECT before you can play any music. I dont see a sound object in that piece of code.

eg...

var mySound:Sound = new Sound();

then you would load your mp3 file using THAT sound object.

it is THAT sound object that you will control the volume, like so...

btnAudio.onRollOver = function(){
mySound.setVolume(70);
}

and the volume would be at 70 on mouse rollOver.

7 replies

webby7097Author
Inspiring
June 23, 2007
I have just now come back to this, and it works perfectly. Thanks for your help.
SketchstaCorrect answer
Inspiring
May 7, 2007
you need to specify a SOUND OBJECT before you can play any music. I dont see a sound object in that piece of code.

eg...

var mySound:Sound = new Sound();

then you would load your mp3 file using THAT sound object.

it is THAT sound object that you will control the volume, like so...

btnAudio.onRollOver = function(){
mySound.setVolume(70);
}

and the volume would be at 70 on mouse rollOver.
webby7097Author
Inspiring
May 7, 2007
My bad too - I knew that but forgot. It's been a little while, and I am still a novice!

The good news is, on changing the btn name and updating it in the action script, the errors are gone. The bad news is that the rollover appears to have no effect.

I suspect I have not set up my sound object properly somehow. It's an imported MP3, the Name is "TheThrilIsGone", the Type is Sound, and the code is this now:

btnAudio.onRollOver = function(){
TheThrillIsGone.setVolume(100);
}

btnAudio.onRollOut = function(){
TheThrillIsGone.setVolume(0);
}

Your help is greatly appreciated!
Inspiring
May 7, 2007
ohh oops... my bad..

you are getting that error because of your button instance name

btn-audio

you CAN NOT use minus ( - ) in instance names..

sorry i didnt see that before.
you should use under score ( _ ) instead, or type instance names likeThisHere.
webby7097Author
Inspiring
May 7, 2007
Actually, no - the code is on frame one of the actions layer, a layer which contains no objects.

My apologies on the length of the error string above, it included error output from several other lines of script I had failed to remove.

The code is on the frame, not on the object; the error text now reads:

**Error** Scene=Scene 1, layer=actions, frame=1:Line 1: Left side of assignment operator must be variable or property.
btn-audio.onRollOver = function(){

**Error** Scene=Scene 1, layer=actions, frame=1:Line 5: Left side of assignment operator must be variable or property.
btn-audio.onRollOut = function(){
webby7097Author
Inspiring
May 6, 2007
Here's the error output:

**Error** Scene=Scene 1, layer=actions, frame=1:Line 1: Left side of assignment operator must be variable or property.
btn-audio.onRollOver = function(){

**Error** Scene=Scene 1, layer=actions, frame=1:Line 5: Left side of assignment operator must be variable or property.
btn-audio.onRollOut = function(){

**Error** Scene=Scene 1, layer=button, frame=1:Line 1: Statement must appear within on handler
var gSound:Sound = new Sound();

**Error** Scene=Scene 1, layer=button, frame=1:Line 2: Statement must appear within on handler
gSound.setVolume(100);

**Error** Scene=Scene 1, layer=button, frame=1:Line 3: Statement must appear within on handler
gSound.attachSound(TheThrillIsGone.mp3);

**Error** Scene=Scene 1, layer=button, frame=1:Line 5: '(' expected
on = function() {

**Error** Scene=Scene 1, layer=button, frame=1:Line 12: Syntax error.
};

**Error** Scene=Scene 1, layer=button, frame=1:Line 5: Statement block must be terminated by '}'
on = function() {

**Error** Scene=Scene 1, layer=button, frame=1:Line 12: Syntax error.
};

Total ActionScript Errors: 9 Reported Errors: 9

**Error** Scene=Scene 1, layer=actions, frame=1:Line 1: Left side of assignment operator must be variable or property.
btn-audio.onRollOver = function(){

**Error** Scene=Scene 1, layer=actions, frame=1:Line 5: Left side of assignment operator must be variable or property.
btn-audio.onRollOut = function(){

Inspiring
May 6, 2007
Thats afew errors.
but from what i can see, most are caused because you have the code on the object itself, when it's supposed to be on a FRAME.

quote:

Originally posted by: kllwca
Here's the error output:

**Error** Scene=Scene 1, layer=actions, frame=1:Line 1: Left side of assignment operator must be variable or property.
btn-audio.onRollOver = function(){
************** place this code on a FRAME not on the OBJECT. *******************


**Error** Scene=Scene 1, layer=actions, frame=1:Line 5: Left side of assignment operator must be variable or property.
btn-audio.onRollOut = function(){
************** place this code on a FRAME not on the OBJECT. *******************


**Error** Scene=Scene 1, layer=button, frame=1:Line 1: Statement must appear within on handler
var gSound:Sound = new Sound();
************** place this code on a FRAME not on the OBJECT. *******************



**Error** Scene=Scene 1, layer=button, frame=1:Line 2: Statement must appear within on handler
gSound.setVolume(100);
************** place this code on a FRAME not on the OBJECT. *******************



**Error** Scene=Scene 1, layer=button, frame=1:Line 3: Statement must appear within on handler
gSound.attachSound(TheThrillIsGone.mp3);
************** place this code on a FRAME not on the OBJECT. *******************


**Error** Scene=Scene 1, layer=button, frame=1:Line 5: '(' expected
on = function() {
************** check your syntax, go through your code carefully *****************


**Error** Scene=Scene 1, layer=button, frame=1:Line 12: Syntax error.
};
************** check your syntax, go through your code carefully *****************


**Error** Scene=Scene 1, layer=button, frame=1:Line 5: Statement block must be terminated by '}'
on = function() {
************** check your syntax, go through your code carefully *****************


**Error** Scene=Scene 1, layer=button, frame=1:Line 12: Syntax error.
};
************** check your syntax, go through your code carefully *****************

=========================================================================================
//*********** be careful WHERE you use the semi column " ; " if you place it in the wrong place, Flash will skip EVERYTHING that follows it on that line. for egsample...
btn.onRollOver = function() ; {

}
in this obvious example, flash will tell you theres a curly bracket " { " expected.
============================================================================================


Total ActionScript Errors: 9 Reported Errors: 9

**Error** Scene=Scene 1, layer=actions, frame=1:Line 1: Left side of assignment operator must be variable or property.
btn-audio.onRollOver = function(){
************** place this code on a FRAME not on the OBJECT. *******************


**Error** Scene=Scene 1, layer=actions, frame=1:Line 5: Left side of assignment operator must be variable or property.
btn-audio.onRollOut = function(){
************** place this code on a FRAME not on the OBJECT. *******************




Inspiring
May 6, 2007
try:

your_btn.onRollOver = function(){
your_sound_object.setVolume(100);
}

your_btn.onRollOut = function(){
your_sound_object.setVolume(0);
}