PDA

View Full Version : Image Flip With Sound



derek barnstorm
07-02-2006, 08:54 PM
I am using the follwing script to flip an image and play sound at the same time. It all works fine in IE, but does anybody know of a script that does the same thing but is cross browser?

<head>
<script>
var aySound = new Array();
// Below: source for sound files to be preloaded
aySound[0] = "bang_1.wav";
aySound[1] = "bang_2.wav";

// DO NOT edit below this line
document.write('<BGSOUND ID="auIEContainer">')
IE = (navigator.appVersion.indexOf("MSIE")!=-1 && document.all)? 1:0;
NS = (navigator.appName=="Netscape" && navigator.plugins["LiveAudio"])? 1:0;
ver4 = IE||NS? 1:0;
onload=auPreload;

function auPreload() {
if (!ver4) return;
if (NS) auEmb = new Layer(0,window);
else {
Str = "<DIV ID='auEmb' STYLE='position:absolute;'></DIV>";
document.body.insertAdjacentHTML("BeforeEnd",Str);
}
var Str = '';
for (i=0;i<aySound.length;i++)
Str += "<EMBED SRC='"+aySound[i]+"' AUTOSTART='FALSE' HIDDEN='TRUE'>"
if (IE) auEmb.innerHTML = Str;
else {
auEmb.document.open();
auEmb.document.write(Str);
auEmb.document.close();
}
auCon = IE? document.all.auIEContainer:auEmb;
auCon.control = auCtrl;
}
function auCtrl(whSound,play) {
if (IE) this.src = play? aySound[whSound]:'';
else eval("this.document.embeds[whSound]." + (play? "play()":"stop()"))
}
function playSound(whSound) { if (window.auCon) auCon.control(whSound,true); }
function stopSound(whSound) { if (window.auCon) auCon.control(whSound,false); }

if (document.images)
{img1on = new Image();
img1on.src = "images/buttons/home_over.gif";
img1off = new Image();
img1off.src = "images/buttons/home.gif";}

{img2on = new Image();
img2on.src = "images/buttons/photos_over.gif";
img2off = new Image();
img2off.src = "images/buttons/photos.gif";}

function imgOn(imgName) {
if (document.images) {
document[imgName].src = eval(imgName + "on.src");}
}
function imgOff(imgName) {
if (document.images) {
document[imgName].src = eval(imgName + "off.src");}
}
//
</script>
</head>


<body>
<a href="home.html" target="_top" onMouseOver="imgOn('img1'), playSound(0)" onMouseOut="stopSound(0), imgOff('img1')"><img src="images/buttons/home.gif" name="img1" border="0" alt="Home"></a>
<a href="photos.html" target="_top" onMouseOver="imgOn('img2'), playSound(1)" onMouseOut="stopSound(1), imgOff('img2')"><img src="images/buttons/photos.gif" name="img2" border="0" alt="Photos"></a>
</body>