1 Reply Latest reply on Mar 10, 2007 4:56 PM by jthereliable

    How to make Flash to wait for user input

    SevenDeserts
      Hi,
      I found this PHP script, then I made some changes to make it FEED the Flash user interface with online user input.
      The main concept of this script is WAITING for user input, so it shows the messages and then go to next line and so on.
      The user input go to directly to TEXT file which writes in lines, each line has a unique id = (mag_id).
      There "get_msge.php" which works as the middleware between FLASH and messages text file.
      The problem, its doesn’t show any data while there are data in the text file.

      Help here please, best regards.
      This is the link of problem illustartion

      AS is:
      // create an object to store the variables
      varReceiver = new LoadVars();
      // load the variables from the text file
      varReceiver.load("get_msg.php?file_id=1&msg_id=1", "POST");
      // trigger something - when the variables finish loading
      varReceiver.onLoad = function(){
      //the variables have finished loading
      if (this.msg_id == 1) {
      _root.xmsg1_swf.text = this.msg;
      _root.xmsg1_ch.text = this.msg;
      gotoAndPlay("line2");
      } else {WAIT }
      }


      PHP is:
      <?php
      //get these values from the FLASH
      $file_id_swf = $_POST ['file_id'];
      $file_name = "messages/messages".$file_id_swf.".txt";
      $msg_id_swf = $_POST ['msg_id']; //_______________________________________________________
      // [0] ."||".[1] ."||".[2] ."||". [3] ."||".[4]."||". [5].
      //$msg_id."||".date."||".time."||".$from."||".$to."||".$msg.

      $fp = fopen ($file_name, 'rb');
      while (!feof ($fp))
      {
      $msg_txt = fgets ($fp, 1024);
      $line = explode ("||", $msg_txt);
      $msg_id = $line[0];
      $from = $line[3];
      $to = $line[4];
      $msg = utf8_encode ($line[5]);

      if ($msg_id == $msg_id_swf)
      {
      echo "msg_id=".$msg_id."&from=".$from."&to=".$to."&msg=".$msg;
      }

      }//while
      fclose ($fp);
      ?>
        • 1. Re: How to make Flash to wait for user input
          jthereliable
          Well, given the things that you've written, I don't think it could. There technically isn't any code in flash that lets it "wait." In order to "wait," you must run the script over again until some condition is met.

          However, your code does look accurate. Why do you need to wait? The onLoad function will be invoked WHEN something is loaded. So, I don't see the reason for the "waiting."

          In addition to that, I would like to say that using text files isn't that great with flash. I have done this before and noticed several problems with using text files. The biggest problem is that the text files are cached after being loaded. Every time you re-load it again, you will get what you got the first time until you reset your cache (ie. close your browser). I suggest using MySQL. (Just my thought.)