satheesh
New Member
- Messages
- 883
- Reaction score
- 0
- Points
- 0
Example Send and Get Data from PHP in Flash
1.Create a blank document.
2.Create a Input Text field and Set them ins="msg".
3.Place your button on the stage.
4.Select the button and press F9.
Copy code below and paste it.
5.Save and publish it(File name="Data").
6.Create a new php called "index.php".
7.Copy the code below and paste it.
Save and Run.
Demo:http://www.svprm.x10hosting.com/for_forums/php/index.php
1.Create a blank document.
2.Create a Input Text field and Set them ins="msg".
3.Place your button on the stage.
4.Select the button and press F9.
Copy code below and paste it.
Code:
on (press) {
var send_msg:LoadVars = new LoadVars();
send_msg.flash = true;
send_msg.msg = msg.text;
msg.text = "Sending please wait...";
send_msg.sendAndLoad("index.php", send_msg, "POST");
send_msg.onLoad = function() {
if (send_msg.sta == "true") {
msg.text = "Now refresh your Page";
} else {
msg.text = "Failed";
}
};
}
5.Save and publish it(File name="Data").
6.Create a new php called "index.php".
7.Copy the code below and paste it.
PHP:
<?php
//Get a Msg from Flash
$flash=$_POST['flash'];
$msg=$_POST['msg'];
if($flash=='true')
{
//Open a File
$open=fopen("msg.txt",'w');
//Write to file
$write=fwrite($open,$msg);
if($write)
{
print "&sta=true&";
}
}
else
{
print' <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="550" height="100" id="Data" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="Data.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="Data.swf" quality="high" bgcolor="#ffffff" width="550" height="100" name="Data" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
<p>Type your text in the text field </p>';
//Open a File
$open=fopen("msg.txt",'r+');
//Read a file
$read=fread($open,1024);
//Print as HTML
print "<br><b><i>Your Previous Sended Msg is: $read <br><font color=\"#FF0000\"> By Satheesh KUmar</font></i></b>";
}
?>
Save and Run.
Demo:http://www.svprm.x10hosting.com/for_forums/php/index.php