A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Auto update dynamic text box with PHP/SQL?

  1. #1
    Member
    Join Date
    Nov 2007
    Posts
    36

    Auto update dynamic text box with PHP/SQL?

    I have a dynamic text box that I'm loading data into from a PHP file using loadVariablesNum("data.php", 0);

    The PHP runs a SQL query that fetches data from MySQL. The data in the MySQL database changes frequently, and I want to update the dynamic text box with the latest info.

    How do you do that? Or is it possible? I assume you use setInterval.

    Currently, it only updates the field if I visit the PHP file and refresh the data. Otherwise, the dynamic text box just displays the data from the last SQL query.

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    I assume you use setInterval.
    yes. depending on your app., every 1 or more seconds.

    gparis

  3. #3
    Member
    Join Date
    Nov 2007
    Posts
    36
    So it is possible then? I guess my question is - can the SWF can trigger the PHP to run the query? or do I still need to set up some other automation (chron job) for that?

  4. #4
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    setInterval calls a function at set intervals. So, make your call to php into a function.

    gparis

  5. #5
    Member
    Join Date
    Nov 2007
    Posts
    36
    The flash movie won't refresh the PHP. So I have it set up to refresh every second:

    Actionscript Code:
    phpData = new LoadVars();
    phpData.onLoad = function(){
        txtTest.html=true;
        txtTest.htmlText = phpData.content;
    }
    var timeint1;
    timeint1=setInterval(fetchData,1000);

    function fetchData() {
        phpData.load("data.php");
    }

    I can get it to auto refresh if I set up a refresh in the PHP - but the movie won't trigger a refresh.

    and another question....

    It seems that I can't get the loadVars to load anything but predefined variables, such as "content" and "name". I can't get it to load "myFavVar" for example. Is that a restriction or is there a trick?

    Is there any benefit to using loadVariables("data.php","") instead?

    BTW, I'm using Flash Pro 8 and AS 2.0
    Last edited by benflashkit; 03-22-2010 at 01:19 PM.

  6. #6
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    Your code is fine. If you add a trace in the onLoad, you'll see the php is called every second by the flash.

    It seems that I can't get the loadVars to load anything but predefined variables, such as "content" and "name". I can't get it to load "myFavVar" for example. Is that a restriction or is there a trick?
    in the onLoad:
    myFavVar = this.myFavVar; // this is refering to the LoadVars

    you'll get the myFavVar variable on that code's timeline.

    Is there any benefit to using loadVariables("data.php","") instead?
    no.

    gparis

  7. #7
    Member
    Join Date
    Nov 2007
    Posts
    36
    Thanks!

    Here's what I have now:

    Actionscript Code:
    var myData1:LoadVars=new LoadVars();
    myData1.onLoad = function () {
        txtTest.text = this.money;
        txtTest1.text = this.mySql;
    }

    var timeint1;
    timeint1=setInterval(fetchData,1000);
    function fetchData() {
        myData1.load("data.php");
    }

    I'm still working on the PHP refresh problem. If I put a refresh header in the PHP file, it works in the movie only if I have it open in a browser. So if I'm playing JUST the movie, the PHP doesn't refresh. The PHP is fetching data from a database, but it doesn't re-query unless I go directly to the /data.php file and make it happen. The movie won't do it.

    Is there a way to get the movie to execute the PHP code? should I use a POST or GET to do it somehow?

    Thanks for your help. I'm new at AS.

  8. #8
    Member
    Join Date
    Nov 2007
    Posts
    36
    This seems to work:

    myData1.sendAndLoad("http://localhost/myscript/data.php", myData1, "POST")

    I'm learning.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center