Flash_and_Flex_03_2009

ActionScript Development

Flex Application Architecture

by Jonnie Spratley

The role of the View in a Cairngorm application is to throw events based on user actions (such as button clicks, loading, entering of data etc.). And bind to the Model for data representation. (Either through Value Objects or other structures).

Learning about the components of Cairngorm

What you will learn... • Cairngorm Framework • M-V-C Application Architecture • Maintainable and Expandable Application

What you should know... • Basic Action Script • Basic MXML

Lets take a minute to understand the components of Cairngorm. The Cairngorm is made up of numerous classes/packages that help the developer separate all logic of the application into maintainable classes of code. But when creating these classes it is good to understand what each class is suppose to do, and how it works. Cairngorm involves a ModelLocator, a ServiceLocator, a FrontController, a Delegate, a Command, an Event; the view is made up of your components. TheModel Locator holds the data that is being used through out the application, it acts as a data storage bank for your application, any data is required to live inside of your application, should be placed inside of your applications ModelLocator. The Service Locator holds the locations of all server side services that your application will

it becomes quickly the favored framework to use. Some say that learning the Cairngorm is a huge task, it is known to have one of the hardest learning curves of the frameworks, but that is just because developers are sometimes lazy and want do not want to take the time to study something new, being outside of ones comfort zone is never a good feeling. I will explain to you that building Flex applications under the Cairngorm Framework is a piece of cake, you just have to forget all of what you have heard about it, and start fresh. In the end your application will become maintainable, re-usable, cleaner, expandable, and more reliable than ever before. Getting ready to use the Cairngorm To begin building Flex/Air applications using the Cairngorm framework, you have to download the free Cairngorm library from opensource.adobe.com. After you have downloaded the file, you create a new Flex project or use an existing one, just copy and paste the Cairngorm.swc file to the libs folder of the project. After you project as re-build, you are now ready to start using the excellent features that Cairngorm has to offer. Now it is time to start structuring your application, inside of your src folder of the application you some new folders to put your classes and component’s. Using reverse domain syntax you should create a folder structure as shown below. CairngormApplication Folder Structure, see (Figure 1).

Level of difficulty

E very Flex programmer, new and old, beginner or advanced will eventually need some type of framework when building applications of the real world. This is where Adobe’s Cairngorm M-V-C style architecture comes into play. The Cairngorm is a micro-architecture framework helping the developer separate the model, the view, and the control of the application in to small reusable classes and components that will make your application more efficient, more reliable, and extendible than ever before. When building Flex applications for the first time, you are going to put all of your applications code, data, and control inside one component, you might think that is a good idea right now at your early stages of programming but it isn’t. If you ever wanted to build a real world application you are going to have to get some type of structure, a set of guidelines, and a process in which your application flows. Frameworks play a major role when building applications that people are actually going to use, so when choosing a framework to develop with be sure to do a lot of research before just using it. The current framework of choice among Flex developers is Adobes Cairngorm Framework; with its M-V-C type architecture

Figure 1. Cairngorm Application Folder Structure

03/2009 (5)

52

Made with FlippingBook HTML5