Send data from flash to php using
LoadVars's
sendAndLoad method -
Step 1Make a page 'greeting.php' and put the following PHP Script on that, Then Upload in on Server,
You can use EasyPHP to Test it.Page Name : greeting.php
- Code: Select all
<?php
$full_name = $_POST['full_name'];
$email = $_POST['email'];
$id_number = $_POST['id_number'];
$cell_phone = $_POST['cell_phone'];
print "welcomeMessage = hi ".$source_name." full name =".$full_name.", ovi email= ".$ovi_email.", Id Number= ".$id_number;
?>
Step 2i) Open Flash, On Stage Make 4 Text Input Fields and Give instance name like this -
txtName,
txtmail,
txtIdnumber,
txtCellphone.text ii) Make a button and give it instance name '
sendData_btn'
iii) On Frame copy and paste the following code -
iv) In Code update
_root.sitePath="greeting.php", PHP PAGE URL.
- Code: Select all
_root.sitePath="greeting.php"
sendData_btn.onRelease = sendDataToPhp
function sendDataToPhp() {
var result_lv:LoadVars = new LoadVars();
result_lv.onLoad = function(success:Boolean) {
if (success) {
} else {
trace("Error connecting to server")
}
};
// Returened Data ..........................................................
result_lv.onData=function(src:String){
trace(src)
gotoAndStop(2)
}
///
// Check Status / Errors..........................................................
result_lv.onHTTPStatus = function(httpStatus:Number) {
if(httpStatus < 100) {
trace("flashError");
}
else if(httpStatus < 200) {
trace("informational");
}
else if(httpStatus < 300) {
trace("successful");
}
else if(httpStatus < 400) {
trace("redirection");
}
else if(httpStatus < 500) {
trace("clientError");
}
else if(httpStatus < 600) {
trace("serverError");
}
}
/////////////-------------------------------------------------------------
// Check Progress..........................................................
this.onEnterFrame = function(){
trace((result_lv.getBytesLoaded()/result_lv.getBytesTotal())*100)
if((result_lv.getBytesLoaded()/result_lv.getBytesTotal())*100==100){
delete this.onEnterFrame
}
}
/////////////-------------------------------------------------------------
var send_lv:LoadVars = new LoadVars();
// set variables
send_lv.full_name = txtName.text;
send_lv.email = txtmail.text;
send_lv.id_number = txtIdnumber.text
send_lv.cell_phone = txtCellphone.text
send_lv.sendAndLoad(_root.sitePath,result_lv,"POST");
}