Welcome, Guest
  • Author Topic: Random Text in Flash  (Read 2359 times)

    Rugrat

    • Server what's that
    • *
    • Posts: 48
      • View Profile
      • Email
    Random Text in Flash
    « on: 02/23/02, 18:18 »
    Hello,

    I am a relative newbie to flash and php scripting and would appreciate some help in regards to a "hopefully" simple project.

    I have written a php script that searches a database and pulls out a random word from the database.  It works fine if you view just the php in the web browser on-line. Code is shown here:

    <?php

    // use the connection to the database with the variable $dbcnx

    $dbcnx = mysql_connect('localhost','******','*****');

    // select the database that you wish to use

    mysql_select_db('*******');


    // store in the variable news the sql query and error trapping


    $blah = @mysql_query("SELECT ID, Keyword FROM tblKeyword ORDER BY RAND() LIMIT 1");
    if (!$blah) {
     echo("<p>Error retrieving news from database!<br />".
          "Error: " . mysql_error() . "</p>");
     exit();
    }


    // build an array to contain the whole list of classmembers
    // the htmlspecialchars codes the html for special characters

    while ($new = mysql_fetch_array($blah)) {
     $id   = $new["ID"];
     $varkeyword = htmlspecialchars($new["Keyword"]);

    print "&keywordtext=" . urlencode("$varkeyword") . "&";
    }
    ?>

    Now to the specific nature of the problem.  I want my flash movie to display the words in a random way. I set up a dynamic text box within  a movie clip called textmovieclip.  How do I get the instances of the movie clip to display the random words from the database?  I am just using loadVariables to reference the php script.  But each time the textmoveclip displays the same word.  I think I have to reload the script each time and I am not sure how to do that.

    Thanks,

    Derek

    flashswami

    • Jr. Programmer
    • **
    • Posts: 55
    • vene vidi vector
      • View Profile
      • Flashswami
    Re:Random Text in Flash
    « Reply #1 on: 02/23/02, 18:41 »
    Try putting the dynamic text box inside a movieclip. Give this mc an instance name and place your loadVariables script inside this mc on frame1, together with the dynamc text box. Add this just before the loadVariables script-

    r=random(999);

    This will append a randomo value to the url string when you initiate the loadvariables action, effectvley making sure Flash loads a 'fresh' script every time. Now, lets say your PHP script is called 'fetcher.php', your loadvariables action should be-

    loadVariablesNum ("fetcher.php", this, "GET");

    Now, extend the timeline of your mc over, say, 40 frames. This means that every 40 frames the mc will loop, hit frame1 again and hopefully return a random word.

    Rugrat

    • Server what's that
    • *
    • Posts: 48
      • View Profile
      • Email
    Re:Random Text in Flash
    « Reply #2 on: 02/23/02, 20:13 »
    Thank- you very much for you help. It worked great.    :)

    Derek

    flashswami

    • Jr. Programmer
    • **
    • Posts: 55
    • vene vidi vector
      • View Profile
      • Flashswami
    Re:Random Text in Flash
    « Reply #3 on: 02/24/02, 02:58 »
    No worries, glad to help :)