A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: AS2 Saving

  1. #1
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167

    AS2 Saving

    Wait, I'm not asking how!

    Okay, sorry I felt the need to to write that because I know a lot of people are asking how to do it and whatnot. Anyways, I've managed to be able to save through sendAndLoad via PHP to a text file in the past.

    However, I've run into a problem. In Flash I have:

    PHP Code:
    saveScore = function(){
    for (
    i=1;i<=10;i++){
            
    mySave["save"+i] = topScore[i];
            
    mySave["name"+i] = topName[i];
        }
        
    mySave.sendAndLoad("save.php",mySave,"POST");

    So basically in PHP, I'm receiving variables save1 - save10 and name1 - name10, which is given by the two arrays topScore and topName.

    Simple.

    For some reason, in my text file, it is only saving save1 and name1 while keeping all other names as NaN or Undefined. I'm assuming it's my PHP, so here's the code.


    Warning!

    I don't know PHP so yes I know what I'm doing is extremely primitive. If anyone knows how to properly and efficiently write the following code, I'll willingly accept it.

    PHP Code:
    <?php 
    $save1 
    $_POST['save1']; 
    $save2 $_POST['save2'];
    $save3 $_POST['save3'];
    $save4 $_POST['save4'];
    $save5 $_POST['save5'];
    $save6 $_POST['save6'];
    $save7 $_POST['save7'];
    $save8 $_POST['save8'];
    $save9 $_POST['save9'];
    $save10 $_POST['save10'];

    $name1 $_POST['name1']; 
    $name2 $_POST['name2'];
    $name3 $_POST['name3'];
    $name4 $_POST['name4'];
    $name5 $_POST['name5'];
    $name6 $_POST['name6'];
    $name7 $_POST['name7'];
    $name8 $_POST['name8'];
    $name9 $_POST['name9'];    
    $name10 $_POST['name10'];

    $toSave "save1=".$save1."&save2=".$save2."&save3=".$save3."&save4=".$save4."&save5=".$save5."&save6=".$save6."&save7=".$save7."&save8=".$save8."&save9=".$save9."&save10=".$save10."&name1=".$name1."&name2=".$name2."&name3=".$name3."&name4=".$name4."&name5=".$name5."&name6=".$name6."&name7=".$name7."&name8=".$name8."&name9=".$name9."&name10=".$name10

    $myfile fopen("save.txt","w"); 
    $fp fwrite($myfile,$toSave); 
    fclose($myfile); 
    ?>


    Thanks everyone!

  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,039
    Hi,

    a simple test would be to replace sendAndLoad by Send (so you see a web page) and put the following code into the test php
    Code:
    <pre>
    <? var_dump($_POST); ?>
    </pre>
    Now, if this game loads a list of previous high score from the text file, and sends modified list back, a simple html form would suffice to replace the top ten list by an entirely different one. I am sure some "players" will take the "challenge" of cheating rather than playing.
    A somewhat better solution would take a new entry, build a new list on the server, and send that back. To be honest, it is just a minor improvement - someone would have to send a html form 10 times to replace the entire top list

    Musicman

  3. #3
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    Thanks.

    I hear what you're saying about the cheating and considered it before. But realistically I'm not aiming to create a website like Kongregate/Addicting Games, nor some really game to put on either where highscores probably matter.

    It's just a simple website to post some simple games as a portfolio.


    Anyways, I switched it to send and the results returned are what I expected, all NaN (save numbers) and Undefined (string names):

    PHP Code:
        array(20) {
      [
    "name10"]=>
      
    string(9"undefined"
      
    ["save10"]=>
      
    string(3"NaN"
      
    ["name9"]=>
      
    string(9"undefined"
      
    ["save9"]=>
      
    string(3"NaN"
      
    ["name8"]=>
      
    string(9"undefined"
      
    ["save8"]=>
      
    string(3"NaN"
      
    ["name7"]=>
      
    string(9"undefined"
      
    ["save7"]=>
      
    string(3"NaN"
      
    ["name6"]=>
      
    string(9"undefined"
      
    ["save6"]=>
      
    string(3"NaN"
      
    ["name5"]=>
      
    string(9"undefined"
      
    ["save5"]=>
      
    string(3"NaN"
      
    ["name4"]=>
      
    string(9"undefined"
      
    ["save4"]=>
      
    string(3"NaN"
      
    ["name3"]=>
      
    string(9"undefined"
      
    ["save3"]=>
      
    string(3"NaN"
      
    ["name2"]=>
      
    string(9"undefined"
      
    ["save2"]=>
      
    string(3"NaN"
      
    ["name1"]=>
      
    string(7"Matthew"
      
    ["save1"]=>
      
    string(1"3"


    I think it has to do with the positioning of where I put the sendAndLoad, but from tutorials I've seen online, its in the right place. But it's so weird that when I trace the name and score arrays, they list it in proper order, right BEFORE the sendAndLoad.

    So I don't know why it's not sending properly. :S

  4. #4
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    Edit:

    It turns out that even when I trace the entire mySave variable that'll be sent to PHP with all the saves/names traces out perfectly. But even with the tested PHP, it POST's all undefined.

    Argh.

    PHP Code:
            trace(mySave)  // GOOD
        
    mySave.send ("test.php",mySave,"POST"); // BAD 
    Last edited by Osteel; 11-20-2009 at 01:46 PM.

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