Preface

Flex 4 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 4. Along the way, we’ll illuminate how the Framework is structured, as well as helping developers familiar with earlier versions of Flex to start working with the new components and styling functionality in Flex 4. The official Flex documentation is quite good at explaining in depth how particular methods or classes behave, so our focus instead is on 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 (RIA) 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.

Who This Book Is For

Flex 4 Cookbook is for developers who want to understand the Flex Framework more thoroughly, who need a reference to consult to solve particular problems, or who are looking to understand new additions to the Flex Framework. As such, this book assumes that you have some previous experience with Flex and ActionScript 3. The code samples and explanations are geared toward intermediate developers familiar with the relationship between MXML and ActionScript, with at least some of the components that make up the Flex Framework, and with basic Flex development strategies.

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.

Who This Book Is Not For

If you need to learn the Flex Framework from scratch, consult Programming Flex 3 by Joey Lott and Chafic Kazoun (O’Reilly) or Hello! Flex by Peter Armstrong (Manning) 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 or are looking to learn techniques focused on core Flash ActionScript programming, try ActionScript 3.0 Cookbook by Joey Lott, Darron Schall, and Keith Peters (O’Reilly). Although Flex 4 Cookbook covers some areas of overlap between the Flex Framework and core Flash ActionScript classes, this book is very much focused on Flex development.

How This Book Is Organized

As its name implies, Flex 4 Cookbook is stuffed full with recipes intended to teach you 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, within each chapter, the recipes progress from simpler to more complex topics.

This book was not intended to be read from cover to cover, but rather to be used as a reference for particular problems, and to provide insight into particular aspects of the Flex Framework. The recipes also include complete component implementations to show you how to implement the concepts that are 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.

Conventions Used in This Book

The following typographical conventions are used in this book:

Italic

Indicates new terms, URLs, filenames, and file extensions. Also used for emphasis.

Constant width

Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, tags and components, data types, environment variables, statements, and keywords.

Constant width bold

Shows commands or other text that should be typed literally by the user. Also used for emphasis in code listings.

Constant width italic

Shows text that should be replaced with user-supplied values or by values determined by context.

Note

This icon signifies a tip, suggestion, or general note.

Warning

This icon indicates a warning or caution.

Using Code Examples

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 4 Cookbook by Joshua Noble, Todd Anderson, Garth Braithwaite, Marco Casario, and Rich Tretola. Copyright 2010 O’Reilly Media, Inc., 978-0-596-80561-6.”

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

How to Use This Book

Think of this book as 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 fieldwork, not the research lab.

O’Reilly Cookbooks

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:

Problem

Each Problem addressed in an O’Reilly Cookbook is clearly stated, specific, and practical.

Solution

The Solution is easy to understand and implement.

Discussion

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 this O’Reilly Cookbook can be downloaded from the book’s website, at http://www.oreilly.com/catalog/9780596805616.

See Also

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), websites, and more.

To learn more about the O’Reilly Cookbook series, or to find other Cookbooks that are up your alley, visit the website at http://cookbooks.oreilly.com.

Safari® Books Online

Note

Safari Books Online is an on-demand digital library that lets you easily search over 7,500 technology and creative reference books and videos to find the answers you need quickly.

With a subscription, you can read any page and watch any video from our library online. Read books on your cell phone and mobile devices. Access new titles before they are available for print, get exclusive access to manuscripts in development, and post feedback for the authors. Copy and paste code samples, organize your favorites, download chapters, bookmark key sections, create notes, print out pages, and benefit from tons of other time-saving features.

O’Reilly Media has uploaded this book to the Safari Books Online service. To have full digital access to this book and others on similar topics from O’Reilly and other publishers, sign up for free at http://my.safaribooksonline.com.

How to Contact Us

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:

http://www.oreilly.com/catalog/9780596805616

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 website at:

http://www.oreilly.com

Acknowledgments

This book truly does represent a product of the Flex community. Thanks are due to many developers and the community relations managers at Adobe, to Matt Chotin, Ely Greenfield, and Alex Harui in particular, as well as to the developers who work with Adobe products, and have contributed to the Flex Cookbook site or blogged about what they’ve discovered. Without all of them, this book would not have been conceivable.

Many, many thanks are also due to the many people at O’Reilly who made this book possible. Many special thanks go to Steve Weiss, Mary Treseler, 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 its many authors. The technical reviewers for this book—Jodie O’Rourke, Ed Mansouri, Kevin Suttle, Mykola Bilokonsky, Chuck Freedman, Russ Ferguson, and Sean Moore—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.

From Joshua

First and foremost, I need to thank Joey Lott and Steve Weiss for so graciously helping me get the opportunity to write my first book so many years ago and for all the wonderful opportunities that has provided me since. To my co-authors, Todd Anderson and Garth Braithwaite, and also the writers of the Adobe AIR 1.5 Cookbook, Rich Tretola and Marco Casario, this book would have been absolutely impossible without you. The same goes for everyone who has 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 brother, my father, and in particular my mother, for always providing me with encouragement, support, wisdom, and humor.

From Todd

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.

From Rich

I would like to thank my wife and best friend Kim, who has always been there for me and has been supportive of my many ventures. I would also like to thank my daughters Skye, Coral, and Trinity. I love you all very much! Also, thanks for the hard work of all of my co-authors.

From Garth

I was only able to be part of this project because of Steve Weiss, Josh Noble, and Todd Anderson; I thank them for the opportunity. Additionally, I thank my father for my love of programming, and Dr. Paul Merril for teaching the courses that led to my profession. I’d like to thank my RIA Radio co-hosts for being a part of my weekly fanboy fest: Leif Wells, Zach Stepek, and Stacey Mulcahy. I also need to thank the Adobe community, and particularly Rachel Luxemburg, Edward Sullivan, and Greg Hamer, for their encouragement. Finally, I am nothing without the support of my wife, daughters, mom, and family.

From Marco

Special thanks to my fantastic co-authors for the quality and the amount of work they put into this book. I would also like to thank my colleagues at Comtaste—without their hard work on our internal projects, I would never have achieved what I have done. My sincere and deep thanks to the crew at O’Reilly for their patience, persistent assistance, and professionalism throughout the entire process.

I welcome conversation and comment on this book—email me at , or leave a comment on my blogs at http://blog.comtaste.com or http://casario.blogs.com.

Get Flex 4 Cookbook 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.