|
 |
|
|
|
|
|
This tutorial will demonstrate how to send/save data to/in a text file. Before starting this tutorial I will define what is an Input Box and how to use it.
What is Input Box Input box is a text field in which you enter your data with the help of keyboard. It is usually used to save Visitors/members information which they input during their visit to your site. It can be in the form of Emailer, Guestbook, Contact form or in any other form which is not supposed to be dynamically used, for example you input a number 4 and when you press Proceed button, it calculates square of 4. Here is an example of Input Text Box and Dynamic Text Box. In this example you will input some text in Input text box and it will send that DATA to dynamic TEXT and perform and action.
Steps in this example. ------------------------------ Note : In this example you will make one Input Text Box and one Dynamic Text Box. Then you will send data of Input Box to Dynamic text through variable.
1. Make a text box and select its type as Input Box. In its Name type inputName. Check the box of target. In variable box use any name for example inputVar. Now inputVar is the variable which will carry the data you will input in this box.
2. Make a text box and select its type as Dynamic Text Box. Give its name and variable as above. See in the following figure.

3. Place a Stop action on Frame number 1 in main timelime. 4. In front of your Dyanmic Text box place any effect you like. 5. Make a button and put this action in its release state.
on (release) { dynamicVar=inputVar; gotoSceneAndPlay("<current scene>",2); }
In above example you have learned how to use an Input Box and how to get data into Dynamic Text box. We have sent data from Input Text box to Dynamic Text Box.
Dwonload Example File
UNDERSTANDING - HOW TO SEND DATA TO TEXT FILE FROM INPUT BOX ----------------------------------------------------------------------------- Now I assume that you can understand how Input and Dynamic TEXT works. So here we go. You must also undestand how varialbes work, if you dont know then please read this Variable Tutorial and this Tutorial..For more details on how it work with PHP, Read this tutorial...
Steps for making an example which sends data to a text file. -------------------------------------------------------------------- 1. Make a text box and select its type as Input Box. In its Name type inputName. Check the box of target. In variable box use any name for example inputVar. Now inputVar is the variable which will carry the data you will input in this box. Click on the button for multiline.
2. Make a text file with notepad and write &myDynamicVar=This is my text.
3. Again open notepad paste the following code in it and save it as myphpfile.php
<? chmod("mytextfile.txt",0666); $f=fopen("mytextfile.txt","w"); fwrite($f,"&myDynamicVar=$inputVar"); fclose($f); chmod("mytextfile.txt",0600); ?>
4. Make a button "Save" and on its action paste the following code.
on (release) { this.loadVariables("myphpfile.php",'POST'); } Download Example File
EXPLANATION of PHP FILE ---------------------------- There are 7 lines in myphpfile.php
1. <? 2. chmod("mytextfile.txt",0666); 3. $f=fopen("mytextfile.txt","w"); 4. fwrite($f,"&myDynamicVar=$inputVar"); 5. fclose($f); 6. chmod("mytextfile.txt",0600); 7. ?>
What is on line 1 "<?" This is PHP synatx used to start PHP code, as we use Begin keyword in Pascal and { in C,C++.
What is on line 2 "chmod("mytextfile.txt",0666);" This is code which will automatically change te permission of text file, so that you are able to write data into it.
What is on line 3 "$f=fopen("mytextfile.txt","w");" Here we have made a new variable $f and we have assign it a value fopen("mytextfile.txt","w"). Now fopen is a PHP function which open any file for different purposes, for example we are opening text file to write data into it, thats why we have used "w" infront of it. If we want to append any file we will use "a".
What is on line 4 "fwrite($f,"&myDynamicVar=$inputVar");" fwrite is the function which write data to file, in its first argument you have passed the variavble "$f" which is opening text file in line 3, in second agrument I have used "&myDynamicVar=$inputVar".
What is on line 5 "fclose($f);" You will have to close file which you have opend for any purpose.
What is on line 6 "chmod("mytextfile.txt",0600);" We have again changed the file permission so that no one else can write any data externally.
What is on line 7 "?>" This is closing syntax for a PHP file.
You are done. Upload your files and check on the server which supports PHP Scripts. You dont need to chmod any file.
best reagrds - Ali Roman..
|
|
|
|