Object problem

Jack Michaelson's picture

He has: 1,733 posts

Joined: Dec 1999

Hi everyone,

I want the visitors to my site (not online yet) to decide whether they want a backgroundsound or not. They even can choose what kind of sound they want via a <select>.

The code is below:

&lt;script language="javascript"&gt;
var aySound = new Array();
aySound[0] = "silence.wav";
aySound[1] = "groovearmada.wav";
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 = "&lt;DIV ID='auEmb' STYLE='position:absolute;'&gt;&lt;/DIV&gt;";
document.body.insertAdjacentHTML("BeforeEnd",Str);
}
var Str = '';
for (i=0;i&lt;aySound.length;i++)
Str += "&lt;EMBED SRC='"+aySound[i]+"' LOOP='TRUE' AUTOSTART='FALSE' HIDDEN='TRUE'&gt;"
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);
}

function okdan()
{
var noiz=document.form1.selekd.options[document.form1.selekd.selectedIndex].text;
if (noiz=='Select backgroundsound')
playSound(0);
if (noiz=='--&gt; No sound &lt;--')
playSound(0);
if (noiz=='Groove Armada')
playSound(1);
}
&lt;/SCRIPT&gt;
&lt;/HEAD&gt;
&lt;BODY background="b.gif"&gt;

&lt;form name=form1&gt;
&lt;table border="0" cellspacing="0" cellpadding="0"&gt;
&lt;tr&gt;

&lt;td&gt;
&lt;Select Name="selekd" onchange="okdan()" class="ucselect"&gt;
&lt;option selected&gt;Select backgroundsound&lt;/option&gt;
&lt;option&gt;--&gt; No sound &lt;--&lt;/option&gt;
&lt;option&gt;Groove Armada&lt;/option&gt;
&lt;/select&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/form&gt;
(...)
'

I got 2 problems:
-IE says: Aucon is no object, which I do not get at all, cause NS accepts this object.
-NS does not loop the wav-file, although I say: LOOP='TRUE'

Who helps me out???
Thanx in advance,

Jack

By the way: you can watch it 'work' at
http://www6.ewebcity.com/uppershelf/b.htm

[This message has been edited by Jack Michaelson (edited 31 March 2000).]
[code] was ommited, just put it back... -Mark

[Edited by Mark Hensler on Feb. 06, 2001 at 01:14 AM]

Shakespeare: onclick || !(onclick)

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi,

Don't really do sound, but...

Offhand, I would say Navigator is choking on the quotes. Try escaping instead of putting doubles inside singles inside doubles.

Regarding IE:
If this is where the error-message is:

auCon=IE? document.all.auIEContainer:auEmb;
check the spelling and case;

Vinny

------------------
GrassBlade: cut&paste javascript

Where the world once stood
the blades of grass cut me still

Jack Michaelson's picture

He has: 1,733 posts

Joined: Dec 1999

Thanx Vinny,

Gonna try that.
Greetz,

Jack

Jack Michaelson's picture

He has: 1,733 posts

Joined: Dec 1999

No Vinny,

it won't work.
Who's gonna help me??

Jack

They have: 231 posts

Joined: Feb 2000

I don't know much about embedded sounds but you might want to try loop="-1".

auCon has not been specified as an object so when you try added a property you get an error. Use the following:

auCon = new Object();

:: Lloyd Hassell :: http://www14.brinkster.com/lloydh ::

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.