O'Reilly logo

Programming Flex 2 by Joey Lott, Chafic Kazoun

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 that stores ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required