Preface

“Gentlemen, I am tormented by questions; answer them for me.”

Fyodor Dostoyevsky

Something motivated you to pick up this book. Perhaps you want to start programming, but you’re not sure where to begin. If so, you’re in the right place, because Adobe Flex allows you to develop programs that run on the Web as well as the desktop. Or maybe you know a little about web development, but you’d like to start creating Web 2.0 applications? Because Flex applications run in Flash Player, Flex is a great framework for creating graphically rich websites, media players, mapping applications, and the like. Or better yet, maybe you already have some basic programming experience and you just want to learn a new language. If you fall into any of these categories, this book should meet your expectations.

Perhaps you’re thinking, “What can I do with Flex, and where can it take me?” The short answer is this: “You can do a lot with Flex, and you’d be surprised where it might take you.” At the very least you can make simple widgets for websites or for your desktop computer. But if you’re willing to pursue the next level, which means learning a middleware and database combination, you can develop applications to handle a variety of Internet applications and software needs (Figure 1). Also, Adobe Flex is seeing increasing demand as a framework for enterprise applications, so if you’re inclined to stay the course, Flex development could become a career (Figure 2).

Note

Middleware and database combinations could include ASP.NET and Microsoft’s SQL Server, PHP and MySQL, ColdFusion and Oracle, and many others. Plus, these combinations aren’t inseparable from one another. Many mixtures work quite well.

The authors of this book didn’t learn to program exclusively in college or by following a direct path. Indeed, our own beginnings inspired this text and its objective of helping new developers learn the craft. As undergraduates, one of us studied anthropology; the other studied history. We first met in middle school, but we started programming for entirely separate reasons. Curiously, almost a dozen years elapsed before we realized how seriously we each pursued programming and software development.

Pure curiosity motivated Alaric to learn to program; to him, computers were just one more thing to master and bend to his will. His first scripts were written as practical jokes to tease his friends. Discovering he had a knack for programming, he eventually dove into advanced projects that helped pay his way through school. Having mastered ActionScript early in his career, Alaric continues to consult on the newest projects using Flash and Flex.

Elijah’s path to Flex followed a much different approach. He initially learned basic web design while working in tech support for Internet providers Arkansas.Net and Socket Internet. Later, in graduate school, he focused on geographic information systems (GIS) programming and ultimately created a hydrology analysis toolkit for Missouri State University’s Ozarks Environmental and Water Resources Institute (OEWRI). Elijah’s university experience taught him the development life cycle, and he eventually landed at VillaGIS, Inc., where he participates in Internet mapping and enterprise application development using Adobe Flex and AIR.

So, where do our experiences merge with yours? It’s simple: we think Flex is cool, and we hope you will too. We know you can learn it, and we believe we can help you. And by teaching you what we’ve already learned, we’ll help you get started quickly and avoid some common pitfalls. Our mutual goal is helping you acquire the precious sense of accomplishment that is so essential for new developers.

Flex application showcase ()
Figure 1. Flex application showcase (http://flex.org/showcase-all)
Searching “flex” at Dice.com ()
Figure 2. Searching “flex” at Dice.com (http://www.dice.com)

Who This Book Is For

We wrote this book as a guide for anyone learning Flex, but we focused on those completely new to software development. Even if you have no experience with the Flash IDE, web design, or programming in general, we’ll make you feel comfortable enough to jump in and tinker with our examples. We will explain basic programming concepts along the way, but this is not a recipe book for advanced projects. Our aim is helping new programmers get started with Flex. Our hope is that each chapter will leave you itching with questions, and that the following chapter will scratch that itch. If we succeed, perhaps you’ll step deeper into programming by taking an interest in advanced user interface (UI) development or distributed systems integration.

Note

Although this is admittedly an introductory text, we’ll give you a taste of advanced development in Chapter 16 by exposing you to a simple Flash-PHP-MySQL implementation. It should be enough exposure to help you segue into more specific studies of either PHP and/or MySQL server technologies.

Flex is a powerful programming environment, but we cover only the nuts and bolts. If you enjoy this technology and want to learn more, there are additional ways to further your studies, including several great books that discuss advanced Flex and ActionScript techniques, as well as blogs, tutorials, and code samples submitted by unsung heroes in the user community.

So, if you’re new to programming, we’ll get you started with some fun examples, and as always, you’re encouraged to extend these examples and make them your own.

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. We’ll take a hands-on approach, guiding you through key concepts by building applications in stages.

You’ll feel comfortable reading each chapter away from your computer, peeking at the code and considering how it affects the applications. Then, once you’ve absorbed the concept, you can revisit the chapter and construct the example, reinforcing the subject covered by the exercise. Of course, if a topic doesn’t interest you, just skip that chapter.

Companion Website

You can download each chapter’s source code from the book’s companion website, http://www.learningflex4.com. So if you skip ahead, experiment, or if your code becomes out of sync with examples in another chapter, just visit the companion website and download code for the appropriate chapter.

We also created a WordPress blog to serve as a forum, and we’ll likely post new examples there from time to time; find it at http://learningflex4.wordpress.com.

What This Book Covers

Our aim is to give you a step-by-step tutorial through the basic aspects of Flex development. We chose topics designed to empower you and get you started without overwhelming you. We’ll familiarize you with the best tool for the job, Adobe’s Flash Builder. Then, we’ll introduce you to the three languages composing the Flex 4 framework: MXML, ActionScript, and FXG. Finally, once you’ve learned how to create applications, we’ll teach you how to deploy them and share them with others.

We’ll have you start by installing Adobe’s Flash Builder 4, which is widely considered the best platform for Flex application development. Because Flash Builder is free to try for 60 days, we strongly recommend using it while you learn Flex. Later, once you’re comfortable with the framework, you can always revisit your options and experiment with alternative development tools.

Note

Just an FYI, Adobe offers Flash Builder for free if you meet any of these criteria:

  • Student, faculty, or staff of an eligible educational institution

  • Unemployed software developer affected by a recessed economy

  • Event attendee possessing a special promo code

This is a very cool campaign. No gimmicks. Check it out for yourself at https://freeriatools.adobe.com/.

After discussing the Flash Builder authoring software, we’ll transition into application development by creating the obligatory “Hello World” example. Then, we’ll discuss the basics of MXML and ActionScript so you’ll understand how these languages work together in Flex. While you cut your teeth on the Flex languages, we’ll walk you through building three applications, and in the process you’ll learn how to manage event-driven interaction, create dynamic user interfaces, and cycle data through your applications. Of course we’ll also discuss “flashy” stuff, including effects, animations, and styles. Toward the end of the book we’ll demonstrate a Flex-PHP-MySQL integration, and the final lesson will demonstrate how to deploy projects to the Web or the desktop.

Note

It’s customary to create a “Hello World” example when learning a new programming language. As Scott Rosenberg describes them in Dreaming in Code (Crown Publishers), “‘Hello World’ programs are useless but cheerful exercises in ventriloquism; they encourage beginners and speak to the optimist in every programmer. “If I can get it to talk to me, I can get it to do anything!”

As this is a beginners’ book, we will occasionally refer you to other sources we consider helpful with regard to deeper subjects. In fact, if you flip to Chapter 18, you’ll find a reasonably dense list of third-party code libraries, books, blog posts, and links to Adobe documentation, all of which might prove useful in your quest.

Typographical Conventions Used in This Book

The following typographical conventions are used in this book:

Plain text

This style is used to describe menu navigation, such as Window→Variables, and keyboard shortcuts, such as Ctrl-C (Windows) or Command-C (Mac OS).

Italic

This styling calls attention to new terms and concepts, much like any instructional text, and is used for emphasis; it’s also used to represent filenames and filesystem paths.

Constant width

Constant width formatting introduces code, either inline among body text or as a block of example code:

<s:Button label="Submit"/>
Constant width bold

This styling calls your attention to additions or changes within a block of code; it appears most often as a complex example grows:

<s:Button label="Edit"/>
Constant width italic

This style indicates replacement by specific, user-supplied values.

Note

This styling denotes tips, suggestions, or general notes.

Warning

This styling signals warnings and cautions.

Using the Code Examples

This book is here to help you learn the craft. In general, you’re welcome to use examples from this book in your own 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 a product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the authors’ names, the book’s title, the publisher, the copyright holder and the ISBN. For example: Learning Flex 4, by Alaric Cole and Elijah Robison (O’Reilly). Copyright 2011 Alaric Cole and Elijah Robison, 978-0-596-80563-0.

If you think your use of code examples falls outside fair use or the permission given here, feel free to contact O’Reilly 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/9780596805630

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

Safari® Books Online

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, and 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.

Acknowledgments

Like a good film, a good technical book is a product of the combined efforts of lots of dedicated people. While we’re the only authors of this book, we couldn’t have done it alone.

Thanks from Alaric

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

Elijah Robison for taking a chance.

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

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 in the first edition.

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

The O’Reilly team for their hard work and support of this book. They’re truly the best in the business.

The Adobe Flex team for another solid release.

Thanks from Elijah

Elizabeth Robison, my wife, for being so encouraging and understanding through another exhausting writing campaign. I couldn’t have succeeded without your support.

Alaric Cole for being my favorite success story.

Chris Giesey and Jesper Larsen, for helping me with the tough stuff.

Ed Fisher, Curtis Copeland, Lori Giesey, Sean Hills, and everyone in management at VillaGIS—thank you so much for your encouragement throughout this process.

Grant Tomlins, for contributing a few photos to the PhotoGallery application, and for scaring me senseless at least five times a week. Actually, thanks for putting up with such a cranky, exhausted carpooler for so many months.

Matt Sabath for contributing his Linux know-how to Appendix D. Thanks, Matt.

David Baclian (http://www.davidbenjaminphotography.com/) and John Van Every for contributing some cool photos to the PhotoGallery application.

Brian Moseley for suggesting several of the quotations introducing the chapters, for being there that time at that place to do that thing, and for being one of the most genuine people I’ve known.

Dave, Debby, and Aston Quinonez; Billy Ellison; the Brownfield family; Corey Nolan; Dillon Walden; John Wallace; Gabriel Scott Dean; Nick Peña; Matt Moser; Mike Wingate; Brian Fitch; Marcus French; Seth Harrell; Chris Person; Justin Besancon; James Geurtz; Trey Ronne; Jimmy Kribs; my first real coder-friend Mark Ewing; Danqsyle; the curvature of the Earth: and anyone else who encouraged me, inspired me, or otherwise tolerated my absence during the first eight months of 2010.

Mark Morgan, Seth Cartwright, Craig Shipley, and Craig Earl Nelson for initially getting me into computers and cool software.

Kenny Anderson, the first of my friends who ever mentioned “integers” in day-to-day conversation.

Brandon Lee Tate, because I fully agree that Brian May is the most underrated guitarist of all time.

Bob Pavlowsky, Xin Miao, Jun Luo, and William Wedenoja for all the doors you open at Missouri State.

Richard and Margaret Van Every, two generous parents whom I cannot thank enough.

Mike and Linda Gurlen for tolerating my eccentricities while I tested so many waters—and for being fine parents.

Steve Robison for being legendary.

Jodie O’Rourke and Russ Ferguson for providing initial feedback that resulted in a much better book.

Sumita Mukherji and Genevieve d’Entremont for marshaling me through the copyedit process with more speed and precision than Ned Braden and Dean Youngblood combined.

Kristen Borg for transforming the raw manuscript into something resembling a book—and for painstakingly colorizing the code for a couple picky authors.

Mary Treseler, the coolest editor I know, and everyone at O’Reilly Media who made this thing happen.

Finally, the teams developing Open Office, the GIMP, and IrfanView, whose fantastic software was used exclusively when writing the manuscript for this book.

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