Post Method for Data Interaction Between as3.0 and PHP

Source: Internet
Author: User

Post Method for Data Interaction Between as3.0 and PHP

 

 

Post Method for Data Interaction Between as3.0 and PHP
First open flash to create an as3.0 File
Drag textarea and button to form the stage
Name the two components: txtcontent and addcontent.

Then, click the first frame to add the action:
VaR URL: String = "http: // localhost/TT. php"; // execute the PHP file to operate the database
VaR requestdata: URLRequest = new URLRequest (URL); // creates a URLRequest object to obtain the data of textarea in flash.
VaR Loader: urlloader = new urlloader (); // creates a urlloader object to send textarea data in flash.
Addcontent. addeventlistener (mouseevent. Click, adddata); // attaches an event object to the button. click the button to execute the adddata function.
Function adddata (E: Event ){
Requestdata. Data = string; //. Data is an attribute of URLRequest. You can check the manual for three attributes.
Requestdata. method = urlrequestmethod. Post; //. method is also an attribute value of urlloader.
VaR urlvariables: urlvariables = new urlvariables (); // create a urlvariables object,
Urlvariables. Cc = txtcontent. Text; // pass the data in txtcontent through the CC Parameter
Requestdata. Data = urlvariables; // The data of urlvariables is assigned to. Data.
Loader. Load (requestdata); // start to send data
}
PHP file is simple
<?
$ Content = $ _ post ["cc"]; // obtain the parameters passed in flash.
$ Conn = mysql_connect ("localhost", "root", "123456") or die ("MYSQL:". mysql_error ());
Mysql_select_db ("guestbook", $ conn) or die ("MYSQL:". mysql_error ());
$ SQL = "insert into topic (content) values ('$ content ')";
Mysql_query ($ SQL );
// Connect to the database and execute the SQL statement.
?>

My code:

        
Function sendpostjson (array: array): void {

VaR variables: urlvariables = new urlvariables (); // create a urlvariables object
Variables. Name = 'hcity capital ';
Variables. Age = '25 ';

/*
* If JSON data is used
VaR objectarray: String = '{"name": "Didi", "Age": "28 "}';
VaR JSON = JSON. Decode (objectarray );
Variables. Name = JSON. Name;
Variables. Age = JSON. Age;
*/

VaR requert: URLRequest = new URLRequest ('HTTP: // thinkphp3.com/addinfo.php ');

Requert. method = urlrequestmethod. post;

Requert. Data = variables;

VaR Loader: urlloader = new urlloader ();
Loader. addeventlistener (event. Complete, onurlloadercompleteevent );
Loader. Load (requert );
}

Private function onurlloadercompleteevent (Event: Event): void {
VaR data: String = urlloader(event.tar get). Data;
Trace ('onurlloadercompleteevent OK: '+ data );
}

The PHP server code is very simple, that is, to submit the received post data to the database!
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.