Flash MX 2004 Data binding (2)

Source: Internet
Author: User
Tags date numeric value rar zip domain domain name
Data

Previous article: http://www.webjx.com/htmldata/2005-03-09/1110356957.html

Formatting

All right! We already know how to get a value from a component and put that value in another component. But this is usually not enough. Sometimes we need the data in the component to be presented in different ways, and sometimes it takes two components to show different data.
We use formatting to achieve this goal. There are several built-in formatting tools you can choose from, while you can also customize the format with the AS2 class. You can choose to select the formatting tools and select them from the list at the time of the select binding. Choosing a custom format requires you to use your own class.

We start with a built-in format, like

Boolean (boolean value)

Perhaps the simplest form of built-in formatting. It is just a Boolean value (or True or false) and outputs a string. You can select the value to describe by true or false--in formatting options.

Bool_formatter.fla

Compose string (array string)

Converts the field of an object to form a single string. You can combine any number of fields, or you can insert other characters. Create a string template, select the Format option, and type a string. You can also place any text here, but any content in the "<>" notation will be treated as a field. If objects have child objects (such as XML), then you can use them--point syntax to get their paths. Examples of string templates are as follows:

Compose_formatter.fla

Date (date)
Convert dates to strings, simple templates like "mm/dd/yyyy". The format allowed is "M" (month), "D" (date), "Y" (year), "H" (Hour), "N" (minutes), and "S" (seconds). You can use the Formatting tool to reverse format the string as a date, but for some reason this is only used in two-way binding.

Date_formatter.fla

number (digit)
Very simple formatting options. You can display decimal digits.

Number_formatter.fla

rearrange Fields (rearranged field)

Allows you to coordinate domains, such as the domain name of a component's data source and the domain name of another component's data source. A field appears as a list in pairs of formatting options. For example, a simple string: "Label=name;data=colour;otherfield=yetanotherfield". This is useful for displaying data, such as the following Drop-down list boxes and list boxes displaying data, and changing the component label field properties to format the fields you want to display as labels with the rearranged fields. In this example, some XML files have been loaded and used to migrate to the Drop-down list box and its fields (rearranged), so the name attribute is used as a label.

Rearrange_formatter.fla

To customize the format, you need to define a very simple class that has two methods: formatted and unformatted, provides a basis for each type, and can return anything. In this example, the class formats the number as a pound sign:

Code: Class used to convert numbers to sterling currency and back again
Class Sterlingformatter {

Turns a number into a string
function Format (data:number): string{
var currency:string;
var pounds:number = Math.floor (data);
var pence:number = Math.Round ((data-pounds) *100);
var poundsstr:string = String (pounds);
var pencestr:string;
if (pence<10) {
Pencestr = "0" + String (pence);
}else{
Pencestr = String (pence);
}
Currency = "£" + pounds + "." + pencestr;
return currency;
}

Removes sterling format and returns a number
function Unformat (data:string): number {
var str:string = data.substr (1);
var num:number = parsefloat (str);
return num;
}
}

Type a numeric value on the left to see what formatting the side will produce

limitation, precaution and practice

The data binding at authoring time is based on the MC Path, which brings some limitations and dangers. The main problem is that when you create a binding between two components, the instances of these two components must be uniquely identified, and this also depends on their path. Therefore, if you change the path of a component and then provide the binding, you will lose the binding. Although I've noticed that you can safely change the name of the component instance without changing their bindings.

Typically, at run time, a component can resolve a binding problem from an absolute path. But if you provide a binding to an MC that does not exist on the stage, the binding will select the "farthest" from the MC that can be identified. The problem is that the same MC will be interpreted differently if the MC is edited on the stage or edited in the library. To avoid confusion, conflict, and loss of completed content, you need to follow the following guidelines:

1, do not use the binding to such MC: that is, in the creation process added to the stage, and the use of dynamic additional;
2. Do not provide data binding to the symbols selected on the stage that have been edited. Use "local edit" to protect the internal structure of the MC;
3. Carefully plan your application before adding bindings, if the program is complex. When you realize that all the bindings are lost because all the components are nested in an MC, it will be an impossible mistake to make.
4, if you want to load the application dynamically into other movies, use _level to replace the target of the movie.

In general, the above tutorial simply guides you through the creation of the simplest application with a form, and you add a lot of scenarios and components. Make the scene run and then join the data binding. The last point to show (a bit annoying but it is also really a sharp problem, in many cases will occur).

If you've seen the source file, you'll see that I've added some arrow symbols to the boot layer. This is irrelevant for simple bindings, but some complex system bindings are hard to track, so I advocate doing this by using the original "documentation" to illustrate what you're doing. It is more difficult to describe your binding in words, but the diagram can express the meaning of the binding. If something needs to be described in more detail, it is helpful to annotate it with text at a guide layer. These arrows are not just symbols, it is important to retain some hint of what is going to happen.

End
Data binding is an important topic in MX2004, and there are many aspects that I haven't covered, including runtime APIs and identity authentication. This is a topic in itself, but it's well worth mastering-it covers a lot of functionality and you can save a lot of time and effort without rebuilding it.

However, you may not select a data-binding panel to develop an enterprise-class application, and you may use the runtime APIs directly. But the data-binding panel can quickly provide a prototype or small application because they provide a very simple way to build complex data interactions. Identity authentication and formatting can be implemented through AS2 to achieve extensible functionality, there is no limit.

Attached source file Download:
Fmx2004-databinding.zip
Fmx2004-databinding1.zip
Fmx2004-databinding2-1.rar
Fmx2004-databinding2-2.rar



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.