Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error can't use nested script

Status
Not open for further replies.

intomuso

Programmer
Jan 26, 2006
19
GB
Hi,

I'm trying to include this javascript file

<script type="text/javascript" src="swfobject.js"></script>

in the function below, but get an error saying I can't use nested scripts. How can I use this file inside the function doSomething. Also how to keep all the page coding outside the function so it doesn't disappear when I click on the button? Thanks for your help this is really doing my head in

####################################

<script type="text/javascript">

function doSomething(str)
{

var flashvars = {};

/* audio player parameters */
flashvars.audio = "str";
//flashvars.autoplay = falses;
/* end */

var params = {};
params.scale = "noscale";
params.allowfullscreen = "true";
params.salign = "tl";

var attributes = {};
attributes.align = "left";

/* embed audio player */
// adapt the path to flashaudioplayer.swf and expressInstall.swf
// adapt the display size of the flash file
swfobject.embedSWF("flashaudioplayer.swf", "audioPlayer", "200", "35", "9.0.28", "expressInstall.swf", flashvars, params, attributes);
/* end */

document.write ('<div id=audioPlayer style=margin:0px> </div>');

}

</script>


<button type="button" onclick="doSomething('str');" return false;>track play</button>






 
You don't need to include it inside your function just include in your page, then just call the functions from the included file that you need.

Code:
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">

    function doSomething(str)
{

        var flashvars = {};
...

 swfobject.embedSWF("flashaudioplayer.swf", "audioPlayer", "200", "35", "9.0.28", "expressInstall.swf", flashvars, params, attributes);
}
</script>



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Hi,

I wish it was that easy, but if you ad it outside the function, it won't be included when you call the function because it's out side the function
 
Of course it is.
Once included all code and functions in your included file are available for use in any part of your script, that's the way includes work.







----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
This might be something else then, because when I click on the button below, the button disappears and I suppose so do the ability to use the <script type="text/javascript" src="swfobject.js"></script> scripts any ideas why that happens?


<button type="button" onclick="doSomething('str');" return false;>track play</button>

thanks,

gavin
 
Looking at your code, what's happening is that your document.write is replacing not only your button, but your entire page with the single player div.
Code:
document.write ('<div id=audioPlayer style=margin:0px> </div>');

This of course has nothing do do with including the js file or being able to use it. Its a completely separate issue.

I would if I where you have the DIV already created, and just alter its display to be shown or hidden instead.

Code:
<script>
 function doSomething(str)
{

        var flashvars = {};
...


document.getElementById('audioplayer').style.display='block';
}
</script>

<div id="audioplayer" style="display:none; margin:0px;"></div>
<button type="button" onclick="doSomething('str');" return false;>track play</button>




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top