Read-Write Text File

 

The purpose is to create a form which a user 'll enter data in. Those data 'll be written in a text file; then we read them. The results 'll be displayed inside movie.
This example 'll use very simple scripts. I suppose you know well how to create objects, thus I will not insist on.

⇒ animation ⇐

Warning :
This example 'll use a PHP script (server side).
Then, to test your creation, you 'll need :
- either an Apache web server set on your computer ( with PHP installed )
- either put your files on your web directory , provide that your host allows PHP scripting.

Remark :
Right here, we don't consider to writing in a MySQL database which however 'd be the best solution with a form.

Creating Objects

1 - Set up width 640, height 480 and a background color #000066. Frame Rate doesn't matter.

2 - Now create a rectangle (color #7C72FC) , named Cadre with a border thickness 3 , color #DDDDDD.
You 'd yield :

Rectangle    Transform

We 'll use this rectangle as a background for the form.

3 - Now create a rectangle (color #8630A7) , named BarreTitre with a border thickness 3 , color #DDDDDD.
You 'd yield :

Rectangle    Transform

We 'll use this rectangle as a background for the title of the form.

4 - Now create a static text Fiche ( color #FF99FF ). You 'd yield :

Texte    Transform

5 - Now create the mentioned static text, ( color #FF9900 ). You 'd yield :

Texte    Transform

Adjust space between words if necessary.

6 - Now create an input text field_nom ( color #000066 )
The dynamic variable is nom. You 'd yield :

Texte    Transform

7 - Now create an input text field_prenom ( color #000066 )
The dynamic variable is prenom. You 'd yield :

Texte    Transform

8 - Now create an input text field_adresse ( color #000066 )
The dynamic variable is adresse. You 'd yield :

Texte    Transform

9 - Now create an input text field_ville ( color #000066 )
The dynamic variable is ville. You 'd yield :

Texte    Transform

10 - Now create an input text field_zipcode ( color #000066 )
The dynamic variable is zipcode. You 'd yield :

Texte    Transform

11 - Now create a rectangle (color #8430A5), with a border thickness 2, color #DDDDDD. You 'd yield :

Rectangle    Transform

12 - Now create the static text Envoyer, (color #E786F7). You 'd yield :

Texte    Transform

13 - With the shift key down, select the last 2 objects; convert to button.

Outline

Now, we need to display the content of the text file below the form :

Transform

14 - Now create the static text Contenu du Fichier, (color #FFFFFF) width 145, height 25. You 'd yield :

Texte

15 - Now create a rectangle (color #CCCD98), width 550, height 172 with a border thickness 2 , color #A5A6C6. You 'd yield :

Rectangle

16 - Now create a dynamic text, named contenu de couleur #000066, largeur 548, hauteur 169.
The dynamic variable is datalist. You 'd yield :

Texte

17 - With the shift key down, select the 3 previous objects, convert to sprite, named content

Sprite

Outline 'd look like :

Transform

PHP script

With a text editor, enter the following text :

Save it as write1file.php. You need to put it into your web site directory.
Explanations :
We get data from the form, stored in an array. For safety, we throw away any html meta. If all data have been sent (i.e. all fields have been filled in), we write them in a text file in Append mode. We put a LineField.

Text file

With a text editor, enter the following text :

&datalist=

Save it as file2write.txt. You need to put it into your web site directory.
Variable datalist 'll be recovered by animation script.

SwishMax scripts

Here is for Scene_1

Here is for button

Et voilà, that's it. Of course, it's a pretty simple example. It's up to you to improve it. Good luck.

 


Si vous aimez le site

 

Select a language if you need :


Page chargée en 0.051 sec.

Dernière Modification : Mer 25 Janvier 2017 8:56
Copyright © 1999-2017 Jean-Paul Molina Tous droits réservés.

to Google