PDA

View Full Version : Nested Javascript problem


clivemcl
05-02-2007, 12:48 PM
I have a Javascript which select a function at random.
There are two functions, each function selects a different flash movie.

I call my flash movies with a seperate Javascript which removes the ActiveX crap, called AC_FL_RunContent.

This is how it looks...



<script language="JavaScript">

// Generate a Random Number
var randomnumber = Math.round(Math.random()*2);

// Select a movie and execute the corresponding function
if (randomnumber == 1)

{movie1();}

else {movie2();}

//Functions to write out the correct flash movie resource.

function movie1(){
document.write("
<script type=\"text/javascript\" >
AC_FL_RunContent(\"codebase\",\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\",\"width\",\"180\",\"height\",\"599\",\"src\",\"images/sideguitar\",\"quality\",\"high\",\"name\",\"images/sideguitar\",\"allowscriptaccess\",\"sameDomain\",\"pluginspage\",\"http://www.macromedia.com/go/getflashplayer\",\"movie\",\"images/sideguitar\" );
</script>
")
}



function movie2(){
document.write("
<script type=\"text/javascript\" >
AC_FL_RunContent(\"codebase\",\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\",\"width\",\"180\",\"height\",\"599\",\"src\",\"images/sidefountains\",\"quality\",\"high\",\"name\",\"images/sidefountains\",\"allowscriptaccess\",\"sameDomain\",\"pluginspage\",\"http://www.macromedia.com/go/getflashplayer\",\"movie\",\"images/sideguitar\" );
</script>
")
}


</script>

the problem (i think) is that the </script> of the inner Javascript is closing the outer one.
The output web page gives me text beginning


") } function movie2(){ document.write(" ") }

and no flash :confused:

glenngv
05-02-2007, 04:27 PM
Remove the script tag inside the document.write statement.
function movie1(){
document.write(AC_FL_RunContent("codebase","http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0", "width", "180", "height", "599", "src", "images/sideguitar", "quality", "high", "name", "images/sideguitar", "allowscriptaccess", "sameDomain", "pluginspage", "http://www.macromedia.com/go/getflashplayer", "movie", "images/sideguitar"));
}
This assumes that AC_FL_RunContent function returns the object html tags to write to the page.