3 Replies Latest reply on Sep 22, 2006 9:44 AM by Newsgroup_User

    avoiding 'onLoad=[type Function]'

    Leao16
      Hi,

      I have a dynamic text box that retrieves text from a PHP file that in turn retrieves text from a mySQL database. Sometimes the PHP file may necessarily display no text if the mySQL database is empty. However, when the dynamic text box in Flash tries to retrieve text from an empty PHP file the dynamic text box displays onLoad=[type Function]. Is there a way of making the dynamic text box display nothing in such circumstances?

      I have attached the actionscript the dynamic text box uses to retrieve its text and also the PHP code used to retrieve text from the mySQL database.

      Many, many thanks,

      leao
        • 1. Re: avoiding 'onLoad=[type Function]'
          Level 7
          >
          > Actionscript
          > path = " http://www.stpatrickscommunity.org/admin/text/landline.php";
          > lv = new LoadVars();
          > lv.onLoad = function(){
          > str = unescape(this);

          okay, here is the first problem. You don't want to use 'this' here, because
          this is referring to the LoadVars object which includes a reference to its
          own onLoad function. The point of using the LoadVars object in Flash is to
          keep from having to do the type of string manipulations you are doing below.

          > str = str.split("=&onLoad=[type Function]").join("");

          LoadVars creates a property for each of the names of variables in your
          return string. So, for example, if your php returned
          myString=Hello%20World&myOtherString=Good%Night

          Then, in the onLoad function, you can try:
          trace(lv.myString);
          trace(lv.myOtherString);

          What you *should* get is the following:
          Hello World
          Good Night

          That is because LoadVars understands Query Strings and has builtin parsing
          capabilities.

          Also nice --- the onData has a builtin unescape call so you don't have to do
          it (** at least that's what I remember)

          However --- if you really want to do your own string parsing in Flash, then
          instead of the onLoad method you can use the onData(raw) method where raw is
          the raw string coming back from your script. Big difference here is that
          the onLoad mehtod is not included in the string.


          > landline.html = true;
          > landline.htmlText = str;
          > };
          > lv.load(path);
          >
          > PHP
          > <?php
          > header('Content-type: text/html; charset=utf-8');
          > mysql_connect("mysql.myhosting.com","stpatri_user","password") or
          > die(mysql_error());
          > mysql_select_db("stpatri_table") or die(mysql_error());
          > $result = mysql_query("SELECT * FROM text")

          You may want to consider changing the name of you MySQL table name from text
          to something else. Reason being, text is a datatype in MySQL so it should
          be treated as a reserved word.

          > or die(mysql_error());
          > $row = mysql_fetch_array( $result );
          > $str_encoded=urlencode($row['landline']);
          > echo "$str_encoded";
          > ?>

          I don't use PHP ever... but... since it is ripped (I mean based) off of
          PERL, I assume you may want to close your connection - unless it does this
          itself.


          • 2. Re: avoiding 'onLoad=[type Function]'
            Leao16 Level 1
            Hi, I resolved the problem by using XML.onData instead of LoadVars (see attached code).

            Is it really necessary to change mySQL table name from text to something else?

            Many thanks,

            Leao
            • 3. Re: avoiding 'onLoad=[type Function]'
              Level 7

              "Leao16" <webforumsuser@macromedia.com> wrote in message
              news:ef0q9q$gof$1@forums.macromedia.com...
              > Hi, I resolved the problem by using XML.onData instead of LoadVars (see
              > attached code).
              >
              > Is it really necessary to change mySQL table name from text to something
              > else?
              >

              Not 100% necessary, but something to be avioded in the future.

              Also, I think you may have missed the point of the LoadVars class still. I
              assume that you are passing back data in the form of
              key=value&key1=value1
              in which case you should be accessing the data not via the string itself,
              but as a property of LoadVars.

              If you are sending back
              myText=thisismytextwithoutanyspaces

              then the LoadVars property after onLoad (onData) is
              lv.myText

              HTH