Simple ASP loads the access database, generates XML, and then loads the XML data into the LIST component for example learning. First, ASP reads the ACCESS database.
Copy the code code as follows:
<% @language=VBScript @codepage=65001%>
<%
'Turn on explicit variable declaration
Option Explicit
'Set output type
Response.contentType=text/xml
'Define three variables, conn (Connection object), connstr (ConnectionString), sql (a SQL statement)
dim conn,connstr,rs,sql,i
'Define the value of ConnectionString
i=1
connstr=provider=Microsoft.Jet.OLEDB.4.0;data source=&Server.MapPath(test.mdb)&;
'Create server connection object
set conn=Server.CreateObject(ADODB.Connection)
'Create a data set object
set rs=Server.CreateObject(ADODB.RecordSet)
'Open data connection
conn.open connstr
'The meaning of this sentence is to retrieve the first 100 song1name and dong1url field values in the ascending order of the id field value in the word data table. The value is attached to the dataset object as a property of the dataset.
sql=select top 100 [song1name],[dong1url] from [test] order by id desc
'The cursor type and lock type are both set to 1. This is a forward-only read-only behavior with the fastest reading speed.
rs.open sql,conn,1,1
Response.Write(<?xml version='1.0' encoding='utf-8'?><Taosha.com>)
'Perform a do while loop and conditionally loop to the last item that meets the condition
do while not rs.eof
'This is the modified part so that the output file can be recognized by the LoadVars object in Flash.
Response.Write(<song information><song name>&rs(song1name)&</song name><address>&rs(dong1url))&</address></song information>
'Record moved down
rs.movenext
i=i+1
'The loop method that echoes do while is the main loop body
loop
Response.Write(</Taosha.com>)
'Close the dataset object
rs.close
'Close the database connection
conn.close
'Release data set resources
set rs=nothing
'Release database connection resources
set conn=nothing
%>
This part of the code is to read the database.
Let's take a look at how XML is generated. In fact, it is during output. Plus the corresponding format of XML. For example, <song information>, and various tags, etc. Be sure to note that each label must be closed.
The entire code of this xml.asp file is as follows:
Next, let’s take a look, how is it loaded in FLASH?
Here, it should be very simple.
Copy the code code as follows:
//Define components
var my_TextArea:mx.controls.TextArea;
var my_List:mx.controls.List;
var my_XML:XML = new XML();
my_XML.load(http://www.taoshaw.com/taoshaw/study/accessAndList/xml.asp);
my_XML.onLoad = function(ok:Boolean) {
if (ok) {
for (i=0; i[td] my_List.addItem({label:this.firstChild.childNodes.childNodes[0].childNodes[0].nodeValue, data:this.firstChild.childNodes.childNodes[1].childNodes[ 0].nodeValue});
}
}
};
var my_Object:Object = new Object();
my_Object.change = function(eventObj:Object):Void {
my_TextArea.text += eventObj.target.selectedItem.label+/n;
};
my_List.addEventListener(change, my_Object);
In this way, the generated XML file is imported into the LIST. Through monitoring functions, data can be called.
If you learn this well, it will not be difficult to create some background projects, such as photo albums, dynamic article management, players, etc.
When making some FLASH that needs to load external files, special attention needs to be paid to the encoding issue.
First of all, be careful not to appear twice in the same FLASH: System.useCodepage=true;
The original meaning of this sentence is to convert the encoding of the loaded external non-Utf-8 format file into the uft-8 format. If it is used twice, an error will definitely occur.
The general cooperation method is to choose the encoding format of uft-8 or Gb2312 when saving external files. As for the detailed difference between these two encodings, I am not sure yet. I hope that if you have friends who understand, you can give me some pointers.
The i in ASP is meaningless. Can be removed. In line 26 of the posted part, the brackets are in the wrong position.
In addition, the code in if(ok){} in the AS posted by the poster is missing part of it. The for loop is incomplete.
Copy the code code as follows:
useCodePage property
useCodePage:Boolean [read-write]
Language version: ActionScript 3.0
Player version: Flash Player 9
A Boolean value that tells Flash Player which code page to use to interpret external text files. When this property is set to false, Flash Player uses Unicode to interpret external text files. (These files must be encoded in Unicode when you save them.) When this property is set to true, Flash Player interprets external text files using the legacy code page of the operating system that the player is running on. The default value of useCodePage is false.
Text loaded as an external file (using flash.display.Loader.load(), flash.net.URLLoader, flash.net.URLStream, or the XML class) must have been saved using Unicode encoding in order for Flash Player to recognize it as Unicode . To encode external files using Unicode, save the files in a Unicode-aware application (for example, Notepad on Windows 2000).
If the external text file being loaded is not in Unicode encoding format, useCodePage should be set to true. In the first frame of the SWF file where the data will be loaded, add the following code right at the front so that it is the first line of code:
System.useCodePage = true;With this line of code, Flash Player will use the legacy code page of the operating system that Flash Player is running to interpret external text. For English Windows operating systems, this code page is usually CP1252; for Japanese operating systems, this code page is usually Shift-JIS. Flash Player 6 and later handle text the same as Flash Player 5 if useCodePage is set to true. (Flash Player 5 treats all text as text encoded in the legacy code page of the operating system the player is running on.)
If you set useCodePage to true, be aware that the characters used in your external text file must be included in the legacy code page of the operating system the player is running on in order for the text to be displayed. For example, if you load an external text file that contains Chinese characters, the characters cannot be displayed on a system using the CP1252 code page because that code page does not include Chinese characters.
To ensure that external text files used in your SWF files can be viewed by users on all platforms, all external text files should be encoded as Unicode and leave useCodePage set to false. This way, Flash Player 6 and later will interpret the text as Unicode.