Do Not Copy
Copyright © 2008 Adobe Systems Incorporated 1
Flex 3: Introducing Cairngorm
August 2008
Do Not Copy
2 Copyright © 2008 Adobe Systems Incorporated
Trademarks
Adobe, the Adobe logo, Acrobat, Acrobat Reader, Adobe Type Manager, ATM, XMP, Display PostScript, Distiller,
Exchange, Frame, FrameMaker, and PostScript" are trademarks of Adobe Systems Incorporated, 1 Step RoboPDF,
ActiveEdit, ActiveTest, Authorware, Blue Sky Software, Blue Sky, Breeze, Breezo, Captivate, Central, ColdFusion,
Contribute, Database Explorer, Director, Dreamweaver, Fireworks, Flash, FlashCast, FlashHelp, Flash Lite, FlashPaper,
Flex, Flex Builder, Fontographer, FreeHand, Generator, HomeSite, JRun, MacRecorder, Adobe, MXML, RoboEngine,
RoboHelp, RoboInfo, RoboPDF, Roundtrip, Roundtrip HTML, Shockwave, SoundEdit, Studio MX, UltraDev, and
WebHelp are either registered trademarks or trademarks of Adobe Systems Incorporated and may be registered in the
United States or in other jurisdictions including internationally. Other product names, logos, designs, titles, words, or
phrases mentioned within this publication may be trademarks, service marks, or trade names of Adobe Systems
Incorporated or other entities and may be registered in certain jurisdictions including internationally.
Third-Party Information
This guide contains links to third-party websites that are not under the control of Adobe, and Adobe is not responsible
for the content on any linked site. If you access a third-party website mentioned in this guide, then you do so at your
own risk. Adobe provides these links only as a convenience, and the inclusion of the link does not imply that Adobe
endorses or accepts any responsibility for the content on those third-party sites.
Copyright © 1997-2008 Adobe Systems Incorporated
All rights reserved.
The software described in this manual is provided by Adobe Systems Incorporated under a Adobe Systems
Incorporated agreement. The software may be used only in accordance with the terms of the agreement. No part of
this publication may be reproduced, transmitted, or translated in any form or by any means, electronic, mechanical,
photocopying, manual, optical, recording, or otherwise, outside the license agreement accompanying these materials,
without the prior written permission of Adobe Systems Incorporated
Adobe Systems Incorporated claims copyright in this program and documentation as an unpublished work, revisions
of which were first licensed on the date indicated in the foregoing notice. Claim of copyright does not imply waiver of
other rights of Adobe Systems Incorporated and its subsidiaries.
Information in this manual may change without notice and does not represent a commitment on the part of Adobe
Systems Incorporated
NOTICE OF LIABILITY
The information in these training materials is distributed on as "AS IS" basis, without warranty of any kind, either
express or implied. While every precaution has been taken in the preparation of these materials, neither Adobe Systems
Incorporated nor its licensors shall have any liability to any person or entity with respect to liability, loss, or damage
caused or alleged to be caused directly or indirectly by the instructions contained in these materials or by the computer
software and hardware products described herein.
Third Edition: Aug 2008, Second Edition: June 2008, First Edition: March 2008
Adobe Systems Incorporated
345 Park Avenue
San Jose, CA 95110-2704
USA
Do Not Copy
Copyright © 2008 Adobe Systems Incorporated i
Flex 3: Introducing Cairngorm
Introducing Cairngorm
Introducing Cairngorm......................................................................................................................................................... 2
Understanding the purpose of Cairngorm..................................................................................................................... 2
Reviewing the benefits of using Cairngorm .................................................................................................................. 3
Learning about the components of Cairngorm ............................................................................................................. 3
Using Cairngorm in Flex RIAs ............................................................................................................................................ 4
Identifying roles of code ................................................................................................................................................... 4
Refactoring code to Cairngorm layers and classes........................................................................................................ 5
Reviewing benefits of Cairngorm refactoring................................................................................................................ 7
Walkthrough 1: Using Cairngorm in a project ................................................................................................................. 8
Implementing the ModelLocator......................................................................................................................................... 9
Example ModelLocator code............................................................................................................................................ 9
Using the ModelLocator ................................................................................................................................................. 10
Walkthrough 2: Building the ModelLocator ................................................................................................................... 11
Implementing the ServiceLocator ..................................................................................................................................... 13
Example ServiceLocator code ........................................................................................................................................ 13
Using the ServiceLocator................................................................................................................................................ 13
Walkthrough 3: Building the ServiceLocator.................................................................................................................. 14
Implementing Cairngorm events....................................................................................................................................... 16
Introducing the concept of Business Events................................................................................................................. 16
Example Cairngorm event code..................................................................................................................................... 16
Using a Cairngorm event................................................................................................................................................ 17
Walkthrough 4: Building Cairngorm events ................................................................................................................... 18
Implementing Commands.................................................................................................................................................. 20
Example Command code................................................................................................................................................ 20
Using the Command ....................................................................................................................................................... 21
Walkthrough 5: Building Cairngorm Commands.......................................................................................................... 22
Implementing the FrontContoller ..................................................................................................................................... 27
Example FrontController code....................................................................................................................................... 27
Using the FrontController .............................................................................................................................................. 28
Walkthrough 6: Building the FrontController................................................................................................................ 29
Implementing Delegates ..................................................................................................................................................... 31
Understanding the role of a Delegate ........................................................................................................................... 31
Implementing a Delegate ................................................................................................................................................ 32
Implementing a Responder ............................................................................................................................................ 32
Example Delegate code ................................................................................................................................................... 32
Walkthrough 7: Building a Cairngorm Delegate ............................................................................................................ 34
Using the Cairngorm components .................................................................................................................................... 36
Walkthrough 8: Modifying FStop to use Cairngorm ..................................................................................................... 37
Lab:
Tasks .................................................................................................................................................................................. 42
Create a new Cairngorm MVC Project............................................................................................................................. 43
Create a form to request a patient visitation .................................................................................................................... 45
Submit the Visitation Request............................................................................................................................................ 47
Create the Business Component to Process the Visitation Details ............................................................................... 49
Do Not Copy
ii Copyright © 2008 Adobe Systems Incorporated
Do Not Copy
Copyright © 2008 Adobe Systems Incorporated 1
Introducing Cairngorm
In this module you will preview the use of Cairngorm for Flex. You will
be introduced to concepts and components of Cairngorm; without
the accompanying in-depth theory and details. You will also convert
an existing Flex application to use Cairngorm.
Objectives
After completing this unit, you should be able to:
• Understand why Cairngorm is used in Flex development.
• Understand what are the primary components used in Cairngorm.
• Understand the use of custom events in Cairngorm.
• Understand the impacts of using Cairngorm on Flex applications.
Topics
In this unit, you will learn about the following topics:
•Introducing Cairngorm
• Using Cairngorm in Flex RIAs
• Implementing the ModelLocator
• Implementing the ServiceLocator
•Implementing Cairngorm events
•Implementing Commands
• Implementing the FrontContoller
• Implementing Delegates
• Using the Cairngorm components