|
||||||
|
||||||
Tutorial: Flash Sound on HTML Web Pages using JavaScript

Free Flash Sound Tutorial
![]()
The aim of the tutorial is to learn how to add sound to any web page that 99% of all users will be able to hear. With this technique there is no Flash interface on your web page - only sound. It works through standard HTML links or plays automatically when the web page loads. It is compatible with all major browsers and allows you to play different sounds for different HTML links. It also allows you to play many different music file formats like wav, mp3 etc. This works by placing an invisible Flash Movie on your web page that users can't see!
Cross Ref: If you want to add sound to your Flash Movie (and not your HTML web page) see the tutorial on: Using Sound in Flash
Important Note: Many sites use this method for playing sound on their site because of it's ease of use, compatibility for all browser, music types, user friendliness, and ability to play different sounds on different links. It is also possible to preload the Flash file so that it loads invisibly when the web page loads. Having said that if you have a large sound file or multiple sound files in one Flash Movie, then because of the file size it may take some time for the sound to start playing when the user rolls over a link. This may require the user to rollover the link several times before the sound file starts playing. Try to keep the swf file (Flash Movie) size down to a minimum and refrain from using large music files. Instead use multiple swf files for each link instead of one swf file for all the links. Don't use the loop feature unless you need it. This is not a major problem and most user don't experience difficulties but some users on slow Internet connections may not hear the sound, or even realise that there is any sound to be heard!
Example:
Download the invisible Flash file
Int 119a
Rollover Here To Start Playing A Looping Sound
The above are two examples of how to make an Invisible Sound Flash Player.
Step One: Creating the Flash Movie
Note: If you don't have a sound file ready, do a search your hard drive for: mp3 or wav
Webwasp members can download the sound file used on this page: Login or Become a Member
Note: To add a sound to a Keyframe you need to first import a sound into the Library (Step 3 above).
Then you select a Keyframe and use the Sound Option in the Property Inspector to add the sound to the selected frame.

The Sync Properties.
Note: Set the Sync Properties to: Start, Repeat and 1 to play a sound once.
Change the value 1 if you want to play the sound a specific number of times.
Change the second box to: Loop if you want the sound to repeat forever.
Movie Clip Layers and Keyframes.
Note: You Publish the Movie by going to: File > Publish or File > Publish Settings > Publish
There is no need to use the latest Flash Player. In the Publish Settings, click on the Flash Tab and select an older Flash Player such as: Player 5 or Player 6
Step Two: Setting up the Web Page
<script language="JavaScript" src="flashsound.js"></script>
<script language="JavaScript">
var mysound = new FlashSound( );
</script>
<script language="JavaScript">
mysound.embedSWF("Sound.swf");
</script>
Note: If your Flash Movie is not called: Sound.swf - you will need to change the code above.
The next bit of code plays a sound on rollover and stops playing sound on rollout.
The sound will play continuously:
<a href="javascript://" onMouseover = "mysound.gotoAndPlay('/SoundPlayer',
'loop')"onMouseout = "mysound.gotoAndStop('/SoundPlayer','stop')"onClick
= "return false"> Rollover here To Start Playing Sound </a>
To have the sound play once when the page loads use this code:
<body onLoad="mysound.gotoAndStop('/SoundPlayer',
'start')">
Or to have the sound play continually, place this code in the Body Tag:
<body onLoad="mysound.gotoAndStop('/SoundPlayer',
'loop')">
The following Body Tag will preload the Flash file:
<body onLoad="mysound.gotoAndStop('/SoundPlayer', 'stop')">
Note: The start, loop and stop in the code above relates to the frame labels that you created in the Flash Movie.
You can have different sounds on different links by adding additional sounds in your Flash Movie:

Multiple sounds and loops have been added for different links on the web page.
Then refer to each individual sound or loop like so:
You can download an example web page to see how to code your web page here
For advanced users who want to experiment, the following is a list of commands that you can use:
mysound.gotoAndStop('/SoundPlayer', 'start')"
mysound.gotoAndPlay('/SoundPlayer', 'start')"
return false
For other tutorials on how to use this technique:
Why not try out webwasp's new community. Meet new people, find friends in your area: Webwasp Mates & Dates
|
|
|
All material on this site is protected under international copyright © law. DO NOT reproduce any material from this site without written permission. Please ask as permission is often granted.
|