In the previous lecture, we introduced how to edit place name tagging in the electronic map debugging environment (see "using trace functions to quickly mark place names in the interactive map background"). Because the amount of information on the electronic interaction map is too large, a large number of operators on the client can complete the tagging work together. In this way, the online tagging function must be realized. However, such features cannot be implemented independently by Flash. We can help with ASP, ASP.net, PHP, etc. In this example, we use ASP to jointly implement the online tagging function.
1. Basic communication process
Figure 1 shows the communication process diagram in this example. Server scripts that transmit information between Flash and databases 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 as an XML document to the server script. You can also load the XML document returned by the server to an XML object using ActionScript to use this document in the SWF file. In this example, saving the relevant XML data is completed by the script program on the server, which is also the focus of this example.
2. Communication between flash and ASP
You can use multiple communication methods between flash and ASP. In this example, the LoadVars object is used.
LoadVars provides a way to deliver variables to the server by using the POST method.
3. Server scripts
Server scripts can be compiled by multiple programs. In this example, ASP is used as an example to compile related scripts.
Microsoft Active Server Pages (ASP) is a Server-side scripting environment that allows you to create and run dynamic and interactive Web Server applications.
You need to use the relevant scripting language to write a script program. The scripting language is between programming languages such as HTML and Java, C ++, and Visual Basic. HTML is usually used to format text and link webpages. A programming language is usually used to send a series of complex commands to a computer. Scripting languages can also be used to send commands to computers, but their syntax and rules are not as strict and complex as compiled programming languages. The script language is mainly used to format text and use compiled components written in programming languages.
ASP makes it possible to compile a complete process in multiple scripting languages for Web development. In fact, you can use multiple scripting languages within a single. asp file.
We can use any script language with its corresponding script engine installed on the Web server. VBScript and JavaScript are usually used. The default scripting language of ASP is VBScript. This example uses VBScript to write scripts.
Let's take a look at the specific instance creation.
Instance Creation:
1. Flash end
First, create the following interface. The code for capturing annotation points has been mentioned in the previous lecture. In this example, only the names of place names are added with some basic information. The methods are the same, so we will not repeat them here; finally, the code to be saved is assigned to the string variable SendData_srt.
Use a variable named Link to receive messages from the server. If the value is 1, the communication with the server is successful. Use
LoadVars, and then use the sendAndLoad method to send data under a LoadVars object.
Open the action panel of the timeline and enter the following ActionScript code:
Function SendData (): Void {// defines the function for sending data Var SendData = new LoadVars (); // Construct a new LoadVars object SendData. Check = 1; // sets the Check action for server verification. SendData. data = SendData_srt; // assign the data variable SendData_srt to the data Output_txt.text = "please wait ...... "; // The status text is displayed as" please wait ...... " SendData. onLoad = function (success) {// verify the function connected to the server If (success) {// if the connection is successful with the server If (this. Link = "1") {// if the verification action is successful Output_txt.text = "marked successfully! The review takes effect immediately. "; // The status text is displayed as successful } } Else { Output_txt.text = "The server is busy. Please try again later! "; // If the connection to the server is unsuccessful, the system returns the error message. } }; SendData. sendAndLoad ("http://www.wanggesz.com/XMLData/Save.asp", SendData, "post "); // Send the data to be saved in post mode } |
2. Write server scripts (ASP)
Create an ASP file with the following content:
<% @ Language = "VBScript" %> <% Dim check' defines the Check variable to verify the data from the SWF file. Dim Link 'defines the Link variable, which is used to return to the SWF file, indicating that the communication is successful. Dim data defines the data variable to receive the data to be saved from the SWF file Set data = Request. Form ("data") 'receives the data to be saved from the SWF file Set Check = Request. Form ("Check") 'verifies 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 successful End if' End if statement Set xml = Server. CreateObject ("Microsoft. XMLDOM ") 'Create an object to operate XML files Xml. Async = False Xml. ValidateOnParse = False Xml. Load (server. mapPath ("http://www.wanggesz.com/XMLData/data.xml ")) 'Load the xml file Set newNode = mxml. createNode ("element", "data ","") 'Create a new node newnode' and set it to data Root. appendChild (newNode) 'Append a new node newNode to the root node of the XML file loaded above, Set objname = mxml. createAttribute ("data ") 'Create an attribute item for the newly created node objname. Text = data' add an attribute value for the newly created attribute item Xml. save (server. mapPath ("http://www.wanggesz.com/XMLData/data.xml ")) 'Save the XML file in the specified path, Response. write "Link" & Link "returns Link = 1 to the SWF file %> |
In this way, map operations and place name tagging are completed in sequence, searching and locating by place name is also an essential and common function.