Jump to content

Recommended Posts

I had a LOT of trouble with this until I figured out a nice, neat, easy template to use for all my sendAndLoad needs.

 

From my statement above you can probably imagine you're going to use flash's sendAndLoad method. It works kind of like this: you define your loadvars (I use 2, a send package and a load package to avoid data collisions), then you define the function to handle the incoming data, then you define all the variables you want to send (the send package), then you send them to a specific file (simultaneously defining where to store the returning data, if there is any -- the load package).

 

and it looks something like this:

 

trace("Sending data to PHP..."); // just some output for debugging// define sendData_lv and loadData_lv as local LoadVarsvar sendData_lv:LoadVars = new LoadVars();var loadData_lv:LoadVars = new LoadVars();// when loadData_lv loads (when data is returned from PHP)...// the script will send a success variable if the load was successfulloadData_lv.onLoad = function(success:Boolean) {// so if the load was successfulif (success) {	// you can access the returned variabled through "this.varName"	// here, it's tracing a variable named test	trace(this.test);} // end if (success)// else (if no success) (if the load failed)...else { 	trace("Unable to load file...");}}; // end function loadData_lv.onLoad// now that that's done, assemble the sendData_lv package// the syntax is sendData_lv.varName = data;// you can put as many variables in here as you'd like// but the more you add the slower it will processsendData_lv.test = "This is a test.";trace("Sending... " + sendData_lv); // another debug, testing the data that is being sent// now we send that data to a php file that will process it and return some results// we define the address of the file, the object to return the results to, and the method to send with, traditionally POSTsendData_lv.sendAndLoad("http://mysite.com/sendAndLoad.php", loadData_lv, "POST");

 

 

Finally, once all that is done you need to make the php file that will receive the data, do something with it, then return some sort of information.

 

 

<?php // sendAndLoad.php// check for data being sent from flash// if it's not there, return an errorif (!isset($_POST['test'])) {// any data being returned to flash must be sent to HTML, and each variable starts with// an ampersand (&), the variable name, an equal sign (=), and the dataecho '&test=Error! No data received.';} // end if (!isset($_POST['test']))// else if the data is not valid...else if ($_POST['test'] != "This is a test.") {echo '&test=Error! Invalid data.';} // and else if the data is not valid// else (if the data is present AND it is valid)...else {echo '&test=Hello world!';} // end else (if the data is present AND it is valid)// end sendAndLoad.php ?>

 

 

Now then, if everything works, you should receive the trace "Hello world!" after executing the sendAndLoad from flash

Link to comment
https://forums.phpfreaks.com/topic/168261-flash-to-php/#findComment-887509
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.