1. Basic communication process
Figure 1 A schematic diagram of the communication process between SWF+XML and the server. Click to enlarge the image
. Figure 1 shows a schematic diagram of the communication process in this example. Server-side scripts that pass information between Flash and the database read and write data in XML format.
You can use ActionScript to convert the information collected in the SWF file into an XML object, and then send the data to the server-side script as an XML document. You can also use ActionScript to load the XML document returned by the server into an XML object for use in a SWF file. In this example, saving the relevant XML data is done by the server's script program, which is also the focus of this example.
2. Communication methods between flash and ASP
A variety of communication methods can be used between flash and ASP. In this example, the LoadVars object is used.
LoadVars provides a way to send variables to the server using the POST method.
3. Server script
Server script can be written by a variety of programs. In this example, ASP is used as an example to write relevant scripts.
Microsoft Active Server Pages (ASP) is a server-side scripting environment that allows you to create and run dynamic, interactive Web server applications.
Scripts are written using an associated scripting language; a scripting language is somewhere between HTML and programming languages such as Java, C++, and Visual Basic. HTML is commonly used to format text and link web pages. Programming languages are often used to send a complex sequence of instructions to a computer. Scripting languages can also be used to send instructions to computers, but their syntax and rules are not as strict and complex as compilable programming languages. Scripting languages are primarily used for formatting text and using compiled components written in programming languages.
ASP makes it possible for Web developers to write complete processes in multiple scripting languages. In fact, multiple scripting languages can be used within a single .asp file.
We can use any scripting language whose corresponding scripting engine is installed on the Web server. Two languages, VBScript and JavaScript, are usually used; among them, the default scripting language of ASP is VBScript. In this example, VBScript is used to write the script.
Let’s take a look at the specific example production below.
Example production:
1. Flash side
First create the following interface. The code for capturing the annotation points has been mentioned in the previous lecture. In this example, in addition to the place name, some basic information is added. The method is the same and will not be repeated here; in the end, the code that needs to be saved will be Assigned to the string variable SendData_srt.
Figure 2 SWF file interface 1
Click to see larger image
Figure 3 SWF file interface 2
uses a variable named Link to accept messages from the server. If its value is 1, it indicates that the communication connection with the server is successful. use
LoadVars, and then use the sendAndLoad method to send the data under a LoadVars entity.
Open the Actions panel of the timeline and enter the following ActionScript code:
function SendData():Void { //Define the function to send data var SendData = new LoadVars(); //Construct a new LoadVars object SendData.Check = 1; //Set the Check action for the server to verify SendData. data = SendData_srt; //Assign the data variable SendData_srt to be sent to data output_txt.text = "Please wait..."; //The status text is displayed as "Please wait..." SendData.onLoad = function(success) { //Function to verify the connection with the server if (success) { //If the connection with the server is successful if (this.Link== "1") { //If the verification action is successful output_txt.text = "Successfully marked! After review Effective. "; //The status text is displayed as successful } } else { output_txt.text = "The server is busy, please try again later! "; //If the connection with the server is unsuccessful, a failure message will be returned } }; SendData.sendAndLoad( "http://www.wanggesz.com/XMLData/Save.asp", SendData, "post"); //Send data to be saved in post mode } |
to create an ASP file with the following content:
<%@Language="VBScript"%> <% Dim Check 'Define the Check variable to verify the data from the SWF file Dim Link 'Define the Link variable , used to return to the SWF file to indicate successful communication Dim data 'Define the data variable to receive the data to be saved from the SWF file set data = Request.Form("data") 'Receive the data to be saved from the SWF file set Check = Request.Form("Check") 'Verify the data from the SWF file if Check = 1 Then 'If the SWF file identity is correct Link = 1 'Set the Link value to 1, indicating that the communication is successfulEnd if 'End the if statement xml.Async=False xml.ValidateOnParse=False xml.Load(server.mapPath("http://www.wanggesz.com/XMLData/data.xml")) set newNode=mxml.createNode ("element", "data", "") root.appendChild(newNode) Set objname = mxml.createAttribute("data") xml.save(server.mapPath("http://www.wanggesz.com/XMLData/data.xml")) %> |
In this way, we have completed the map operation, place name annotation and other functions in turn; in the process of using the map, using place names for query and positioning is also an indispensable common function.