In AS2, you typically use the Loadvars class to exchange data with a Web server:
var msg:LoadVars = new LoadVars();
var msgSent:LoadVars = new LoadVars();
msg.var1 = "one";
msg.var2 = "two";
msgSent.onLoad = function(success:Boolean):Void {
if (success) {
trace("Message sent.");
}
else {
trace("Message failed.");
}
};
msg.sendAndLoad ("http://127.0.0.1:8080/communicate_flash/index.jsp", msgSent);
==================================================================== ===============
In AS3, the equivalent of:
var scriptRequest:URLRequest = new URLRequest ("http://127.0.0.1:8080/communicate_flash/index.jsp");
var scriptLoader:URLLoader = new URLLoader();
var scriptVars:URLVariables = new URLVariables();
scriptLoader.addEventListener(Event.COMPLETE, handleLoadSuccessful);
scriptLoader.addEventListener(IOErrorEvent.IO_ERROR, handleLoadError);
scriptVars.var1 = "one";
scriptVars.var2 = "two";
scriptRequest.method = URLRequestMethod.POST;
scriptRequest.data = scriptVars;
scriptLoader.load(scriptRequest);
function handleLoadSuccessful(evt:Event):void {
trace("Message sent.");
trace("DataReceived:" + evt.target.data);
}
function handleLoadError(evt:IOErrorEvent):void {
trace("Message failed.");
}
==================================================================== ===============
Scriptloader.load (Scriptrequest): is actually sending a request to the server:
http://127.0.0.1:8080/communicate_flash/index.jsp? var1=one&var2=two
==================================================================== ===============
Where communicate_flash/index.jsp is a Web application that we deploy under Tomcat WebApps:
index.jsp files are as follows:
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
System.out.println("----- connected -----");
// 在和 flash 通信时,请保证字符集为 UTF-8,否则传输中文会产生乱 码
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
out.print("result1=天天"+request.getParameter ("var1")+",");
out.print("result2=快乐"+request.getParameter ("var2"));
%>
==================================================================== ===============
When the data returned from the JSP page is received, the handleloadsuccessful () function is called: The data is obtained by Evt.target.data:
result1=天天one,result2=快乐two
==================================================================== ===============
Finally, don't forget that JSP is the servlet, so you can communicate with the JSP and the servlet. Of course, with PHP, ASP communication methods are the same. The above is flash and background communication The simplest and most direct method.