# Simple Flash AS \<-\> PHP example

**URL:** <https://forum.kirupa.com/t/simple-flash-as-php-example/25724>\
**Category:** Uncategorized\
**Created:** [July 16, 2003, 12:27am UTC](https://forum.kirupa.com/t/simple-flash-as-php-example/25724 "2003-07-16T00:27:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Danneman](https://avatars.discourse-cdn.com/v4/letter/d/b19c9b/32.png) [@Danneman](https://forum.kirupa.com/u/Danneman)\
**Post date:** [July 16, 2003, 12:27am UTC](https://forum.kirupa.com/t/simple-flash-as-php-example/25724/1 "2003-07-16T00:27:48Z")

</div>

Im trying to get a grip on Flash AS (client-side) and PHP (server-side) interaction.

## This Flash ActionScript is supposed to send a variable (myData.ClanName) found in a textbox (TXTBOX\_TESTING) to a PHP-script (when a button is pushed):

## on(press){ myData = new LoadVars(); myData.ClanName = TXTBOX\_TESTING; myData.send(“[http://members.lycos.co.uk/usnswe/contact/contact.php](http://members.lycos.co.uk/usnswe/contact/contact.php)”); }

## Then this PHP-script is supposed to add this varible to a textfile (contact.txt):

## \<?php $FileName = “contact.txt”; $FilePointer = fopen($FileName, “a”); fwrite($FilePointer, $ClanName); // Dubious Variable fclose($FilePointer); ?\>

Well, I know the PHP-script works, as Ive tried to put plaintext into the “fwrite”-functions second parameter instead of the “$ClanName”-parameter.  
That will create/open “contact.txt” and add a line to it.

The problem with Flash AS is:  
a) It doesnt seem to call the PHP-script when the button is pushed.  
b) I dont know the correct syntax to translate the myData.ClanName - variable (sent from the AS) to a variable that the PHP-script can read.  
Above Ive tried “$ClanName” (PHP: 4th line), but that doesnt seem to work.

Any suggestions?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 16, 2003, 1:00am UTC](https://forum.kirupa.com/t/simple-flash-as-php-example/25724/2 "2003-07-16T01:00:31Z")

</div>

$ClanName should be $\_POST[‘ClanName’];

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 16, 2003, 1:33am UTC](https://forum.kirupa.com/t/simple-flash-as-php-example/25724/3 "2003-07-16T01:33:19Z")

</div>

Ok, that should solve problem b) - thanks 🙂

## Now onto problem a). Ive changed the php-file to:

\<?php

$FileName = “contact.txt”;  
$FilePointer = fopen($FileName, “a”);  
fwrite($FilePointer, $\_POST[‘ClanName’]);  
fclose($FilePointer);

## ?\>

## But still the data doesnt seem to be sent from the Flash AS in the first place. Why?

## on(press){ myData = new LoadVars(); myData.ClanName = TXTBOX\_TESTING; myData.send(“http://…contact.php”); }

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 16, 2003, 1:37am UTC](https://forum.kirupa.com/t/simple-flash-as-php-example/25724/4 "2003-07-16T01:37:10Z")

</div>

would **myData.ClanName = TXTBOX\_TESTING.text** do it?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 16, 2003, 8:23pm UTC](https://forum.kirupa.com/t/simple-flash-as-php-example/25724/5 "2003-07-16T20:23:41Z")

</div>

## Ok, using “sendAndLoad” instead of “send” with LoadVars-objects got it working. Also, the “POST” method of “sendAndLoad”-function should probably be specified, since the “GET”-method could otherwise be used (which would make the retreival of the “ClanName”-variable in the PHP-code a bit tricky, since it uses “POST”).

## on(press){ myData = new LoadVars(); returnData = new LoadVars(); myData.ClanName = TXTBOX\_TESTING.text; myData.sendAndLoad(“[http://www.myWebpage.com/contact.php](http://www.myWebpage.com/contact.php)”, returnData, “POST”); }

Thanks for the help.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 16, 2003, 9:28pm UTC](https://forum.kirupa.com/t/simple-flash-as-php-example/25724/6 "2003-07-16T21:28:39Z")

</div>

LoadVars.send() uses POST by default… i don’t see why would you use sendAndLoad and specify the POST again…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 16, 2003, 9:49pm UTC](https://forum.kirupa.com/t/simple-flash-as-php-example/25724/7 "2003-07-16T21:49:11Z")

</div>

Your right. Some faulty debugging made me draw that premature conclusion. It works fine without.
