Intro
Hello, in this tutorial i will teach you how to use php with flash
whats php you ask?
* PHP stands for PHP: Hypertext Preprocessor
* PHP is a server-side scripting language, like ASP, Perl
so what?
well a server-side scripting language exicutes a script on a server.
so whata again?
well with php you can do all saughts of awsome dynamic stuff that flash cant do alone
like: make dynamic TXT/XML files which you can save data to.
thats the primary thing i use php for... well only thing...
It can do other things like get data from other places and.. eerr... other stuff...
so lets have a little look at a php script
<?php
echo "hello world"
?>
thats php, simple enough?
any way this tutorial isnt realy about php, rather its about php and flash
so im not going to teach you much more about php it you want more info go to
www.w3schools.com
the php script that we will be using in this tutorial is
<?php
$white = "whitespace";
$name = $_POST['name'];
$info = $_POST['info'];
//--------------------
$fh = fopen("text.txt", "w+");
fwrite($fh, "white=$white&name=$name&info=$info");
fclose($fh);
header("location: http://shazwoogle.t35.com/text.txt");
?>
put that in a text file and save it as save.php
i know i said im not going to teach you php but heres somthing that no tutorial will tell you
the line white=$white&name=$name&info=$info is one large string the string (thats simple) but the first part white=$whie that is asigning another variable to the textFile
because the first variable assigned to the text file gets bugged up quite often and its to tempremental... so i just asign a useless variable at the start of it so the first "real" variable isnt all screwy...
now upload it to you server/website if you dont have any php hosting just use www.t35.com
its pretty bad...popups banner adds... and more crap but there fast and have good browser uploading
ok now for the flash part
put two input textboxes on the stage put the var for one 'name' and the other 'info'
and then add a button and call it submit
then add this to the main frame
var myData:LoadVars = new LoadVars();
name = "";
info = "";
submit.onPress = function() {
if (name != "" && info != "") {
myData.info = info;
myData.name = name;
myData.sendAndLoad("http://shazwoogle.t35.
com/php/guestbook.php", myData, "POST");
}
};
i use sendAndLoad(); because if i use just send(); it will redirect the browser to the php file
which is not all that good =(
but with sendAndLoad(); the browser dosnt go any where which is good =D
if you want an example Go here!
the text file is Right Here
ok to loading loading data is realy easy and it is saughta coverd here As: Load External Data
but this is kinda different since we are using multipull variables we want to pull out idividual
variables and that isnt realy coverd by that tut.
any way we will use the LoadVars class again
put 2 more textboxes onto the stage one with the var 'name2' and the other 'info2'
add this to the main frame
myData.onLoad = function() {
info2 = this.info;
name2 = this.name;
};
myData.load("http://shazwoogle.t35.com/php
/guestbook.txt");
lets have a look at that script
myData.onLoad = function(){
this says as soon as any myData has loaded somthing from and external sauce
do some crap
the crap that it dose is asign some data to info2 amd name2 that data is myData.info
i give it a new variable simply because it makes it easier to use you could use myData.info
or myData.name but that can cause problems because myData is already being used
to send data...
any way the next line
myData.load("http://shazwoogle.t35.com/php
/guestbook.txt");
that simply loads in data from http://shazwoogle.t3..om/php/guestbook.txt
if you want an example Go here
it uses the same php script and text file as the previouse example
so thats mostly it
re-caping
php+flash = good
php*flash+good = cool programs
---
you use the loadVars class to send and load data
you use php scripts to get the data then do somthing with it.
any questions?