PREFACE

A lot of software developers cut their teeth on learning COBOL, Pascal, or one of those other programming languages that have stuck around for years. I didn’t learn programming that way. I didn’t take computer science courses in school. I studied anthropology.

Being a developer was not something I imagined I would ever do for a living. I did enjoy creating graphics and building websites, though, and I supported myself through school doing just that. I found that I wanted to create some fancy animated content for a website, so I decided to spend a weekend and learn the Flash IDE. I was too cheap to buy a good book, so I spent a lot of time perusing the included documentation. Hours later, I figured out how to animate a line drawing I had made. Ecstatic, I dove through the documentation, learning more and more. What started as a weekend experiment turned into a weekly passion, as I slowly progressed from simple timeline animations into scripting.

Flash was cool. I could take text and render it as a graphic, something I couldn’t do with regular old HTML and JavaScript (DHTML). It also empowered me to build applications on the Web that were not possible at the time with DHTML. I could get data from a remote computer such as the weather forecast and display it right in my Flash content, with complete control over the look and feel. I could have a user send an email through Flash without having to refresh the web page. I could display a photo gallery on my site, rotating the photos, adding borders, and making it look like a real photo album. I was hooked.

As the language of Flash, ActionScript, matured, I grew along with it. I found that as my imagination led me to create richer experiences, the code I was required to write became more and more complex. No longer just scripting one-offs, I was learning real programming. I was pushing Flash beyond its limits and had to continually find ways of making my code more readable and maintainable. I found myself longing for a better way.

Then along came Flex. It was far from perfect in its first iteration, but I knew it was going to stick. For once, I could create my applications with simple, structured XML, which felt comfortably like the HTML I had been using all along. Flex made sense, and it helped me to build complex applications more quickly and easily than ever before.

I wasn’t the only one who felt this way. As Flex got better with each new version, more developers began adopting it. Flex grew into a powerful framework that can hold its own with the more traditional means of software development. And it still hasn’t lost its fun.

Who This Book Is For

I wrote this book as a way for anyone to get started using Flex, even those completely new to software development. This means those with no experience with the Flash IDE, web design, or programming in general can feel comfortable jumping right in and tinkering with examples. While I attempt to explain some basic concepts of programming to help the reader along, this is not exactly a how-to book for programming or software design. My aim is to get you going quickly and at a fun pace, learning Flex from the inside out. My hope is at the end of each chapter you will be itching with questions, and the following chapter will scratch that itch.

Flex is a powerful programming environment, and I’m not claiming to cover everything about it. If you find that you enjoy this technology and want to learn more, there are many great ways to continue your studies, including taking a course, studying the code of others, or finding a suitable book for advanced Flex or programming techniques. I’ll give you some fun, real-world examples to play with that you should feel free to extend.

How This Book Is Organized

This book is meant to be read cover-to-cover. Skills are taught progressively, so each chapter builds on the one preceding it. This is done using a hands-on approach, allowing you to apply key concepts by building applications progressively. You can feel comfortable being away from the computer and reading each chapter, peeking at the code and seeing how it affects the applications through extensive screenshots. Later, you can skim that chapter and add the code to your examples, practicing each concept by applying it directly. If there’s a topic you’re not interested in, feel free to skip that chapter.Just make sure you grab the necessary code from the companion website at www.greenlike.com/flex/learning, which contains the code for each chapter, so your applications will work.

What This Book Covers

My aim is to give you a step-by-step tutorial through all aspects of Flex development, from familiarizing yourself with the right tools to learning basic features of ActionScript and MXML to sharing your completed work with others. I chose topics based on what I felt empowered you to begin development without overwhelming you.

The book therefore begins with the first step, setting up your computer for Flex development. I chose to cover the most popular and (in my opinion) best option for working in Flex: Flex Builder. While it is true that you can develop Flex applications with just a text editor and a command-line interpreter, this option doesn’t provide the optimum experience for a new developer. The visual tools in Flex Builder make writing and understanding Flex code much more natural and fun.

I supply you with simple, visual examples to get you started creating Flex applications right away. I then discuss the basics of MXML and ActionScript so that you’ll have a deeper understanding of the languages and how they work together in Flex. After this introduction, I have you start building a few real-world applications that you’ll continue with throughout the book. I explain the standard set of skills for Flex, including the ability to move data around and structure your applications. I talk in depth about different ways of making a dynamic user interface and accepting user input. Once these basic skills are in place, I give you plenty of time to have fun with your applications, going over the “flashy” stuff like animations and styles.

This is a beginner’s book, and Flex is a very powerful and fully featured development tool, so there are some advanced subjects that I chose not to cover. When I think it will help, I refer you to learn more about such related topics.

Companion Website

All the exercises included in this book are available for download from the book’s companion website, www.greenlike.com/flex/learning. While I will frequently show sections of code in the book, you may find it easier to download the Flex projects and copy and paste the appropriate code into your examples. This will prevent typos from ruining your fun. However, I do hope that you follow along with the examples, because I’ve tried to create examples that you’ll build upon from chapter to chapter.

Typographical Conventions Used in This Book

The following typographical conventions are used in this book:

Plain text

Indicates menu titles, menu options, menu buttons, and keyboard modifiers (such as Alt and Command).

Italic

Indicates new terms, URLs, email addresses, filenames, file extensions, and pathnames.

Constant width

Indicates ActionScript code, text output from executing scripts, XML tags, HTML tags, and the contents of files.

Constant width bold

Shows commands or other text that should be typed by the user.

Constant width italic

Shows text that should be replaced with user-supplied values.

Note

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

Warning

This icon indicates a warning or caution.

Using the Code Examples

This book is here to help you get your job done. In general, you can 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: Learning Flex 3 by Alaric Cole. Copyright 2008 O’Reilly Media, Inc., 978-0-596-51732-8.

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

We’d Like to Hear from You

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:

www.oreilly.com/catalog/9780596517328

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:

www.oreilly.com

Acknowledgments

Like a good film, a good technical book is a product of the combined efforts of lots of dedicated people. While I’m the only author for this book, I couldn’t have done it alone.

I would like to personally thank the following:

Micah Laaker for the initial push and for all the insider tips.

Eli Robison for continued encouragement and for being a real friend.

Sharif Zawaideh at http://globalimagesllc.com for his stunning photos that make the book shine.

Hepp Maccoy for the helpful feedback early on.

Justin Kelly for his reality checks (even though one of them bounced).

Michael Hoch for his un-boss-like understanding and patience when I came to work dreary from all-night writing marathons.

Allen Rabinovich for going above and beyond the title of tech editor.

Lydia Schembri for her ornery motivation, positive energy, and grace.

Mom and Dad for being a true mother and father, respectively.

Robyn Thomas, Steve Weiss, Michele Filshie, Dennis Fitzgerald, David Van Ness, and the rest of the O’Reilly team for their continued support. The quality of this book is a direct result of their guidance and hard work.

The Adobe Flex team for another solid release.

Get Learning Flex 3 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.