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{ ...

Get Professional Cairngorm™ 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.