duffman014 Posted July 31, 2009 Share Posted July 31, 2009 can someone point me in the right direction maybe to some tutorials im using flash actionscript 2.0 and im trying to just figure out how to send variables to and from.. i cant find anything that gives me good information... any help or tips??? Quote Link to comment https://forums.phpfreaks.com/topic/168261-flash-to-php/ Share on other sites More sharing options...
GingerRobot Posted July 31, 2009 Share Posted July 31, 2009 Since you're having troubles with the flash/action script part of this, you shouldn't be posting in the PHP section of the forums. I've moved it here so that it might get the attention of people who know more about this subject. Quote Link to comment https://forums.phpfreaks.com/topic/168261-flash-to-php/#findComment-887497 Share on other sites More sharing options...
Errant_Shadow Posted July 31, 2009 Share Posted July 31, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/168261-flash-to-php/#findComment-887509 Share on other sites More sharing options...
phpfreakjav Posted August 1, 2009 Share Posted August 1, 2009 http://www.phpfreaks.com/forums/index.php/topic,255426.0.html Quote Link to comment https://forums.phpfreaks.com/topic/168261-flash-to-php/#findComment-888403 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.