A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: PHP LoadVars help

  1. #1
    President PhobiK's Avatar
    Join Date
    Jan 2005
    Location
    Guatemala
    Posts
    918

    PHP LoadVars help

    Hi guys. I want to store variables into a .txt file for flash to read them later. It's my first work on php so I don't know if there are better ways for doing this. In the php file (called "new.php") I have:
    PHP Code:
    <HTML>
    <BODY>
    <?
    $nombre_archivo = 'new.txt';
    $gestor = fopen($nombre_archivo, 'w');
    $contenido = "name=" . $name . "&score=" . $score;
    fwrite($gestor, $contenido);
    fclose($gestor);
    ?>
    </BODY>
    </HTML>
    That is for php to write over the file "new.txt" like this: name=yourname&score=yourscore, so flash can load the variables from the txt file using load (or loadVariables).
    Please try the swf here . You'll notice that the first time it stores the name and the score, but then if you try again it doesn't seem to work, or sometimes you have to wait a long time until it stores them.
    Does anyone know why is this happening?
    I'm attaching the .fla file, i'd like you to check it out please, cus I'm using loadVars and I'm not familiar with them, it's the first time I need them so I don't actually know how they work and there are some things in the code there that I don't even know what they do, they just work. So please if anyone could help me with this and tell me why is this happenning or a better and more efficient way to do it I'll really appreciate it.
    Thanx in advance

    p.s. thanx for the tute tonypa
    Last edited by PhobiK; 07-18-2009 at 02:44 AM.
    This is MC. His _parents sent him to stop() by the super market to buy some _root beer if he wanted to gotoAndPlay() with his friends at the park later.

    This is my Blog!... The gaming Process
    Please check out my site: Giddel Creations

  2. #2
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Perhaps new scores are not loading because the browser uses old cached version. I think you could use something like
    scores.load("new.txt?ranvar="+random(1000000000));
    to avoid caching.

  3. #3
    President PhobiK's Avatar
    Join Date
    Jan 2005
    Location
    Guatemala
    Posts
    918
    Thanx tonypa, didn't think about that. I'll try that to see if it works.
    This is MC. His _parents sent him to stop() by the super market to buy some _root beer if he wanted to gotoAndPlay() with his friends at the park later.

    This is my Blog!... The gaming Process
    Please check out my site: Giddel Creations

  4. #4
    GODs Angel GodAngel's Avatar
    Join Date
    Feb 2005
    Location
    guatemala
    Posts
    175
    Quote Originally Posted by tonypa
    Perhaps new scores are not loading because the browser uses old cached version. I think you could use something like
    scores.load("new.txt?ranvar="+random(1000000000));
    to avoid caching.
    hi everybody "tonypa" i try with the scores.load---" but not working i have a dato.load("dato.txt?ranvar="+random(1000000000));
    but not working, im using flash mx 2004 v7.2

    could you help me please
    Even the wise men do not know all the ways.
    Sogar der wises ermannt sich wissen(kennen) alle Wege nicht.
    Ni los mas sabios conocen todos los caminos.

  5. #5
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Quote Originally Posted by GodAngel
    hi everybody "tonypa" i try with the scores.load---" but not working i have a dato.load("dato.txt?ranvar="+random(1000000000));
    but not working, im using flash mx 2004 v7.2

    could you help me please
    Does it load scores first time? I was proposing to add random variable only for the problem with "scores load first time, but not later".

  6. #6
    GODs Angel GodAngel's Avatar
    Join Date
    Feb 2005
    Location
    guatemala
    Posts
    175

    here is the code

    for send data to php

    dato = new LoadVars();
    guardar.onPress = function() {
    dato.mensaje = mensaje.text;
    dato.sendAndLoad("dato.php", dato, "POST");
    };

    php code:

    <?
    $mensaje = $_POST['mensaje'];
    $hola = "&mensaje=" .$mensaje;
    $archivo = "dato.txt";
    $nom = fopen($archivo,"w");
    fwrite($nom,$hola);
    ?>

    for load:

    on (release) {
    dato = new LoadVars();
    dato.load("dato.txt");
    dato.onLoad = function(ok) {
    if (ok) {
    _root.dl= dato.mensaje;
    }
    };
    }

    but not working only some times please help me
    Even the wise men do not know all the ways.
    Sogar der wises ermannt sich wissen(kennen) alle Wege nicht.
    Ni los mas sabios conocen todos los caminos.

  7. #7
    Member
    Join Date
    Dec 2002
    Location
    Baku, Azerbaijan
    Posts
    39
    Maybe it's not so important, it may be a mechanical mistake but I think you should write
    dato.mensaje ="mensaje.txt";

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