Using

xiaoxiao2021-03-06  14

USING_FOD

Written by Leefj

See the upper part compressed package documentation

I. Overview

FDO is a set of components that can be operated between Flash and the server, which integrates the Flash client and the server and use XML to complete data exchange. You can use FDO to query, update, etc. FDO can also make certain extensions, even if it is not a database operation, FDO can also be used, such as some information on the server, etc. Since the server can adopt a variety of technologies, the server function can be implemented in accordance with the specified data exchange format, and the current version is implemented using the ASP, only some of the simplest features. In FDO debugging, a relatively simple, relatively common mode: Flash ASP Access. In addition to the main module, the server program is a certain degree of modification to adapt to the needs of different services. Of course, FDOs can also implement some extensions to adapt to different business logic.

In security, the FD is not transmitting SQL to the server, which can only send a command string and related parameters. The server accepts this data and finds the server defined SQL that has been defined in the server according to the command string, and then executes SQL and returns the result. In addition, FDO has also made certain precautions for SQL injection, SQL injection.

Here I will gradually describe how to use the ASP version of FDO in your Flash app. You can also view some technical parameters and user interfaces of FDO in additional reference documents. The original procedure and related comments have been given in the fdo_asp.rar compression package, you can modify and expand in your own requirements.

Second, use FDO

Let's introduce the use of FDOs as and in your application, I will explain a step by step.

[1] Building a debugging environment

Create your site directory in your hard drive, I named MySite here. Unzip the FDO compression package, including four folders:

· FDO_SERVER: The server FDO directory can modify the directory name according to the actual needs.

· Client: Client FDO class file, component file.

· Database: Debugged database directory.

· DOC: FDO related documentation.

Copy them into MySite your site directory while establishing a corresponding MySite site in your Dreamweaver. Open IIS now, build a virtual directory of MySite.

Then, according to your actual needs, I will modify the name of the FDO server FDO_SERVER folder, and I change it to: myfdo_sv_1, and shown in the figure. Of course, if you don't think you want to modify it, you may not modify it.

After completing these, you can perform the test of the database connection. In IIS, browse the FDO_CONN_TEST.ASP file, test the database connection. Of course, you may use other databases, this requires additional configuration, and then say it.

IIS opens IE to run FDO_CONN_TEST.ASP, if the result is as shown in the figure, the connection is successful, and the next operation can be performed.

In this way, the debugging environment is almost built, and it is almost also the basic steps of establishing an ASP site locally.

The Flash project Myfl is then created, and the Flash document of addNew_test.fla is created. Establish a MyFL_PRJ folder at the site root directory to store Flash files, as shown in the figure to build a project.

Join the class file to your project, there are two ways. Let's talk about the first method first. Copy the FDO folder under the Client directory to myfl_prj folder, the AS file under the client directory is the source file of FDO. This is not said, everyone knows. Figure:

Then you need to add a class path for Flash, in EditàPreferencàActionScriptàActionScript 2.0 Settings Add a ./fdo class path: This will be commissioned. The second method is to release the FDO in a component, copy the fdo.swc to the FDO.SWC in the Client directory En / Configuration / Components / Data Components under the Flash installation directory, then restart flash, and call up the component panel. FDO components.

Then, add this component to the current Flash file, and the FDO project appears in the library panel. After you have finished these, you can work with the server to debug FDO. But it is necessary to pay attention to the first method and the second

Now add the following code and test it in the first frame of the AddNew_Test.fla Flash document.

VAR BaseURL: String = "http://127.0.0.1/mysite";

VAR FDO_SV1_NAME: String = "Myfdo_sv_1";

Var myfdo_1: fdo = new fdo (baseurl, fdo_sv1_name);

Output in the Output panel:

[debug] create fdo; fdo_servernane: myfdo_sv_1; siteURL: http://127.0.0.1/mysite

Here you need to explain, BaseURL refers to your site URL, IIS on my computer uses 88 ports with other software conflicts, your computer is generally 80 ports in the URL without indicating ports. This baseURL can directly intercept paste directly in the IE address bar. FDO_SV1_NAME is also the name of the FDO server, that is, the current name of the folder named by FDO_SERVER to myfdo_sv_1.

Ok, so the basic architecture is tailored, and the database configuration can be performed.

[2] Configure the database

Here is the configuration of a database as an example of an Access database. The database does not have to be placed in the Database directory. For security reasons, you can completely modify the name of the Database folder or place the database. Here I also set up a folder in place the database. As shown in the figure, I built the Leefj_db folder as a folder for the database.

Then, build an Access database named myData.mdb. I created a NewS table, including ID, title, content, and entertime fields. Figure

After the database is established, you need to modify the database connection profile: FDO_CONN.ASP, in this file, define database connection configuration information if you need to use other types of databases, modify the database connection string. Now open this file, modify the second line of code: database = "../ Database / fdo.mdb" to Database = "./ leefj_db / mydata.mdb", then browse the FDO_CONN_TEST.ASP file again to perform the database test again. If you have a message in your browser or no success, you need to adjust your code. In addition, if the browser is blank, you can view the web source code to view the error message.

There is also a need to mention, and FDO supports multi-database connections, you can change the FDO database connection, and the code for changing the database connection is given in FDO_CONN_TEST.ASP:

DIM ConnStr

CONNSTR = "Driver = {Microsoft Access Driver (* .mdb)}; dbq =" & Server.mappath ("../ Database / fdo2.mdb") Call myfdo.changebd (connStr)

Response.write ("Database connection is changed ...
")

[3] Configure FDO Server

The FDO server parameters need to be configured in different files, this is a little trouble. But not a lot, this is not difficult for friends who have a little understanding ASP. First find the fdo_init.asp file. View its 20th 7: Call myfdo.init (cmd_len, parm_len, con), the fdo's init consists of three parameters. The first parameter specifies the maximum number of command strings, and the command string is to be defined in the fdo_cmd_list.asp file. The second parameter specifies the number of maximum parameters included with the command string. These two parameters are digital, the last one is Boolean, indicating whether the database needs to be connected when the FDO is initialized.

Then you can define the commands in FDO_CMD_List.asp. You need to understand the command mode of FDO before you have a formal operation. This is a bit like a secret. About this I used to post a post in Flash8. Here I am in Luo.

We often hear something such as SQL injection, and Flash can also be disassembled to see some things inside, so it can be considered that Flash is unsafe. Just like you will write your password in JavaScript, you will not (nor) put your password in the SWF file. Then, in your SWF file, your SQL is also fatal. He seems to be more bad than SQL injection, at least those bad people can spend less work. Based on this reason, you don't leave SQL in your SWF! So what do you do? So a mapping is established in the FDO, that is, a command string corresponds to a SQL, which is less than half SQL in your SWF. For example, the command string is: Tell Me The Fact can correspond to a SQL: Select * from news. When executed, the SWF sends a number of parameters to the command string to the server, the server program looks for SQL that matches the command string and executes the parameters to SQL execution, and then returns the execution result. In this way, SQL hides other people in addition to the developers. The security of FDO is guaranteed to a certain extent.

Now let's take a look at the fdo_cmd_list.asp file, we can modify the original SQL statement, I modified the list as:

<%

Redim cmd_list (cmd_len), SQL_LIST (cmd_len)

'Add in order, if there is a command of the command, the subscript is prioritized

Cmd_list (0) = "getAllNews"

SQL_List (0) = "SELECT * from news"

CMD_List (1) = "AddNews"

SQL_LIST (1) = "Insert INTO NEWS (Title, Content) VALUES ('?', '?')"

CMD_List (2) = "UpdateNews"

SQL_LIST (2) = "Update news set content = '?', title = '?' where id =?"

CMD_List (3) = "deletenews"

SQL_LIST (3) = "DELETE from news where id =?"

%> There are two array cmd_list and SQL_LISTs the same subscript, and the question mark is the location of the parameter to be entered. The difference here is a text-type parameter or a digital parameter. Let's take a look at the example. Of course, different databases can have different SQL statements. It is necessary to mention that the FDO query command only supports a simple query that returns the record set. In addition, the mapping list has the same command string, then priority is prioritized, the next synonymous command will be ignored, the lookup method of command matches is ascending, that is, the same name command behind the array will always be ignored. So it is recommended to use different command strings. Command string is case sensitive.

In this way, we have completed the basic configuration of the server, you can concentrate the year in the client flash. Of course, the FDO server can also expand according to the needs of business logic, and then say it.

[4] debugging FDO in Flash

The FDO client object has been established in the client's code, and now describes the writing of the FDO client program. The purpose of FDO is to encapsulate data communication processes and complex server programs. This way you can concentrate on dealing with the client.

The database has been established and the news table has been established, and there is no data. So I will execute an AddNew, but first introduce the basic principles first.

The client FDO constructor includes two parameters: site URL and FDO server name. After establishing an FDO object, you need to create a Command object to bind the FDO object. This kind of Command can send a command to the FDO. The execution of the client FDO actually includes two processes, data communication, and server execution. Therefore, the implementation of FDO is time consuming, how much time does this time depend on the network and server conditions. So when an FDO object is executing, any of his commands is invalid until he performs the end. Based on such a situation, in fact, multiple FDO objects can be created on the client, while performing different commands.

So, how do you know if the fdo command is executed, the status (%) of the fdo command is executed? Three events of FDO need to be known using FDO.

· OnLoading: Call the FDO according to a certain frequency, this frequency can be set using the FDO's setFreq method, default 50ms. It includes two parameters, which is CMD: the command string currently executing; Percent: The current execution schedule can be used to drive the progress bar.

· OnData: is called after the query data arrives. In turn, the two parameters, cmd: The command string that is currently executed; RCD: a Recordset object with record set.

· OnResult: When the FDO operation fails or when the insertion, update, delete operation is performed, it is called when the result is returned. Sequently transmitted as three parameters, CMD: The current execution command string; SUC: Reflects a logical value of the results of the results, True is successful; RST: The result of the operation returned from the server.

Ok, now we can start. Create some simple graphical interfaces in the Library panel, this is not detailed, everyone looks at the library project of the FLA file in the compressed package. This is the first frame code for addNew_test.fla files and comments:

// Create an FDO object and determine the base path, which is where the FDO server is located, or the location relative to the SWF file,

// So here can also use a relative path

VAR BaseURL: String = "http:// localhost / mysite";

VAR FDO_SV1_NAME: String = "Myfdo_sv_1";

Var myfdo_1: fdo = new fdo (baseurl, fdo_sv1_name); // Set the FDO's online incident call frequency, unit MS, FDO object to create the default 100MS

Myfdo_1.setfreq (5);

// Create a Command object and bind to myfdo_1

Var cmd_1: command = new command (myfdo_1);

/ / Change the FDO Help of the Command Object

//cmd_1.setfdo(MYFDO_1);

// Create a parameter array

VAR PARM_1: array = new arrright ();

/ / According to the order in SQL, it is the news title, news content

PARM_1.PUSH ("This is an addition test of FDO.");

PARM_1.PUSH ("News Content ...");

// Command's AddNew method includes three parameters: command string, parameter list, request page

/ / About the request page In the FDO extension business logic, the default page of the AddNew method is FDO_ADDNEW.ASP,

/ / But you must specify in the parameter

// If there are too many parameters, then it is ignored.

CMD_1.AddNew ("addNews", PARM_1, "FDO_ADDNEW.ASP");

/ / Drive the progress bar in the online function

Myfdo_1.onloading = function (cmdstr, PCT)

{

EXE_BAR (PCT);

}

// onResult event tells the user to complete, whether it is successful

Myfdo_1.onResult = function (cmdstr, SUC)

{

TRACE (CMDSTR ";" SUC);

IF (SUC)

{

IF (cmdstr == "addNews")

{

Trace ("News has been added.")

INFO_TXT.TEXT = "News has been added."

}

}

}

// Progress strip drive function

Function EXE_BAR (PCT)

{

BAR_MC._WIDTH = 200 * PCT / 100;

Info_txt.text = "is adding news ... [" PCT "%" "]"

}

The execution results are as shown:

Take a look at the data in the database, because you have difficulty thinking about what is executed, look at the data in the data sheet, it is clear that the data has been added. Data table is as shown:

Below you can find out the contents of FDO_ADDNEW.ASP, in this file, there is only one way: myfdo.addnew (), there is another myfdo.log ("" server addnew return value: "& RST) This is the server debugging, it Will be output in the OUTPUT panel. This is said in the FDO expansion business logic.

Copy addNew_test.fla Rename is CTN_AddNew_Test.fla to make a continuous addition test, just add a line of cmd_1.addnew ("addNews", PARM_1, "FDO_ADDNEW.ASP") in onResult events; it is possible.

Since we have added so much data, we can now take these data, replicate addnew_test.fla, named: query_test.fla, modify the first frame of code to:

/ / Set the FDO debug mode

Debug.Indebug = True;

// Create an FDO object and determine the base path, that is, the location where the FDO server is located, or the location relative to the SWF file, //, so it can also use a relative path here.

VAR BaseURL: String = "http:// localhost / mysite";

VAR FDO_SV1_NAME: String = "Myfdo_sv_1";

Var myfdo_1: fdo = new fdo (baseurl, fdo_sv1_name);

// Set the FDO online incident call frequency, unit MS

Myfdo_1.setfreq (5);

// Create a Command object and bind to myfdo_1

Var cmd_1: command = new command (myfdo_1);

/ / Change the FDO Help of the Command Object

//cmd_1.setfdo(MYFDO_1);

// Create a parameter array

VAR PARM_1: array = new arrright ();

/ / According to the order in SQL, it is the news title, news content

PARM_1.PUSH ("This is an addition test of FDO.");

PARM_1.PUSH ("News Content ...");

// Command's AddNew method includes three parameters: command string, parameter list, request page

/ / About the request page In the FDO extension business logic, the default page of the AddNew method is FDO_ADDNEW.ASP,

/ / But you must specify in the parameter

// If there are too many parameters, then it is ignored.

CMD_1.AddNew ("addNews", PARM_1, "FDO_ADDNEW.ASP");

/ / Drive the progress bar in the online function

Myfdo_1.onloading = function (cmdstr, PCT)

{

EXE_BAR (PCT);

}

// onResult event tells the user to complete, whether it is successful

Myfdo_1.onResult = function (cmdstr, SUC)

{

TRACE (CMDSTR ";" SUC);

IF (SUC)

{

IF (cmdstr == "addNews")

{

Trace ("News has been added.")

INFO_TXT.TEXT = "News has been added."

}

}

}

// Progress strip drive function

Function EXE_BAR (PCT)

{

BAR_MC._WIDTH = 200 * PCT / 100;

Info_txt.text = "is adding news ... [" PCT "%" "]"

}

Debug output:

[debug] create fdo; fdo_servernane: myfdo_sv_1; siteURL: http:// localhost / mysite

[Debug] request_url: http://localhost/mysite/myfdo_sv_1/fdo_query.asp? fdolee

[Server_Debug] FDO has been created ...

[Server_Debug] FDO initialization completed ...

[Server_Debug] Get 132 records

[Debug] ServerData loaded ....

Data has been obtained

Recording set length: 132

Title: This is an addition test of FDO.

Here, it relates to the RECORDSET class, which stores data returned from the server, and easy access to the data through its method, which is described in detail in FDO_REF.PDF. I haven't said it here. Delete and update the operation is basically similar to insertion. Give an example everyone is optimistic. [5] FDO business logic extension

Of course, the original intention of FDO is to perform database operations, but it can also perform some extensions, which enable certain business logic to implement the needs of general websites. This extension of FDO is very important, this extension can almost replace the FDO function mentioned earlier. Below I use a specific example to demonstrate the FDO extension function.

Before you officially start, I don't think I must first learn more important functions. Typically, one page can only place an addNew, query, update, a delete function, of course, you can put them together, but this requires special skills.

The fdo.log function has been used in the previous example, using this function to output the information to the Output panel. AddNew, Query, Update, DELETE functions have a parameter that specifies whether to output the result. If true, the auto output result is returned to flash. Otherwise, the user needs to customize the output result, and fdo.setResult () can be used. That is, the run results can be given by the FDO or user-defined, but the result can only be once, whether the system or user is customized. FDo.set () can only be used in pages with AddNew, Query, Update, deletex. If you want to return a result in the FDO extension, you must use the EXEFINISH function that stops the server response and returns the result.

Below I demonstrate a user login, and execute an addition program after landing, return the result. First build a USER table in MyData.mdb, enter a record. Then create a new Flash document in myfl_prj directory, named logon.

FLA

Then, in the myfdo_sv_1 directory, create new logon.asp, getsum.asp, and logout.asp files, their code, please find it in the example.

The code is very simple, as long as the program is not wrong.

FDO has been a few days, quite tired, don't want to get it, I will send the original document to everyone, everyone is awarded to improve the other books, there is no way to ask the company, flash is just hobbies. If you have any questions, please contact me.

QQ: 190868487;

MSN: tianmazhixing@hotmail.com

Email: tianmazhixing @ hotmail.com

Leefj

3/6/2005 5:42:17 PM

转载请注明原文地址:https://www.9cbs.com/read-48868.html

New Post(0)