Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Nested Javascript problem

    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

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Remove the script tag inside the document.write statement.
    Code:
    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.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •