#1
  1. Obsolete Vernacular
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    76012
    Posts
    278
    Rep Power
    14

    Random Flash with JavaScript


    I'm working on this code to generate a random Flash movie.


    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    var howMany = 3
    var movie = new Array(howMany+1)
    movie[0]="http://www.flophouse.org/flashnav.swf"
    movie[1]="http://www.flophouse.org/flashnav2.swf"
    movie[2]="http://www.flophouse.org/flashnav3.swf"
    movie[3]="http://www.flophouse.org/flashnav4.swf"
    function rndnumber(){
    var randscript = -1
    while (randscript < 0 || randscript > howMany || isNaN(randscript)){
    randscript = parseInt(Math.random()*(howMany+1))
    }
    return randscript
    }
    quo = rndnumber()
    quox = movie[quo]
    -->
    </SCRIPT>

    That works fine. If I write document.write(quox) it writes one of the URLs down. My problem is writing this into the actual HTML. I can't seem to get it right. Does anyone have any ideas? Should I be writing the entire Flash Object into a document.write script, or is there an easy way to call a JavaScript variable from a regular HTML page?
  2. #2
  3. No Profile Picture
    Seņor Member
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2000
    Posts
    1,157
    Rep Power
    37
    Since you can't insert <script> tags in the middle of another tag (which is what you would have to do to accomplish what you are asking in your last question), you will need to output the entire block of code (the <object> tag and also the <embed> tag, if you are using it, via document,write in the JavaScript. In the document.write, you can pass the variable. Basically, something like: document.write("blah blah" + variable + "blah blah").
    Michael
  4. #3
  5. Obsolete Vernacular
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    76012
    Posts
    278
    Rep Power
    14

    Talking


    Thanks for your help! But only one problem: To define the quotes inside the HTML tags within the document.write("") function, what would I type? Like should it be

    document.write("<object name=\"objectname\">")

    ?
  6. #4
  7. No Profile Picture
    Seņor Member
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2000
    Posts
    1,157
    Rep Power
    37
    Yes, or you can use ' instead of ".
    Michael

IMN logo majestic logo spyfu logo threadwatch logo seochat tools logo