send data from flash to php

Flash and PHP Relation

send data from flash to php

Postby Ashish on Wed Dec 03, 2008 5:19 pm

// put this on first frame of flash and make a button and a input text box on stage named "myBtn" and "years"


ashi = new LoadVars();
myBtn.onRelease = function() {
ashi.years = years.text;
ashi.send("abc.php", "_self");
};


/* // The PHP Script
<?php
$calculation= $_POST['years'];
echo $calculation;
?>
*/

Ashish
 
Posts: 84
Joined: Tue Oct 14, 2008 1:49 pm

Re: send data from flash to php using LoadVars's sendAndLoad

Postby fffadmin on Sat Apr 17, 2010 12:20 pm

Send data from flash to php using LoadVars's sendAndLoad method -

Step 1

Make 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 2


i) 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");

}

fffadmin
Site Admin
 
Posts: 79
Joined: Mon Sep 22, 2008 10:26 pm
Location: India

Re: send data from flash to php using AS 3

Postby Ashish on Tue May 11, 2010 10:54 am

Send data from flash to php using AS3

Actionscript 3.0 code to send/pass variable values from flash to php.
Code: Select all

var request:URLRequest = new URLRequest ("http://127.0.0.1/seadAndLoadAs3/addUser.php");
request.method = URLRequestMethod.POST;

var variables:URLVariables = new URLVariables();

variables.firstName = "Give your first variable value here";
variables.lastName = "Give your second variable value here";
request.data = variables;

var loader:URLLoader = new URLLoader (request);

// configuring listeners...
loader.addEventListener(Event.COMPLETE, onComplete);
loader.addEventListener(Event.OPEN, openHandler);
loader.addEventListener(ProgressEvent.PROGRESS, progressHandler);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

//
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.load(request);


function onComplete(event:Event):void {
   trace(event.target.data);
}
/////////////////////////////////////////////////////////////

function httpStatusHandler(event:Event):void {
   trace("httpStatusHandler status: " + event+"\n\n");
}

function ioErrorHandler(event:IOErrorEvent):void {
   trace("ioErrorHandler: " + event+"\n\n");
}

function openHandler(event:Event):void {
   trace("openHandler: " + event+"\n\n");
}

function progressHandler(event:ProgressEvent):void {
   trace("progressHandler loaded:" + event.bytesLoaded + " | total: " + event.bytesTotal+"\n\n");
}

function securityErrorHandler(event:SecurityErrorEvent):void {
   trace("securityErrorHandler: " + event+"\n\n");
}



PHP code to receive variable values, sent from Flash ActionScript 3.0

Code: Select all
<?php

$fname = $_POST['firstName'];
$lname = $_POST['lastName'];

Print "Result =" .$fname.$lname;

?>

Attachments
sendAndLoad_variable-sourceCode_AS3_Example.zip
Login to download the source code.
(7.05 KiB) Downloaded 8 times
Ashish
 
Posts: 84
Joined: Tue Oct 14, 2008 1:49 pm


Return to Flash and PHP

Who is online

Users browsing this forum: No registered users and 1 guest

cron