Twitsnip is a place to post code snippets and share them. Login with your existing Twitter account, if you don't have a Twitter account simply create on at www.twitter.com

Sending dynamic data to server and back in flash

Sending dynamic data to server and back in flash

0

This snippet shows how to send data from flash to php then change the data and send back to flash using LoadVars.

var retrieveLoadVars:LoadVars = new LoadVars();// setup object to catch data from remote file
var sendLoadVars:LoadVars = new LoadVars(); // setup object to send data to remote file
retrieveLoadVars.onLoad = function(success) // call function when data is loaded
{
	if(success) //function to run if data has been loaded
	{
		trace(retrieveLoadVars.name1);// print out results to the output window
		trace(retrieveLoadVars.name2);// print out results to the poutput window
	} else //data not loaded
	{
		trace("error");// print out error to the poutput window
	}
}
sendLoadVars.param1 = "flash";//send data to remote file
sendLoadVars.param2 = "rules";//send data to remote file
sendLoadVars.sendAndLoad("http://www.yourdomain.com/filename.php",retrieveLoadVars,"POST");
//send data to remote file then load the data. specify url then object to catch loaded data then method to be used.

//This is the php that is used:

<?php
$name1 = $_POST['param1'];
$name2 = $_POST['param2'];
if($name1 == 'flash'){ $name1 = 'php';}
echo "name1=$name1&name2=$name2";
?>

Tags: LoadVars, server, data, flash

Comments

No comments yet

Login to Twitter to comment