SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Jul 2002
    Location
    Italy
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Flash updating with PHP

    I'm trying to write to a text file from my Flash movie. My Actionscript is

    Code:
    var mydata = new LoadVars();
    mydata.score = _root.userScore.text;
    mydata.sendAndLoad("http://localhost/www/Playing/quiz1a.php","_self","POST");
    and my PHP code

    PHP Code:
    $fh fopen ("quizs.csv""a+");
    $record $_POST['score'] . "," date("YmdHi") . "," $_SERVER['REMOTE_ADDR'] . "\n";
    fwrite ($fh$record);
    fclose ($fh); 
    although it doesn't even seem to get to run the PHP script. Any help would be gratefully received...
    blessed are the cracked for they let in the light

  2. #2
    SitePoint Guru krityx's Avatar
    Join Date
    Jan 2006
    Location
    Around
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Your flash code is ok. If you're running Flash CS3 make sure to have selected an AS2 and not AS3 document as you are scripting AS2. And also if you just want to send info the PHP there's no point in using sendAndLoad. Just use send(). maybe you'll want to have a look at this http://www.sephiroth.it/tutorials/fl...ars/page02.php .

    Good luck


  3. #3
    Community Advisor silver trophy

    Join Date
    Nov 2006
    Location
    UK
    Posts
    2,559
    Mentioned
    40 Post(s)
    Tagged
    1 Thread(s)
    The point in using sendAndLoad is that even if you are only sending (and not receiving data back) but afterwards you want to remain on the same page. From the LoadVars help files:

    'A successful send() method call will always open a new browser window or replace content in an existing window or frame. If you would rather send information to a server and continue playing your SWF file without opening a new window or replacing content in a window or frame, then you should use LoadVars.sendAndLoad().'

  4. #4
    SitePoint Evangelist
    Join Date
    Jul 2002
    Location
    Italy
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've got something right then! It's because I read that send() opens a new window. I have found that changing "_self" with mydata my PHP script gets executed - and works BUT $_POST['score'] is undefined. I guess I'm still missing something. (Oh yes, I always forget to mention something - I'm using Flash 8)

    Thanks for the link. I'll see if that gives any more clues.

    And thanks...

    PS. I've got the answer. Instead of

    mydata.score = _root.userScore.text;

    I've just put

    mydata.score = userScore;

    and that does the job.
    Last edited by gandalf458; Jul 13, 2008 at 00:15.
    blessed are the cracked for they let in the light


Bookmarks

Posting Permissions

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