Table Of ContentRevised edition of Flex 3 in Action
IN ACTION
Tariq Ahmed
Dan Orlando
John C. Bland II
WITH
Joel Hooks
AND
M A N N I N G
Praise for Flex 3 in Action
The code examples are the strength of this book—plentiful for almost every topic covered.
—Andrew Grother, Triware Technologies, Inc.
Easy enough for the newbie, detailed enough for the veteran.
—Ken Brueck, Move Network
This is a book you will not only want to read cover to cover but also keep on your desk
as a reference for your day to day development needs.
—Abdul Qabiz, reader
Does a great job of covering some of the history behind traditional web development and
where Rich Internet Applications are headed.
—Sami Hoda, eCivis Inc.
A user-friendly tutorial and reference.
—Christophe Bunn, Kitry S.A.S.
An impressive amount of Flex content in a single volume.
—Charlie Griefer, Amcom Technology
It’s clear that the authors put a lot of time and effort into the book. The fact that it comes
with an ebook for this version and the future Flex 4 in Action is a nice bonus.
—A. Kapadia, Amazon reader
I’m a huge fan of Manning’s In Action series. This series caters to people who want
more than a quick gloss-over…. Flex 3 in Action is a roll up your sleeves and get busy
kind of book that makes it easy to get into Flex.
—Allan Mercado, Amazon reader
Flex 4 in Action
REVISED EDITION OF FLEX 3 IN ACTION
TARIQ AHMED
DAN ORLANDO
with JOHN C. BLAND II
and JOEL HOOKS
MANNING
Greenwich
(74° w. long.)
For online information and ordering of this and other Manning books, please visit
www.manning.com. The publisher offers discounts on this book when ordered in quantity.
For more information, please contact
Special Sales Department
Manning Publications Co.
180 Broad St.
Suite 1323
Stamford, CT 06901
Email: orders@manning.com
©2011 by Manning Publications Co. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in
any form or by means electronic, mechanical, photocopying, or otherwise, without prior written
permission of the publisher.
Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in the book, and Manning
Publications was aware of a trademark claim, the designations have been printed in initial caps
or all caps.
Recognizing the importance of preserving what has been written, it is Manning’s policy to have
the books we publish printed on acid-free paper, and we exert our best efforts to that end.
Recognizing also our responsibility to conserve the resources of our planet, Manning books
are printed on paper that is at least 15 percent recycled and processed without the use of
elemental chlorine.
Manning Publications Co. Development editor: Cynthia Kane
180 Broad St. Copyeditor: Linda Recktenwald
Suite 1323 Proofreader: Maureen Spencer
Stamford, CT 06901 Typesetter: Dottie Marsico
Cover designer: Marija Tudor
ISBN 978-1-935182-42-9
Printed in the United States of America
1 2 3 4 5 6 7 8 9 10 – MAL – 15 14 13 12 11 10
brief contents
PART 1 APPLICATION BASICS .....................................................1
1 ■ Making the case 3
2 ■ Getting started 21
3 ■ Working with ActionScript 44
4 ■ Layout and containers 70
5 ■ Displaying forms and capturing user input 96
6 ■ Validating user input 117
7 ■ Formatting data 138
8 ■ MX DataGrids, Lists, and Trees 155
9 ■ Using the Spark List controls 178
10 ■ List customization 192
PART 2 APPLICATION FLOW AND STRUCTURE .........................219
11 ■ Events 221
12 ■ Application navigation 244
13 ■ Introduction to pop-ups 273
14 ■ Implementing view states 294
15 ■ Working with data services 316
v
vi BRIEF CONTENTS
16 ■ Objects and classes 341
17 ■ Custom components 358
18 ■ Creating reusable components 388
19 ■ Architectural design patterns 405
PART 3 THE FINISHING TOUCHES...........................................441
20 ■ Customizing the experience 443
21 ■ Working with effects 469
22 ■ Drag-and-drop 502
23 ■ Exploring Flex charting 530
24 ■ Debugging and testing 557
25 ■ Wrapping up a project 579
contents
foreword to the first edition xx
preface xxii
acknowledgments xxv
about this book xxvii
about the title xxxii
about the cover illustration xxxiii
PART 1 APPLICATION BASICS ........................................... 1
1 Making the case 3
1.1 Why are web applications so prolific? 3
1.2 The RIA solution 5
They all want it all 5 ■ RIAs to the rescue 5
How RIAs do it 6
1.3 The RIA contenders 7
Flex by Adobe 7 ■ Silverlight by Microsoft 8 ■ JavaFX by Sun
Microsystems 8 ■ AJAX—the last stand 9
1.4 Becoming acquainted with Flex 11
Taking advantage of Adobe Flash 11 ■ Flex and JavaScript can
play together 12 ■ The Flex ecosystem 12
vii
Download from Wow! eBook <www.wowebook.com>
viii CONTENTS
1.5 How Flex works 14
The Flex languages 14 ■ Events, events, events 16
Limitations 17
1.6 What’s new in Flex 4 18
1.7 Summary 19
2 Getting started 21
2.1 Flex on the cheap 21
Setting up the compile environment 22 ■ Setting up the editing
environment 24 ■ Next steps (if you’re still interested) 24
2.2 Get serious with Flash Builder 25
Product and pricing matrix 26 ■ Getting Flash Builder 26
2.3 Exploring Flash Builder 27
2.4 Views and perspectives 29
Out-of-the-box perspectives 29 ■ Switching perspectives 29
Customizing perspectives 30
2.5 Our first project—Hello World! 31
Create the project 31 ■ Entering code 33 ■ Compile and
run 33 ■ Making it real 33
2.6 Using design mode 34
2.7 Built-in reference and API documentation 35
Object-oriented languages and their APIs 35 ■ Accessing the API
Reference 36 ■ Perusing the API Reference 37
2.8 MXML and ActionScript in a nutshell 38
The structure of MXML 38 ■ How MXML and ActionScript
relate 39 ■ Events are handled by ActionScript 40
2.9 Summary 42
3 Working with ActionScript 44
3.1 Comments 45
Inline comments 45 ■ Block comments 45
3.2 Variables 45
Variable names 46 ■ Strict data typing 46 ■ Static versus
dynamic type checking 46 ■ Top-level classes 47
Special data types 48
CONTENTS ix
3.3 Loops 48
For (starting value; valid condition; increment) 48 ■ For (property
names in array/object) 49 ■ For each (item in array/object) 50
While (condition) 50 ■ Do while (condition) 50
3.4 Conditional statements (if statements and switches) 51
If..else 51 ■ Switch 53
3.5 Arrays 54
Indexed arrays 54 ■ Associative arrays 56
3.6 ActionScript tidbits 58
Braces 58 ■ Logical operators and shortcuts 59
3.7 Sneak peek at functions, classes, and packages 61
Your own functions 62 ■ Separating ActionScript to
individual files 65
3.8 Simple data binding 66
Life without binding 66 ■ Adding binding 67 ■ The binding
tag 67 ■ Making ActionScript variables bindable 68
3.9 Summary 69
4 Layout and containers 70
4.1 Spark versus Halo (MX) 71
4.2 Absolute layout 72
4.3 Constraint-based layout 74
Basic constraints 74 ■ Enhanced constraints 76
4.4 Automatic layout 80
Using the layout classes 81 ■ Getting spaced out 82
4.5 Variable and fixed sizing 83
Variable sizing 83 ■ Fixed sizing 83
4.6 Containers 84
Application container 84 ■ Canvas container 86
Group-based containers and SkinnableContainer 86
Panel container 88 ■ ApplicationControlBar container 89
DataGroup and SkinnableDataContainer 90 ■ DividedBox,
HDividedBox, and VDividedBox containers 92 ■ Form
container 93 ■ Grid container 94
4.7 Summary 95
Description:Flex 4 in Action is an easy-to-follow, hands-on Flex 4 tutorial. Revised and updated from the previous edition on Flex 3, this book is chock-full of examples, goes beyond feature coverage, and helps readers put Flex to work in real day-to-day tasks. This book helps Flex developers make their Flex ap