A Flash Developer Resource Site

Page 1 of 3 123 LastLast
Results 1 to 20 of 55

Thread: PHP/Flash 5 -Save Text Problem

  1. #1
    Senior Member
    Join Date
    Sep 2003
    Posts
    356

    PHP Re-Saving Text w/out reloading SWF

    This is what I have but it doesn't work. Loading the text file is easy, that's not included here.

    Everything is on main stage of movie on frame 1 (stop()) - I only testing on 1 frame.

    On btnSave click...

    Code:
    on (release) {
    	loadVariablesNum ("savevar.php", 0, "POST");
    }
    in php file...

    Code:
    <?php
    //set var
    $txt1 = $_POST['mycode'];
    $txt2 = $_POST['mytext'];
    // set string
    $toSave ="mycode=$txt1&mytext=$txt2";
    //Open a file in write mode
    $fp = fopen("savevar.txt", "w");
    if(fwrite($fp, $toSave)) echo "writing=Ok&";
    else echo "writing=Error&"
    fclose($fp);
    ?>
    It is not saving the file.
    Anyone help?
    Last edited by FHilton; 11-22-2005 at 02:41 PM.

  2. #2
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    The php and text file are in the same server folder.

    Any ideas?

  3. #3
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    Well I figured one problem.

    I was using LoadVariableNum to call the PHP file to save the text.

    I changed it to getURL....

    Now I get and error on this line...

    Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in ......ourwebzone.com\savevar.php on line 11

    which is.... fclose($fp);


    So why am I getting this error?

  4. #4
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    Alright... I didn't have to change it to getURL... so I put it back to loadVarNum.

    I was missing a ";" at the edn of an echo.

    Now my file saves ( ) but when I click an open button it does show the new file. I have to close the browser and try again to get it to load the changes.

    I can I get around this?

  5. #5
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    Is anybody out there???


  6. #6
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    Okay.. I got my text to save.

    Now I have a new problem...

    When I click my open button after saving, it does not show the new file. I have to close the browser and click open again to get it to load the changes.

    I can I get around this?
    Is there an clear loadvariables command or somthing that resets the loadvariable command?

    see it here... http://www.ourwebzone.com/savevar.swf

    PLEASE HELP ASAP!!

    Last edited by FHilton; 11-22-2005 at 02:51 PM.

  7. #7
    Flash Gordon McUsher's Avatar
    Join Date
    Mar 2001
    Location
    Krautland
    Posts
    1,560
    Sounds like a caching problem..
    where u load it put like:

    "savevar.txt?version="+new Date().getTime()

    this new Date().getTime() will put the milliseconds since 1970 which is unlikely to
    ever be the same, so your savevar.txt will never get outta cache

  8. #8
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    Didn't work
    This is my line to open file....

    loadVariablesNum ("savevar.txt?version=\"+new Date().getTime()", 0);

    How come flash 5 put the "\" in there?

  9. #9
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    Okay... it works

    loadVariablesNum ("savevar.txt?version="+new Date().getTime(), 0);

    had to remove \ and a quote at end.

    Now another problem... if you check link....

    If I specify fon color using ' or " around the hex. It puts slashes in their....

    what is the deal with that

    Thanks Thanks

  10. #10
    Flash Gordon McUsher's Avatar
    Join Date
    Mar 2001
    Location
    Krautland
    Posts
    1,560
    Hups, i deleted the savevar.txt.. damn..

    does it put slashes or backslashes? i assume u are talking about backslashes..

    ok.. you upload a string, a string is like var x="abc";
    if you need quotes in that string u use the backslash to escape it:

    var x="abc \" def";
    trace(x);// will output: abc " def

    got it so far?

    Ok for changing a colour you need a Number,
    to convert a string to a Number you could use
    Number(varName) prior to using it as a Number..

    Got it ? My english is so bloody krautish...

  11. #11
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    Backslashes

  12. #12
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    I put new code in text field see link

  13. #13
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    McUsher....

    I have on my main page a webblog that loads a text file (not save, I mannually set it up) using html tags. I load it into a dynamic text field with Html on.

    This input box is dynamic, but it is not html. So it saves raw text.
    Not sure why it is adding the backslashes though.

    Thanks for your help... I'll keep doing some research

  14. #14
    Flash Gordon McUsher's Avatar
    Join Date
    Mar 2001
    Location
    Krautland
    Posts
    1,560
    this is correct: <font color=\"#AA000\">text</font>
    works correctly if assigned directly to the html-TextField..

    I suspect your routine that loads and handles the savevar.txt
    to do something with the var, that it shouldn't..

    As the txt-file doesn't start "&mycode=" but "mycode="

  15. #15
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    should it start with &?

  16. #16
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    I added the "&" to the beginning of the line when it save.

    No change

  17. #17
    Flash Gordon McUsher's Avatar
    Join Date
    Mar 2001
    Location
    Krautland
    Posts
    1,560
    Quote Originally Posted by McUsher
    I suspect your routine that loads and handles the savevar.txt
    to do something with the var, that it shouldn't..

  18. #18
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    This is my PHP...

    Code:
    <?php
    $MyXCode = $_POST['mycode'];
    $toSave ="&mycode=$MyXCode";
    $fp = fopen("savevar.txt", "w+");
    if(fwrite($fp, $toSave))
    echo "writing=Ok&";
    else
    echo "writing=Error&";
    fclose($fp);
    ?>
    My btnSave....
    Code:
    on (release) {
    loadVariablesNum ("savevar.php", 0, "POST");
    }

  19. #19
    Flash Gordon McUsher's Avatar
    Join Date
    Mar 2001
    Location
    Krautland
    Posts
    1,560
    I give up...

    Quote Originally Posted by McUsher
    I suspect your routine that loads and handles the savevar.txt
    to do something with the var, that it shouldn't..

    there where u added the bloody new Date().getTime() thingy i provided ...

  20. #20
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    PHP Code:
    <?php
    $MyXCode 
    $_POST['mycode'];
    $toSave ="&mycode=$MyXCode";
    $fp fopen("savevar.txt""w+");
    if(
    fwrite($fp$toSave))
    echo 
    "&writing=Ok&";
    else
    echo 
    "&writing=Error&";
    fclose($fp);
    ?>
    you need the '&' in front of what you are echoing back to flash...See if that works for ya!

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