Flash Advanced Programming Guide

Source: Internet
Author: User
Tags date bind modify advantage
Programming | advanced

This tutorial by my friends in France Zhang Xin Jay for this site, all the content by the author of my calligraphy. Website: http://www.openvue.net
BTW: The author himself from the mobile field of development, there should be more chapters, but due to the busy work, can not complete the following chapters. Some of the four sections in the tutorial are focused on the Macromedia component. If you are interested in the Macromedia component or are not sure which way to use your existing development, it might be appropriate for you.

I have always felt that Flash MX 2004 is a programmer-oriented, especially java,c# programmers, from this product you can see the development direction of Macromedia, it wants to make Flash and its supporting server-side products become the main E-commerce development platform. From the programmer's point of view of the Flash MX 2004, I am most concerned about the design model behind it, it is very good with XML integration of the presentation layer, the middle tier, and the database layer, is the design of database network applications, or E-commerce class program is a good platform for development, and provides a very powerful set of components to speed up the development process, a lot of people learn MX2004, only focus on its UI Component, which is the fur, it is the essence of the database related to several components.

Let's take a look at these very important components and get a general idea of how a typical database application should be compiled in the context of Flash MX 2004.

First, use connector (including Xmlconnector, webserviceconnector,remotingconnector) to connect to the server to get the raw data, which is generally required in XML format, With the exception of Remotingconnector, these data are obtained after entering the dataset to do a caching and data format conversion, which is. NET and Java EE inside the concept of offline database, which not only can integrate different data source data, and through caching can greatly improve efficiency. The data in the dataset can be connected to the UI component by binding, and each UI component has a binding panel that you can associate with the dataset. This way you can just write a line of code to show the data to your users: Xmlconnector.trigger () or Webservice.trigger (). The trigger command connects the server and gets the data, and the rest of the work is automatically flowing through the assembly because you have set up the binding.

So how will the data be returned to the server after the client has been modified, and then the changes are reflected in the database? Flash MX 2004 provides us with two very powerful components: Rdbmsresolver and Xupdateresolver, which can be associated with datasets, The dataset uploads the user-modified data to the two resolver in a specific format, rdbmsresolver in a format that is Macromedia in its own definition and in a very simple format, where you can find references on their website. Xupdateresolver uses the xupdate format, which is a standard format, and many XML databases use it as a database to update languages. This dataset can automatically modify the data by resolver the connection server.

You see, the whole process is actually not how to write code, just set some attributes, drag some components, the state can be fixed, is it simple?

In (a) I mentioned that Flash MX 2004 has three kinds of connector, namely Xmlconnector, Webserviceconnector,remotingconnector, If you have no remotingconnector in the flash editing environment, please go to Macromedia's website to download it.

Xmlconnector is the simplest kind of connector, server-side can be any language script, asp,php,jsp and so on can, its advantage is that the server program does not need to load additional libraries, as long as you return the content is XML. This actually makes it easier for programmers to update the original server-side script with minimal cost to match the flash rich client. The downside is that such scripts make it difficult to work with the front and back programmers because their interfaces are hidden, because if you can't communicate closely with the script developer, you don't know anything about the interface or the parameters, at least not fully, or even whether there's a backdoor. But if you are developing the foreground and developing the background differently, many other people who are accustomed to the traditional Web server script development can also get started quite quickly.

We skip Webserviceconnector, talk about Remotingconnector, this connector is based on Flash Remoting technology, a lot of friends are very enthusiastic about Remoting technology, but I am not very optimistic about it. It should be said that the design idea of remoting technology and Flash SWF file format design idea is in the same vein. They all strongly emphasize the importance of bandwidth, the content of the transmission on the Internet to be as concise as possible, compressed. Because a while ago, I once wanted to develop a J2ME version of Flash Player, so I have done a more in-depth study of SwF format, it is in the compression of quite in place, every bit as far as possible to use, remoting is also hope that through the binary byte throttling to reduce the amount of transmission to improve efficiency, So I say the starting point is the same. Remoting is essentially a kind of RPC, it and Dcom,corba,java rmi belong to a class of technology, the difference is that remoting communication protocol with HTTP, so that it has the webservice across multiple domains, across the firewall function. The efficiency of the remoting is undoubtedly higher than the webservice, but this is not our decision to choose a technology, otherwise, dcom,corba the performance of these things more powerful, but they are not widely used in the Web age. In addition, remoting is Macromedia's "private property", MM has the absolute initiative to modify and expand it, just as mm to flash format and as the drastic reform, developers are very taboo this kind of thing. Although MM exposes most of the content of the remoting AMF protocol, it is actually deliberately secretive about the transfer protocol of the media stream. A lot of people are keen to remoting to a large extent by the MM video chat demo temptation, and in fact, in order to video chat, you need to pay a heavy price, first the server must use mm software, because no third party know how and flash client Exchange media streaming, and MM Server software in accordance with connection collection of money, expensive to frighten you, with piracy is another matter. For the above reasons, I personally do not agree with the use of remoting.

Webserviceconnector I put in the last lecture. This is the most promising RPC technology at the moment, and some say WebService is a bad technology, because Microsoft's push to promote it today. I'm not so impressed by the stereotype of Microsoft that its technology is generally quite successful, like now. NET, C #, as a programmer, I can only use artwork to describe them. WebService may not be one of the most perfect technologies, but in the present, it is best suited for Web distributed computing. Today, it has become more and more mature, and in many world-class large-scale projects have been applied and tested. A technology that is used more widely, and its value goes up, it brings a significant benefit that you can not be tied to a development platform, whether server or client, such as if one day your client asked you to use SVG or Java applets to develop clients, Because you are using WebService on the server side, you can quickly leapfrog to another client technology. Don't think this is going to happen. In fact, if you've looked at SVG 2 's technical documentation, you'll find that flash is likely to be replaced by it someday, it's really powerful, and it's good for developing rich-client applications, when your server script uses remoting technology and you're miserable. Moreover, from the development environment, such as Visualstudio.net,websphere,jbuilder and so on WebService provides a very good development and debugging environment. The advantage over Xmlconnector,webserviceconnector is that it allows you to bind (Binding) its parameters (paremeters) and the result (Results) at design time (designtime). For example, you can bind your check box (checkbox) to an argument on webservice, and when the selection in the checkbox is changed, the webservice is triggered (Trigger), The WebService connection server retrieves the new dataset from the database, and then the dataset updates and other components that it states, and you see a master-detail structure of the database application is so simple to generate, The process you really want to make up is probably only 3, 4.

Summary: If the server side allows, you also have some WebService programming experience, preferably with webserviceconnector. Try to avoid using flash Remoting. The use of xmlconnector depends on the specifics of your project, such as scale, development model, whether you need to reuse a large number of existing scripts, and so on.

I am in the first few of this tutorial, I try to get everyone to see the Flash MX 2004 in the database programming aspects of the framework of things, know its why, to help you step through the analysis of each component of its function and mm why will launch these components, and not other. At the end of the tutorial I'll give you a more complicated example of how to get started.

This section, we analyze the dataset this thing, this is the MX 2004 database programming framework inside the soul component, is the core. The MM Flash 2004 comes out late, so it has the opportunity to get from Microsoft's. NET and Sun's Java EE absorb a lot of nutrients. The dataset is a very good database component after mm absorbing it.

(1) The primary function of the dataset is to partially or completely cache database mirroring in memory, the most important way to improve the performance of database applications, and a key feature of the flash application that distinguishes it from an HTML class application, and HTML is a stateless (stateless) language, When you ask for the next page, the previous state does not exist, from the server to create all the state, it's a lot of disadvantages, such as we often encounter such a situation, a website let you fill in a lot of registration information, a page, a lot of pages, you fill in half of the time, suddenly network delay, the form does not go out, how to do? Do you want to return to the previous page? No, because of security, the previous page has expired (expired), you can not enter, not back, how to do? Had to fill it out from scratch. Luckily you're just filling in your registration information, and if you're making a deal online, that's a big problem. This is also the most criticized place of HTML, Flash program does not have this problem, because as long as you do not shut it, its state has been maintained. DataSet is used to maintain the local database state is a good way, the network delay or temporary network, no problem, we wait for the network, and then synchronize with the remote database, you do not have to worry about the loss of important data.

(2) Another function of the dataset is to homogenization heterogeneous databases. For example, a large company, formerly its subsidiaries fragmented, do a set of management systems, data areas vary, from Access, mysql,sqlserver to DB2 Chiba Strange all have, the head office to unify to do a set of management system, but the cost of all database upgrades, how to do? We can go through the connectors that are mentioned in the second section, by reading raw data from different data sources into a dataset, the differences between the data sources are bridged for the client, and they are homogeneous, and you can operate on multiple databases as easily as a single database.

(3) Data format conversion, the original data in the database is often not directly displayed, the simplest example of a conversion is a date, and the date the database returns is often a string of long, accurate to millisecond or even time zone strings, which you usually have to deal with, insert into "year", "Month", "Day" In the dataset, you can specify an encoding (Encoding) for each field that will help you translate the original data into the format you want. You can also customize the encoder, such as:

if (Points < 20)
Return rookie;
Else
REUTRN veteran;

This "integral" field is converted to a more comprehensible text by the encoder.


(4) The most powerful feature of the dataset is that it automatically generates an update script. Common database applications, when users make some changes, you need to update them to the database, the process of using pseudocode may be as follows:
For (each row that is modified)
If its state is "new", execute server.addnew (...)
If its state is "deleted", execute Server.delete (...)
If its status is "updated", execute server.update (...)
DataSet otherwise, after you bind the fields in it to the UI component, make changes on the UI component, the dataset will flag on the corresponding record (records) and fields (field), and then when the user asks to save the changes to the database, The dataset packs all the modifications, assuming that you have previously bound the dataset's Datapacket property to the Xupdateresolver Datapacket property, then when the program executes to resolver. Applyupdate (), resolver will convert the dataset's modify script into a xupdate command sent to the server, the server-side program to execute the appropriate modify command, and return the results.

Have you ever noticed dataholder this component? Most of the people I want to see this tutorial have never used this stuff. I'm not saying it's a very core component like a dataset, but if you make the most of it you'll have an unexpected effect.

When I'm learning every component, I ask myself a question, why is it? MM in the development of Flash MX 2004, in fact, online already has a large number of various components for flash, MM in the development of standard components, it must be taken into account that it should have a broad scope of application, So Dataholder what is the ability to let mm into the standard components? In the previous tutorials, I've been repeating one word: binding. It allows us to write less n more code and make the program easier to maintain. But there are things you can't do with bindings, such as a text box, which is the result of a complex calculation of a few fields, at which point you typically write code to manually modify the contents of the text box. For example, if you call a traditional Web server script to read data, you might need to pass in parameters like this
http://www.openvue.net/getOrderDetails.php?OrderID=233&CustomerID=8324
Note that when you set such a connection parameter for Xmlconnector, the OrderID and CustomerID are changed during the execution of the program, not fixed, and you may need to manually write a string connection code in the program to set the correct parameters.

The above is not a general binding can be achieved, dataholder is to make these "impossible tasks" into possible. Dataholder is equivalent to a grocery store that provides dynamic bindings, and you can put anything in it to provide a data source bound to other components.

Take the two examples given above to illustrate:
(1) There is a text box called "Total", which is called "Unit Price" text box and a numericstepper called "Quantity" (This component Chinese don't know how to call, embarrassed) product, then you set a dataholder, it put three variables, a called " UnitPrice "(unit price), one is called" Quantity "(quantity) is called" Total "(sum), the" Unit Price "text box is bound to" UnitPrice ", the" number "Numericstepper bound to" Quantity ", the" total " The text box is bound to "total" and then writes a trigger that automatically calculates total when UnitPrice or quantity changes:

var calculatetotal = function ()
{
Dataholder. Total = Dataholder. UnitPrice * Dataholder. Quantity;
}
Dataholder. AddEventListener ("UnitPrice", calculatetotal);
Dataholder. AddEventListener ("Quantity", calculatetotal);

OK, now when the user enters a number in the "Unit Price" text box, or when the value in the Numericstepper is changed, the number in the "Total" text box changes. It looks pretty smart:
(2) Dynamic binding of the connection parameters, drag a dataholder onto the form, Dataholder set 3 parameters (Orderid,customerid and Orderdetailsurl), set a xmlconnector, His URL is bound to the Dataholder Orderdetailsurl, and then a trigger is written for Dataholder:

var generateurl= function ()
{
Dataholder. Orderdetailsurl= "http://www.openvue.net/getOrderDetails.php?OrderID=" + dataholder. OrderID + "&customerid=" + dataholder. CustomerID;
}
Dataholder. AddEventListener ("OrderID", GenerateURL);
Dataholder. AddEventListener ("CustomerID", GenerateURL);

What's the use of this, okay, let me add two text boxes called OrderID and CustomerID, which are bound to OrderID and CustomerID in Dataholder, respectively, Now when the user in OrderID and CustomerID input numbers, your program will automatically generate the appropriate URL to the server for query, return the corresponding OrderDetails.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.