dcsimg
A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 31

Thread: Variable

  1. #1
    Member
    Join Date
    May 2004
    Location
    Netherlands
    Posts
    58

    Variable

    Thanks for your answer.
    I upload the script here. Maybe you can tell me what i did wrong.
    It's maybe just a simple something but i'm not so good in scripting at all. Thanks again for helping.

    Sorry post it wrong. It had to be a reply on the last post.
    Attached Files Attached Files

  2. #2
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Ok first off you are looping which is not good. Turn off looping or add stop action

    next the following
    myUrl="http://www.rmvos.nl/ruiter/test.php?var1="+var1
    loadVariables (myUrl,"GET")

    while that should work I've found that it is indeed limited to 255 characters. (Reported bug a long time ago fixed via the POST option)

    Change the above to:
    root.loadVariables (myUrl="http://www.rmvos.nl/ruiter/test.php", "POST")

    this sends ALL variables to your PHP file

    Now in you PHP be sure to use $_POST['var1'] as opposed to $_GET['var1'] to access it

  3. #3
    Member
    Join Date
    May 2004
    Location
    Netherlands
    Posts
    58

    PHP script

    When i do that, changes in the text are not writen to the txt file on the server. My PhP script looks like this. I changed the $_post it was $_get before. Was that what you ment. Also the movie file wich i edit. I think the way you say it must be.



    <?php
    $file_name="./test.txt";//Be sure to set this to your file

    if ($_POST['cmd']='w'){
    //to write a file
    $fp=fopen ($file_name,'w');//open file for writing
    fwrite($fp,"&var1=".$var1);//save what ever is in the string contents
    fclose ($myfile);//close it
    }else{

    //open a file and assign it a 'handle' of fp
    $fp=fopen($file_name,'r') ;

    //Then read the file
    $contents = fread ($fp, filesize ($file_name));
    fclose ($fp);//done close the file
    }
    //either way I think it's ok to send the contents back to 3dfa
    //so send it
    echo "&var1=".$var1;//change this to the variable you use in 3dfa
    ?>



    greetings Rob
    Attached Files Attached Files
    Last edited by RobVos; 12-30-2004 at 12:25 PM.

  4. #4
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    I recconize that code

    make sure you set a variable in your movie
    cmd="w" so that will get sent as well other wise no write and that is what the line

    if ($_POST['cmd']='w'){

    checks

  5. #5
    Member
    Join Date
    May 2004
    Location
    Netherlands
    Posts
    58

    cmd="w"

    where do i have to define this variable.
    When i push the button or at the start of the movie.
    How do i make that variable. : like cmd="W" (capital or not)
    I tried it at the start of the movie but that didn't do the trick

    thanks again

  6. #6
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    How do i make that variable. : like cmd="W" (capital or not)
    lower case as that is what the PHP script is looking for. Or modify the PHP to set the case to what you are looking for.

    You should be able to put it anywhere but just before the loadvaiables command is probably the best bet.

  7. #7
    Member
    Join Date
    May 2004
    Location
    Netherlands
    Posts
    58
    Thanks Blanius,

    So this is my php file. As you can see the post['cmd']='w'
    I defined a variable cmd='w' in the script section.
    When i change the tekst and push the tekst opslaan button (save text button) then there is nothing saved. I really don't know what i'am doing wrong. Can you help me again.


    <?php
    $file_name="./test.txt";//Be sure to set this to your file

    if ($_POST['cmd']='w'){
    //to write a file
    $fp=fopen ($file_name,'w');//open file for writing
    fwrite($fp,"&var1=".$var1);//save what ever is in the string contents
    fclose ($myfile);//close it
    }else{

    //open a file and assign it a 'handle' of fp
    $fp=fopen($file_name,'r') ;

    //Then read the file
    $contents = fread ($fp, filesize ($file_name));
    fclose ($fp);//done close the file
    }
    //either way I think it's ok to send the contents back to 3dfa
    //so send it
    echo "&var1=".$var1;//change this to the variable you use in 3dfa
    ?>
    Attached Files Attached Files

  8. #8
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Are you sure you have write permissions set for the directory you are using?

  9. #9
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    test it change all the $_POST to $_GET and then in your browser call it

    http://www.rmvos.nl/ruiter/test.php?var1=test text&cmd=w

    you can also add the following to your PHP file

    print_r($_GET) and it will show all the $_GET variables
    Last edited by blanius; 12-30-2004 at 02:41 PM.

  10. #10
    Member
    Join Date
    May 2004
    Location
    Netherlands
    Posts
    58

    http://www.rmvos.nl/ruiter/test.php?var1=test text&cmd=w

    I changed the POST to GET and called it in the browser.
    Underneath is what i get

    Warning: fclose(): supplied argument is not a valid stream resource in /usr/local/plesk/apache/home/vhost/rmvos.nl/httpdocs/ruiter/test.php on line 8
    &var1=test text

    The txt file was filled with &var1=test text
    When i change the POST to GET again then it writes in the txt file.
    Does this make sense ?
    Last edited by RobVos; 12-30-2004 at 03:05 PM.

  11. #11
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    I think it's a path issue on your PHP

    Here's What I suggets make a form in HTML that sends a textfield to your PHP so you can test it.

    You can use print_r to see the array either print_r($_POST) or print_r($_GET) so you can see that your variables are as expected in the PHP code then debug your PHP till it's working then its a simple thing to have the 3dfa send the vars instead of the HTML form.

  12. #12
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    DOH! look at the line 8
    fclose ($myfile);//close it
    should be $fp not $myfile

  13. #13
    Member
    Join Date
    May 2004
    Location
    Netherlands
    Posts
    58
    thanks again for the answer Blanius.
    But i'am not clever enough to get it to work.
    Can you have a look at it again please ?

    the php file on the server is like this now:

    <?php
    $file_name="./test.txt";//Be sure to set this to your file
    if ($_POST['cmd']='w'){
    //to write a file
    $fp=fopen ($file_name,'w');//open file for writing
    fwrite($fp,"&var1=".$var1);//save what ever is in the string contents
    fclose ($fp);//close it
    }else{
    //open a file and assign it a 'handle' of fp
    $fp=fopen($file_name,'r') ;
    //Then read the file
    $contents = fread ($fp, filesize ($file_name));
    fclose ($fp);//done close the file
    }
    //either way I think it's ok to send the contents back to 3dfa
    //so send it
    echo "&var1=".$var1;//change this to the variable you use in 3dfa
    ?>

    I include the movie as a zip file. Is the movie oke ?
    I hope you can help me it is driving me INSANE ;-)

    greetings
    Attached Files Attached Files

  14. #14
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Rob it's hard to diganose without actually testing myself on server.

    That being said I've found another problem with the php file.

    the line
    PHP Code:
    if ($_POST['cmd']='w'){ 
    should be
    PHP Code:
    if ($_POST['cmd']=='w'){ 
    Also move the cmd="w" into the button script, and it's better to put it into the Button up instead of down, this is the way standard buttons work that way you can drag the mouse off a button after pressing and not activate the button actions.

    Try those and see it that doesn't work for you.

  15. #15
    Member
    Join Date
    May 2004
    Location
    Netherlands
    Posts
    58

    Going away

    Blanius,

    i cant get it to work. I made a change tot the script it looks like :
    <?php
    $file_name="./test.txt";//Be sure to set this to your file

    { //to write a file
    $fp=fopen (test.txt,'w');//open file for writing
    fwrite($fp,"&var1=".$var1);//save what ever is in the string contents
    fclose (test.txt);//close it
    }
    ?>

    This shoud always write to the text file i suppose.
    See the movie. I changed the button etc. Does it have to be on a server? I mean i have the txt file and the php file on the server and the movie on my c drive. I thought that had to be possible.

    I'am going away for a few days (till thursday next week) so i wish you a happy ending and a jolly good newyear. Thanks for all the help and i hope i can get it to work next year ;-)
    Attached Files Attached Files

  16. #16
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Rob I'm pretty sure your problem is on the server.

    I just did this
    var1="This is data sent from 3dfa"
    loadVariables("http://bretlanius.com/test.php","POST");

    in a button and the PHP in test.php was simply

    <?php
    $fp=fopen('cgi-bin/test.txt',w);
    fwrite($fp,$_POST['var1']);
    fclose($fp);
    ?>

    Get the PHP working with GET so you can test by typing in the url. then just switch to POST and then use 3dfa to send data. And yes you can test local.

  17. #17
    Member
    Join Date
    May 2004
    Location
    Netherlands
    Posts
    58

    I tried it

    Hai Blanius,

    I tried what you send me and the result is:

    when i push the button i see the text from var1 become your line "this is data send from 3dfa". But it is not saved inside the text file.
    I have webspace by protagonist. You don't know them probably.
    I don't know what to do next. Is there another way to send variables to a text file ? Maybe another script ?

    thanks again.

    Rob

  18. #18
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Rob, I don't know what else to tell you Flash cannot save information to the server itself and the PHP code I know works if your permissions are set right.

    The last example worked fine on my site.

  19. #19
    Member
    Join Date
    May 2004
    Location
    Netherlands
    Posts
    58

    It works

    Blanius,

    It works. I made it just like you said and was testing it from a movie on my computer. I compiled it and upload it to my server. Now it is working. So i think i have to do it real 'live' on the server and not the movie local and the rest on the server.

    Oh boy, am I happy.

    3 times thanks for all the help.

    greetings from a happy Rob

  20. #20
    Member
    Join Date
    May 2004
    Location
    Netherlands
    Posts
    58

    Question

    Blanius,

    as you can see i have to define the test.txt file in the php file.
    Is there a possibility to define the $file_name like a variable.
    That way i can set up the movie to connect to the right txt file.
    Like in the button something like $file_name="test.txt" The problem is that 3df don't allow me to use $file_name as variable. This way i can use one php file to write to many txt files.

    <?php
    $file_name="./test.txt";//Be sure to set this to your file

    if ($_POST['cmd']=='w'){
    //to write a file
    $fp=fopen ($file_name,'w');//open file for writing
    fwrite($fp,"&var1=".$var1);//save what ever is in the string contents etc etc.

    Thanks again

    Rob

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