A Flash Developer Resource Site

Page 2 of 2 FirstFirst 12
Results 21 to 36 of 36

Thread: Writing to text file via Dreamweaver

  1. #21
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    Here is another method:
    http://sap.ittoolbox.com/groups/tech.../asp-l/467097#
    are you getting any erros when the page executes?
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  2. #22
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    I got the PHP method to work for me. ASP kept giving my a persmission violation.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


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

    No I didnt get any errors, it just simply didnt write anything to the file. I think it just might be a permissions problem. I wont have a chance to test it tomorrow, but on friday I'll give it a shot.

    If not, then I'll use the php method

  4. #24
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    Hey again,

    Sorry to bring this up again, but heres where Im at. The asp method isnt working and I think its because of some premission problems as well. I decided to try using Php with that tutorial you gave me.

    By using the code:
    PHP Code:
    <?php
    $filename 
    'testStuff.txt';
    $somecontent "Add this to the file\n";

    // Let's make sure the file exists and is writable first.
    if (is_writable($filename)) {

       
    // In our example we're opening $filename in append mode.
       // The file pointer is at the bottom of the file hence 
       // that's where $somecontent will go when we fwrite() it.
       
    if (!$handle fopen($filename'a')) {
             echo 
    "Cannot open file ($filename)";
             exit;
       }

       
    // Write $somecontent to our opened file.
       
    if (fwrite($handle$somecontent) === FALSE) {
           echo 
    "Cannot write to file ($filename)";
           exit;
       }
       
       echo 
    "Success, wrote ($somecontent) to file ($filename)";
       
       
    fclose($handle);

    } else {
       echo 
    "The file $filename is not writable";
    }
    ?>
    I was able to change the text file to display the words Add this to the file when I ran it on the internet.

    So my question is, how do you use flash to send a variable for Php to write to the text file, like we did with the asp file?

  5. #25
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    Cancel that, I got it to work!

    Thanks so much for your help Kortex, I owe you one

  6. #26
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    Cool, No prob. Good luck.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


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

    This is more out of curiousity then it is a problem, just wondering something that might be useful for future projects.

    Imagine you have a text file that simply contains comment1=0;

    Now at the click of a button, you want to store inside a variable, the number contained inside the text file but added by one. So in this case, it would store instead of a zero, a one.

    So when you click the button, it would be something like:

    code:
     
    on (release) {
    myText = new LoadVars();
    myText.onLoad = function() {
    numberComment = this.comment1;
    inputComment = numberComment+1;
    };
    myText.load("text files/commentVariable.txt");



    But when I tried doing that, it just posted up the zero contained inside the text box as well as adding a one beside.



    Secondly, say after that all happens and you successfully stored the number of the text file inside a variable added by one. Is it possible to then change the zero in the text file to one? [again, incremented by one]

  8. #28
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    I am not sure if this is right. But if I remember correctly whenever you load vars, they are loaded as strings. So you might have to convert the string to a number before adding it. Let me look into it.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  9. #29
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    Thats what I thought so I tried the whole Number(string) concept. It came back with a NaN value. Perhaps I just didnt use it properly

  10. #30
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    did you try :
    parseInt(yourVar);
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  11. #31
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    No, didnt know that exsisted, someone told me to do the whole Number() thing.

    But it works, thanks!



    So thats one of two things completed haha. I feel like Im asking way to much of you, so dont feel obligated to help me if your tired of it

    The final step is to take whats contained inside this variable inputComment = parseInt(numberComment)+1; and send it to the text file commentVariable.txt

    Now thats easy, here's the catch.

    Inside this text file contains the line &comment1=0 and notice how there is a zero set to it. What needs to happen is that the value in the variable inputComment must overwrite that zero to the value its holding.

    The Php code I have is:

    PHP Code:
    <?php
    //phps opening tags are  "<" + "?" 
    //these are the variables that will 
    //hold data sent from flash via  input textbox
    //data is sent by  sending part of  loadVars object
    //inputData is a variable we will set in flash, 
    // its a variable attached 
    //to the loadVars object and will be send to  php 
    $receivedFromFlashData $_POST['inputData'];
    //this is to make our textfile readable and writable 
    //place it in a variable so we can refer back to it easily.
    // ( @  symbol is to hold back certain error messages)
    $myTextFileHandler = @fopen("writeComment1.txt","r+");
    // With @file we will turn our textfile 
    // into an array so we can know how 
    // many entries there are in the file.

    $txtfileArray = @file("writeComment1.txt");

    //here we check if we could open the file 
    // if everything is ok , go on.

    if($myTextFileHandler){
    //a print to help us 
    // so this will not be send to flash.
    print("txtFile is opened\n");
    //loop through the text file array 
    //remember -> @file("membersDatabase.txt");
    //use $count variable in the string we send to text file,
    // it attaches a number to the string for us 
    //to show how may times we inserted something into textfile.

    foreach($txtfileArray as $count => $member);
    //We go to the last byte of the file, 
    // because we want to insert data at  end of the file

    $gotoLastByteOfTxTFile
    = @fseek($myTextFileHandler,0,SEEK_END);
    //Increase count by one 
    //because an array starts counting at 0.

    $count $count 1;
    // make a variable writeInTxtFile with command @fwrite.
    //It will write a string  into the text file 
    //defined in myTextFileHandler, 
    //notice the \n makes it start on a new line each time .

    $writeInTxtFile = @fwrite($myTextFileHandler,$receivedFromFlashData);
    //"\nreceived from flash $count=$receivedFromFlashData");
     
    //Was writing into the txtfile  a success , 
    // if true print a variable to flash to be handled
    // in the response loadVars Object.

    if($writeInTxtFile){
        
    // make a variable to hold the message  in flash 
    // if writing to the textfile was a succes.

    $writeStatus "writing to textfile was a succes";

    //printed to flash and this  data is actually attached to 
    // the loadvars object we defined in flash.
    // can acces like  a variable in a movieclip or object.
    //can set this variable to be show in a textbox like this:
    // mytextbox.text =    myReveivingLoadvars.writeStatus
    // this piece of code must be triggered in the 
    // myReveivingLoadvars.onLoad part

    print("&writeStatus=$writeStatus");

    //if writing was a failure we print that to flash

    }else{
    $writeStatus "writing to textfile was a big failure";
    print(
    "&writeStatus=$writeStatus");
    };
    //here we close the stream to the textfile

    @fclose($myTextFileHandler);
     
    // If opening the text file was a failure in 
     //the first place we print this to the php output.
    // You can also send error messages like this to flash, 
    // just change the print command to something like:

    //print("&failMsg = $youErrorMsg"); 
    //and call the failMsg variable in your flash
    //  file in the receiving onLoad part of 
    //the loadVars object e.g. like 
    // myTextBox.text = myReceiveLV.failMsg. 
    }else{
    print(
    "opening txtfile has failed\n");
    };

    //this is printed to flash and received by the reveiver
    // part of our loadVars object. 
    // This piece of data will be show in a textbox
    // in flash immediately after a you press submit.
    // so you sumbit your inputted text in flash , 
    //its ran through this little 
    // engine like php script and you immediately receive
    // an answer back.
    //print("&receivedData=$receivedFromFlashData");

    ?>
    ...

    Thanks!

  12. #32
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


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

    So the line $myTextFileHandler = @fopen("writeComment1.txt","r+"); the second value in the brackets is what you want the contents to do. To overwrite it you simply replace it with a 'w'.

    Am I right in saying that?

    Sorry, cant test it right now so thats my guess.

  14. #34
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    That's what i looked like it was saying to me.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  15. #35
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    Hey!

    Just getting back with an update, I tested it and it completly overwrites the text file when replacing the second parameter with a 'w'

    Its probably a bit primitive, but it works!


    Thanks so much for your help Kortex, it seems like everything I need to continue on is working, so thank you!

    I just hope thats everything

  16. #36
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    Hey if it works it works. Can imagine code that small is placing a huse burden on the processor or server.

    Good luck.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


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