O'Reilly logo

Professional Cairngorm™ by Jeremy Wischusen

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

8.3. How Do You Create One?

The location of delegate classes will vary according to the example you look at. "Flex 3: Introducing Cairngorm" (cited in earlier chapters) creates them in a business.delegates package, as shown in (Figure 8-1).

Figure 8.1. Figure 8-1

The Cairngorm store, on the other hand, creates them in the business package, as shown in (Figure 8-2).

Figure 8.2. Figure 8-2

For demonstration purposes the following example will be created directly in the business package.

Since delegates do not extend any Cairngorm classes or implement any interfaces, creating one is just like creating any other ActionScript class in Flex. The naming convention is to prefix the word delegate with something descriptive about the type of services the delegate handles (e.g., ProductDelegate). Once you have the basic class created, you simply need to add the code and function that will enable you to access the services, as in the following:

package com.cairngormexample.business { import com.adobe.cairngorm.business.ServiceLocator; import mx.rpc.AsyncToken; import mx.rpc.IResponder; import mx.rpc.http.HTTPService; public class ExampleDelegate { private var responder:IResponder; public function ExampleDelegate(responder:IResponder) { this.responder = responder; } public function loadSomeData():void{ ...

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