First time here? First time here? Newsletter Signup Newsletter
651326 Members and growing! | Flash Jobs
Search tutorials
Author: Jeffrey F. Hill | Website: http://www.flash-db.com/services/

Sending the data from the Translation script

First we have to add some ActionScript to let the movie know what to do when someone clicks on the 'Translate Now' Push button component. This is shown as follows (remember the push button was given an instance name of 'submit'):

// Set the change Handler function for the push button named 'submit'
submit.setClickHandler("onClick");

Now that we have that set up - we add the 'onClick' function. This function will locate all of the necessary data in the movie and send it to the script which handles the translation.

// Function to handle what the movie does when some one selects a mode and clicks the push button.
function onClick(){
	
   // Grab some values from the ComboBox and the Input Text Field.	
   sendMode 			= comboBox.getSelectedItem().data["mode"];
   sendText	    		= Input.text;
   
   // Load New vars.. (this is the Load Vars object that will send and receive the response from the server,
   //  ie - sends 2 variables to a PHP script - then returns an Object that has the translation.
   translate 			= new LoadVars();
   
   // Add Vars to translate Object.
   translate.Mode        		= sendMode;
   translate.sourceData  		= sendText;

   // This Tells the Flash movie What function to invoke when the Load Vars Is complete. 
   translate.onLoad 		= addTranslation;

   // Find the Text File - Load it - after which the function addTranslation is invoked.
   translate.sendAndLoad("Translate.php", translate, "POST");
}

Ok what where doing here is getting the selected mode and the text entered by the user in the text field with instance name 'Input'. Then creating a new Load Vars object and sending it to the script which handles everything else. The important thing here is that we load up the Load Vars object with all of the variables we want to send to the script. In this case we are naming the new load Vars object 'translate' - so we add two variables to the Object in standard dot syntax ie (translate.Mode = sendMode). So now the Translate Object has 2 variables associated with it - Mode and sourceData. Mode is the language conversion we want to do, and sourceData is the user entered text to translate. We then use the sendAndLoad method to send these variables via "POST" to the receiving script. We also set an .onLoad function (addTranslation) to handle what's returned.

Recieving the data from the Translation script

So before we get to the Server side of this, we set up the function addTranslation.

function addTranslation() {
	Output.htmlText = translate.soapOut;
}

The Text field with instance name 'Output' receives the results of the script (the translated text). The same Load Vars Object is referenced in this case (translate) - and it now contains the resulting data. Make sure to specify the output sent to the 'Output' text field as HTML text. This is done by using the property - .htmlText. So now the Output text field knows that it is receiving HTML text and will format it correctly.

So now the Flash Client is set up and ready to send and receive the data.

» Level Advanced

Added: 2002-08-19
Rating: 7 Votes: 10
(10 being the highest)
» Author
Jeffrey Hill is a freelance web developer from Boulder, Colorado. He specializes in creating and developing dynamic database driven Flash content, applications, and content management systems. Specialty's include SQL, PHP, Perl, XML, web services, and Flash clients for web services.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: doc_chin7
» Description:

The flash's horizontal road drive was done in CS4 and was upgraded to CS6. The car responds to right/ left key and flash will auto-generate the movement of roads from left-right or right-left based on random number. Have fun driving in this virtual environment and avoid other cars... :) If you are creative, a road driving game can be created from it.

Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.