Create a client to send data on the basis of the original one.
Step: Import flash. Text .*;
Use the textfield class to create two input boxes
For example:
Username = new textfield (); <br/> addchild (username); <br/> username. width = 200; <br/> username. height = 20; <br/> username. X = stage. stagewidth/2; <br/> username. y = stage. stageheight/2; <br/> username. type = textfieldtype. input; // Input Method <br/> username. border = true; // border <br/> username. background = true;
Specify its position, width, and height, and specify the border display and background. Specifies the textfield object as the input mode.
Next, create a button:
VaR BTN: button = new button (); <br/> addchild (BTN); <br/> BTN. width = 40; <br/> BTN. height = 20; <br/> BTN. label = "send"; <br/> BTN. X = stage. stagewidth/2; <br/> BTN. y = stage. stageheight/2 + 50; <br/> BTN. addeventlistener (mouseevent. click, sendhander );
Initialize its height and width, specify the location, and listen to the method.
Package <br/> {<br/> Import flash. display. sprite; <br/> Import flash. events. *; <br/> Import flash. text. *; <br/> Import flash. display. simplebutton; <br/> Import FL. controls. button; <br/> Import flash.net. *; <br/> public class main extends sprite <br/>{< br/> private var con: connect; // connection class <br/> private var Username: textfield; // name <br/> private var PWD: textfield; // password <br/> public function main () <br/>{< br/> con = Connect. getconnect (); <br/> Init (); // initialization input box <br/>}< br/> private function Init (): void <br/> {</P> <p> username = new textfield (); <br/> addchild (username); <br/> username. width = 200; <br/> username. height = 20; <br/> username. X = stage. stagewidth/2; <br/> username. y = stage. stageheight/2; <br/> username. type = textfieldtype. input; // Input Method <br/> username. border = true; // border <br/> username. background = true; </P> <p> Pwd = new t Extfield (); <br/> addchild (PWD); <br/> pwd. width = 200; <br/> pwd. height = 20; <br/> pwd. X = stage. stagewidth/2; <br/> pwd. y = stage. stageheight/2 + 22; <br/> pwd. type = textfieldtype. input; // input mode <br/> pwd. border = true; // border <br/> pwd. background = true; </P> <p> var BTN: button = new button (); <br/> addchild (BTN); <br/> BTN. width = 40; <br/> BTN. height = 20; <br/> BTN. label = "send"; <br/> BTN. X = stage. stagewidth/2; <br/> BTN. y = stag E. stageheight/2 + 50; <br/> BTN. addeventlistener (mouseevent. click, sendhander); </P> <p >}< br/> private function sendhander (E: mouseevent): void <br/>{< br/> If (username. text! = "" | PWD. Text! = "") <Br/>{< br/> var para: urlvariables = new urlvariables (); // send the required data, including user name and password <br/> para. username = username. text; <br/> para. userpwd = PWD. text; <br/> con. sendmessage (para, connect. myurl); <br/>}else <br/>{< br/> trace ("Empty message cannot be sent "); <br/>}< br/>}
One is the name and the other is the password. Call the original class to create and send it to the platform
There is a button in the input box for code creation. Send the required data by clicking the button
Private function sendhander (E: mouseevent): void <br/>{< br/> If (username. Text! = "" | PWD. Text! = "") <Br/>{< br/> var para: urlvariables = new urlvariables (); // send the required data, including user name and password <br/> para. username = username. text; <br/> para. userpwd = PWD. text; <br/> con. sendmessage (para, connect. myurl); <br/>}else <br/>{< br/> trace ("Empty message cannot be sent"); <br/>}
Next is the server end.
Use a simple method to accept data:
<% @ Page contenttype = "text/html; charset = gb2312" Language = "Java" Import = "Java. SQL. * "errorpage =" "%> <br/> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br/> <HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = gb2312 "/> <br/> <title> untitled document </title> <br/> </pead> <br/> <body> <br/> <p> welcome to 2ss3 </P> <br/> <% <br/> string myname = request. getparameter ("username"); <br/> string Pwd = request. getparameter ("userpwd"); <br/> out. print (myname); <br/> out. print (PWD); <br/> // session. setattribute ("username", myname); <br/>%> <br/> </body> <br/> </ptml> <br/>
The encapsulated link class
Package <br/> {<br/> Import flash.net. urlloader; <br/> Import flash.net. URLRequest; <br/> Import flash. events. *; <br/> Import flash.net. urlvariables; <br/> Import flash.net. urlloaderdataformat; <br/> Import flash.net. *; <br/> public class connect <br/>{< br/> Private Static Var CONNECT: connect = NULL; <br/> // URL of the connection <br/> Public Static Var myurl: String = "http: // localhost: 8080/flash/index. JSP "; </P> <p> Public static function getconnect (): connect <br/>{< br/> If (connect = NULL) <br/>{< br/> connect = new connect (); <br/>}< br/> return connect; <br/>}< br/> Public Function sendmessage (para: urlvariables, myurl: string ): void <br/> {// set the variable for sending data </P> <p> // set the method for sending data <br/> var request: URLRequest = new URLRequest (); <br/> request. data = para; <br/> request. url = myurl; <br/> request. method = urlrequestmethod. post; // sending method </P> <p> // sending data <br/> var Loader: urlloader = new urlloader (); <br/> loader. dataformat = urlloaderdataformat. variables; // format of data transmission <br/> loader. addeventlistener (event. complete, completehandler); <br/> loader. addeventlistener (ioerrorevent. io_error, iohandler); <br/> try <br/>{< br/> loader. load (request); <br/>}< br/> catch (E: Error) <br/>{< br/> trace ("failed "); <br/>}</P> <p >}< br/> private function completehandler (E: Event ): void <br/> {<br/> trace ("OK"); <br/> var loader2: urlloader = urlloader(e.tar get); <br/> var variables: urlvariables = new urlvariables (loader2.data); <br/> trace (variables. daynames); </P> <p >}< br/> private function iohandler (E: Event ): void <br/>{< br/> trace ("failed"); <br/>}< br/>}