Building Data Binding Proxies

Some types of objects and some elements in Flex applications cannot use data binding directly. For example, you cannot use data binding directly with component styles. Yet you can build an elegant solution that uses something called delegation. Delegation is what occurs when a class called a proxy wraps an object, and it passes along requests to the object it wraps. The goal of delegation may be different in different scenarios, but in this case, the goal is to provide a layer of indirection so that the data-binding-enabled proxy can accept requests in place of the object that cannot accept those requests.

A proxy class generally uses the following structure:

package {

    public class ProxyClass {

        private var _object:Object;

        public function ProxyClass(object:Object) {
            _object = object;
        }

        public function method():void {
            _object.method();
        }

    }

}

Obviously, the preceding format is overly simplified, and each proxy class may vary the format slightly. We’ll look at two specific implementations of proxy classes designed to facilitate data binding in the next two subsections. Hopefully you’ll then be able to generalize this solution so that you can apply it to similar scenarios when you need to enable data binding for an object that doesn’t natively support data binding.

Using Data Binding with a Shared Object

You cannot use data binding with shared objects. Yet you can use a proxy to enable data binding. For this example, we’ll use a very simple case in which you ...

Get Programming Flex 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.