Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to bind to functions, objects, and arrays in Flex data binding

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to bind to functions, objects and arrays in Flex data binding, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.

Flex data binding

1. Bind to functions, objects, and arrays

(1) bind functions in response to Flex data binding events

Functions that use "unbound parameters" can be used as the source of Flex data-binding expressions. However, there must be a way to activate this function to update the destination property of the Flex data binding.

In the following example, the [Bindable] metadata tag is used to specify that Felx calls the isEnabled () function in response to the myFlagChanged event. When myFlag's setter method is called, it issues a myFlagChanged event that triggers any Flex data binding that uses the isEnabled () function as the source.

(2) use objects for Flex data binding

When working with an object, you have to consider when to define the binding to the object? Or consider when to define a binding to the properties of this object?

Bind to object

When making an object the source of an Flex data binding expression, Flex data binding occurs when the object is updated, or when the object's reference is updated, but not when a single (data) field (feild) of the object is updated.

In the following example, a subclass of the Object class is created with two properties, stringProp and intProp, but does not make them bindable:

PackagemyComponents {/ / binding/myComponents/NonBindableObject.as / / Makenoclasspropertiesbindable. PublicclassNonBindableObjectextendsObject {publicfunctionNonBindableObject () {super ();} publicvarstringProp:String= "Stringproperty"; publicvarintProp:int=52;}}

Because the two properties of this class are not bindable, Flex does not issue events to trigger Flex data binding when they are updated. Next, use this class in the Flex application, as shown in the following example:

Because the single data field (fields) of the NonBindableObject class is not made bindable, the bindings applied to the two Text controls are updated when the application starts and when the myObj is updated. When compiling the application, the compiler outputs a warning message that the Flex data binding mechanism cannot detect changes in the stringProp and intProp properties.

(3) bind to the properties of the object

To make the properties of the object bindable, create a new class definition, as shown in the following example:

PackagemyComponents {/ / binding/myComponents/BindableObject.as / / Makeallclasspropertiesbindable. [Bindable] publicclassBindableObjectextendsObject {publicfunctionBindableObject () {super ();} publicvarstringProp:String= "Stringproperty"; publicvarintProp:int=52;}}

By placing the [Bindable] metadata tag before the class definition, you can make all public variables in the class, as well as all public attributes that fully have setter and getter, bindable properties. You can then use the stringProp and intProp properties as the source for Flex data binding, as shown in the following example:

(4) use arrays in binding

When working with arrays, such as Array or ArrayCollection objects, you can use arrays as the source or destination of Flex data-binding expressions.

Note: when using an array as the binding source, you should use an array of type ArrayCollection, because the ArrayCollection class can issue events to trigger Flex data binding when the array or array elements change. For example, calls to the ArrayCollection.addItem (), ArrayCollection.addItemAt (), ArrayCollection.removeItem (), and ArrayCollection.removeItemAt () methods trigger Flex data binding.

Bind to an array

Arrays are usually bound to the dataProvider property of a Flex control. The following example shows the use of array bindings for List controls

Pieces:

This example defines an ArrayCollection object, and then sets the dataProvider property of the List control to the Flex data binding to the ArrayCollection. Flex data binding is triggered when you modify an element in an ArrayCollection object, or when you modify a reference to an ArrayCollection object.

Bind to elements in an array

You can use a single element in an array as the source of Flex data binding, as shown in the following example:

If you specify the array element as the source of the Flex data binding expression through the square bracket syntax [], Flex data binding is triggered only when the application starts, or when the array or its reference is updated. Flex data binding is not triggered when this array element is updated.

However, the myAC.getItemAt (0) in the Flex data binding expression is updated when the array element changes. Therefore, Text controls with id of text2 are updated when button1 is clicked, while Text controls with id of text1 are not updated.

When using elements in an array as the source of the Flex data binding representation, you should use the ArrayCollection.getItemAt () method in the binding expression.

Copying myAC2 to myAC when you click button2 triggers all Flex data bindings to array elements regardless of how they are implemented.

Thank you for reading this article carefully. I hope the article "how to bind to functions, objects and arrays in Flex data binding" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and follow the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report