Flex 3 is a powerful framework that provides enterprise-level components for the Flash Player platform in a markup language format recognizable to anyone with HTML or XML development experience. The Flex Framework provides components for visual layout, visual effects, data grids, server communication, charts, and much more.
To put a blunt point on it, the Flex Framework is massive, and any book attempting to cover the entire Framework in any depth will without question fail in some respect or another. With this in mind, we’ve made an attempt to cover the topics that most vex developers working with Flex 3—in a way that can illuminate how the Framework is structured as well as help solve common problems. The official Flex documentation is quite good at explaining in depth how particular methods or classes behave, so instead we explain how to tackle common tasks within the Flex Framework, how to get different components to work together, and how Flex can partner with other technologies to create Rich Internet Applications and more. With the help of Adobe AIR, for example, you can use the tools of Flex and the Flash Player to create deployable desktop applications. This complements the expansion of open source and commercial tools for Java, .NET, and PHP development, among others, making Flex a powerful solution for an ever wider range of development needs and challenges.
The Flex framework is such a huge topic and we had so many recipes and so much information to cover that we simply couldn’t fit it all into the printed book. Four chapters totaling 76 pages are available to you online that cover working with XML, the Charting components, working with SharedObjects, and Development Strategies for creating Flex applications. Go to www.oreilly.com/catalog/9780596529857 to read this bonus material.
Flex 3 Cookbook is for developers who want to understand the Flex Framework more thoroughly or who need a reference to consult to solve particular problems. As such, this book assumes that you have some previous experience with Flex and ActionScript 3. The code samples and explanations likewise are geared toward intermediate developers familiar with the relationship between MXML and ActionScript, at least some of the components that make up the Flex Framework, and basic strategies of Flex development.
We have made a very deliberate decision to ensure that all the recipes contain usable components and functional, tested implementations of those components. This was not done with the intention of swelling the book unreasonably, but to ensure that this book is suitable for intermediate and advanced developers who simply need to see a small code snippet to understand a technique, as well as readers who are still learning how the Flex Framework can be used and the best practices for working with it.
If you need to learn the Flex Framework from scratch, consult Programming Flex 3 by Joey Lott and Chafic Kazoun (O’Reilly, 2008) to gain an understanding of the core concepts of Flex development before reading any further here. With a grounding in Flex and ActionScript basics, you’ll be better prepared to take advantage of the techniques in this book. If you need a refresher course in ActionScript development, try ActionScript 3.0 Cookbook by Joey Lott, Darron Schall, and Keith Peters (O’Reilly, 2006) for techniques focused on core Flash ActionScript programming. Although Flex 3 Cookbook covers some areas of overlap between the Flex Framework and core Flash ActionScript classes, this book is very much focused on Flex development.
As its name implies, Flex 3 Cookbook is stuffed full with recipes for techniques that will help you get more from your Flex applications. To help you find the solutions you need faster, the recipes are organized by theme. Generally the recipes progress from simpler topics to the more complex throughout each chapter.
This book was not intended to be read from cover to cover but rather to be used as a reference for a particular problem, or to provide some insight into a particular aspect of the Flex Framework. The recipes also include complete component implementations to show you how to completely implement the concept discussed. You should be able to use the demonstrated code in your own applications or at the very minimum adapt relevant portions of the code to your needs.
The following typographical conventions are used in this book:
Indicates new terms, URLs, email addresses, filenames, and file extensions.
Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.
Constant width bold
Shows commands or other text that should be typed literally by the user.
Constant width italic
Shows text that should be replaced with user-supplied values or by values determined by context.
This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Flex 3 Cookbook by Joshua Noble and Todd Anderson. Copyright 2008 Joshua Noble and Todd Anderson, 978-0-596-5298-57.”
If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at email@example.com.
Think of this book like a friend and a counselor. Don’t put it on a shelf. Keep it on your desk where you can consult it often. When you are uncertain as to how something works or how to approach a specific programming issue pick up the book and flip to the relevant recipe(s). We have written this book in a format so that you can get answers to specific questions quickly. And since it’s a book you don’t ever have to worry that it will laugh at you for asking questions. No question is too big or too small.
Although you can read the book from cover to cover, we encourage you to use this book when you need an answer. Rather than teaching you a bunch of theory, this book intends to help you solve problems and accomplish tasks. This book is meant for field work, not the research lab.
Looking for the right ingredients to solve a programming problem? Look no further than O’Reilly Cookbooks. Each cookbook contains hundreds of programming recipes, and includes hundreds of scripts, programs, and command sequences you can use to solve specific problems.
The recipes you’ll find in an O’Reilly Cookbook follow a simple formula:
Each Problem addressed in an O’Reilly Cookbook is clearly stated, specific, and practical.
The Solution is easy to understand and implement.
The Discussion clarifies and explains the context of the Problem and the Solution. It also contains sample code to show you how to get the job done. Best of all, all of the sample code you see in an O’Reilly Cookbook can be downloaded from the book’s web site, at http://www.oreilly.com/catalog/9780596529857.
The See Also section directs you to additional information related to the topic covered in the recipe. You’ll find pointers to other recipes in the book, to other books (including non-O’Reilly titles), web sites, and more.
To learn more about the O’Reilly Cookbook series, or to find other Cookbooks that are up your alley, visit their web site at http://cookbooks.oreilly.com.
When you see a Safari® Enabled icon on the cover of your favorite technology book, that means the book is available online through the O’Reilly Network Safari Bookshelf.
Safari offers a solution that’s better than e-books. It’s a virtual library that lets you easily search thousands of top tech books, cut and paste code samples, download chapters, and find quick answers when you need the most accurate, current information. Try it for free at http://safari.oreilly.com.
Please address comments and questions concerning this book to the publisher:
|O’Reilly Media, Inc.|
|1005 Gravenstein Highway North|
|Sebastopol, CA 95472|
|800-998-9938 (in the United States or Canada)|
|707-829-0515 (international or local)|
|707 829-0104 (fax)|
We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at:
To comment or ask technical questions about this book, send email to:
For more information about our books, conferences, Resource Centers, and the O’Reilly Network, see our web site at:
This book truly does represent a product of the Flex community. Thanks belong to many developers and the community relations managers at Adobe, Amy Wong, Matt Chotin, Ely Greenfield, and Alex Harui in particular, as well as to the developers who work with Adobe products and contributed to the Flex Cookbook site or blogged about what they discovered. Without all of them, this book would not be conceivable.
Many, many thanks are due to the many people at O’Reilly who made this book possible. Many special thanks go to Steve Weiss, Linda Laflamme, and Michele Filshie for their hard work, flexibility, and patience throughout the writing and editing of this book.
The quality of the technical information within this book is not simply due to the knowledge of the many authors of this book. The technical reviewers for this book, Mark Walters (http://www.digitalflipbook.com/), Alfio Raymond, and Jen Blackledge, not only provided help debugging, correcting, and clarifying the code for this book, but also provided fantastic insight into ways to clarify explanations, structure chapters, alter recipes, and help the readers’ understanding.
First and foremost, I need to thank Joey Lott for so graciously helping me get the opportunity to write this book and the one before this. I wouldn’t be writing this without his encouragement and advocacy for my abilities, and I can’t thank him enough for believing in me enough to recommend me for this book. The same goes to Steve Weiss, who took a chance on a somewhat unknown author and made it possible for the book to blossom to its current size. To my co-authors, Todd Anderson and Abey George, and also the people at Cynergy Systems, Andrew Trice, Craig Drabnik, Keun Lee, and Ryan Miller, for stepping in and helping when I needed them, to all of them I owe a huge debt. I also need to thank Daniel Rinehart, who did such a fantastic job writing the recipes that make up “Unit Testing with FlexUnit,” simply to educate and share with the Flex community, completely unprompted. The same goes for everyone who participated in the Adobe Cookbook site and on forums like FlexCoders, making a vibrant, helpful community that helps us all.
I’d also like to thank my friends whom I’ve known from jobs and from life, for providing me with so much help, advice, support, and humor. Finally, I’d like to thank my family, and in particular my mother, for always providing me with encouragement and wisdom.
I would first like to thank Josh Noble for asking me to participate in this book and for providing knowledge, patience, and humor throughout. I’d also like to thank Joey Lott for his huge encouragement and belief in people’s abilities. I’d like to thank my friends and the Flash community for offering advice, a few laughs, and expertise. And finally to my family, I cannot thank you enough for the huge love and support.
Joshua Noble, a development consultant based in New York City, is the co-author of ActionScript 3.0 Bible (Wiley, 2007). He has worked with Flex and Flash on a wide range of web applications on a variety of platforms over the past six years as well as working with PHP, Ruby, Erlang, and C#. In his free time, he enjoys playing with C++ and OpenCV as well as using microcontrollers and sensors to create reactive environments. His website is http://thefactoryfactory.com.
Todd Anderson is a senior software engineer for Infrared5. With over five years of developing for the Flash platform in the areas of RIA and game development, Todd has delivered web and desktop solutions for the publishing and entertainment industries with companies including McGraw-Hill, Thomson, Motorola, and Condé Nast Publications. Currently residing in the Boston area, when he’s not programming he likes to get back to his fine arts roots and build things on paper. Anderson runs http://www.custardbelly.com/blog, focusing on development of the Flash platform.
Abey George is a software engineer with expertise in architecting and developing Rich Internet Applications (RIAs). He has implemented a wide range of RIA solutions for both web and enterprise applications by using a combination of Flex, Flash, and C#. He holds an MS from Texas A&M University and has over six years of professional experience in the field of software engineering. Interested in effectively leveraging RIAs in the enterprise, Abey is currently a principal software engineer at Fidelity Investments and has worked previously for Yahoo, Keane, and Mindseye.
Daniel Rinehart is a software architect at Allurent, where he is helping to build a new generation of innovative online shopping experiences using Flex. He has worked in the field of software development as an engineer and architect for the past eight years. Prior to joining Allurent, Daniel worked at Ruckus Network, Towers Perrin, and Bit Group, where his clients included Cisco and Dell Financial Services. He can be reached on the Web at http://danielr.neophi.com/.
Keun Lee is a technical lead for Cynergy Systems. He specializes in technologies such as Adobe Flex and the Microsoft Windows Presentation Foundation. He has an extensive background in business intelligence, B2B application architecture, and Rich Internet Application development. In his spare time, he enjoys playing and composing music and in general building cool things with the abundance of available technology at his disposal.
Craig Drabik has been building web applications since 2000 by using DHTML, ColdFusion, Flash, and Flex. He currently works for Cynergy Systems, leading the implementation of customer Flex projects.
Ryan Taylor is an award-winning artist and programmer specializing in object-oriented Flash development and static/motion design. He currently serves as a senior developer on the Multimedia Platforms Group at Schematic. Ryan frequently speaks at industry events and shares all of his thoughts, experiments, and open source contributions on his blog at http://www.boostworthy.com/blog.
Marco Casario founded Comtaste (http://www.comtaste.com), a company dedicated to exploring new frontiers in Rich Internet Applications and the convergence of the Web and the world of mobile devices. He is the author of the Flex Solutions: Essential Techniques for Flex 2 and Flex 3 Developers (Friends of ED, 2007) and Advanced AIR Applications (Friends of ED, 2008). Marco often speaks at such conferences as Adobe MAX, O’Reilly Web 2.0 Summit, FITC, AJAXWorld Conference & Expo, 360Flex, From A to Web, AdobeLive, and many others, details of which are on his blog at http://casario.blogs.com.
Andrei Ionescu is a Romanian web developer who likes new technologies and making them interact. He enjoys making and implementing Rich Internet Applications in the best possible way and bringing to life all kinds of web applications. He is author of the Flex blog http://www.flexer.info, and his company site is http://www.designit.ro.
Ryan Miller has been developing web applications for more than seven years. Working for companies big and small, he’s managed to get his hands all kinds of dirty over the years. Currently he works out of his Beaverton, Oregon home for Cynergy Systems doing Flex development, all day, every day, and loving every minute.