ebook img

Effortless Flex 4 development Description based on print version record. - Includes index PDF

457 Pages·2010·24.117 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Effortless Flex 4 development Description based on print version record. - Includes index

EFFORTLESS FLEX 4 DEVELOPMENT LARRY ULLMAN Effortless Flex 4 Development Larry Ullman New Riders 1249 Eighth Street Berkeley, CA 94710 510/524-2178 510/524-2221 (fax) Find us on the Web at: www.newriders.com To report errors, please send a note to: [email protected] New Riders is an imprint of Peachpit, a division of Pearson Education. Copyright © 2010 by Larry Ullman Editor: Rebecca Gulick Production Coordinator: Myrna Vladic Compositor: Debbie Roberti Copy Editor: Elle Yoko Suzuki Proofreader: Patricia Pane Cover and Interior Design: Terri Bogaards Indexer: Valerie Haynes Perry Technical Editor: Ryan Stewart Notice of Rights All rights reserved. No part of this book may be reproduced or transmitted in any form by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher. For information on getting permission for reprints and excerpts, contact [email protected]. Notice of Liability The information in this book is distributed on an “As Is” basis, without warranty. While every precaution has been taken in the preparation of the book, neither the author nor Peachpit shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the instructions contained in this book or by the computer software and hardware products described in it. Trademarks Adobe, the Adobe logo, Flash, the Flash logo, Flash Builder, Flash Catalyst, Flash Lite, and Flash Player are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States and/or other countries. MySQL is a registered trademark of MySQL AB in the United States and in other countries. Macintosh and Mac OS X are registered trademarks of Apple Computer, Inc. Microsoft and Windows are registered trademarks of Microsoft Corporation. Other product names used in this book may be trademarks of their own respective owners. Images of Web sites in this book are copyrighted by the original holders and are used with their kind permission. This book is not officially endorsed by nor affiliated with any of the above companies, including MySQL AB. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and Peachpit was aware of a trademark claim, the designations appear as requested by the owner of the trademark. All other product names and services identified throughout this book are used in editorial fashion only and for the benefit of such companies with no intention of infringement of the trademark. No such use, or the use of any trade name, is intended to convey endorsement or other affiliation with this book. ISBN 13: 978-0-321-70594-5 ISBN 10: 0-321-70594-7 9 8 7 6 5 4 3 2 1 Printed and bound in the United States of America With eternal gratitude to all the doctors, nurses, and staff at Fresenius, CMSA, and Johns Hopkins, most especially to Dr. Fine, who has gone well above the call of duty time and again. SPECIAL THANKS Bucketsful of thanks to everyone at Peachpit Press/New Riders for their assistance, patience, and hard work, particularly: My favorite-est editor ever, Rebecca Gulick. Thanks, thanks, and thanks! Elle Suzuki and Patricia Pane, for the extra coat of polish on my writing. Myrna and Deb, who can magically take a Word doc and some images and turn that into an actual book. Valerie Haynes Perry, the indexer, for making sure readers can find what they’re looking for amongst all those pesky pages and words. Everyone else at Peachpit for doing what’s required to create, publish, distribute, market, sell, and support these books. And thanks for sparing the extra pages when you can! Jason Batten, for taking the time and putting in the effort to read through the chapters and provide feedback. The input, and the votes of confidence, really helped! Ryan Stewart at Adobe, who provided the technical review, making the book accurate. And lots of thanks to Mike Potter at Adobe, who got me interested in Flex in the first place (well, more interested), and did what he could to make this book happen. Big thanks for all the support, too! CONTENTS Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii What is Flash? ................................................. xiii Why use Flash? ................................................ xiv The Case for RIAs .............................................. xiv The Case for Flash .............................................. xv The Case Against Flash ......................................... xvi What is Flex? .................................................. xvi About This Book ............................................... xvii PART One: THe FUnDAMenTALS .......................................... 1 Chapter One: Building Flex Applications ................................... 2 A Survey of the Land ............................................. 2 The Flex Framework .............................................. 3 The Software .................................................... 4 Deployment ..................................................... 5 Basic MXML ..................................................... 5 Using Flash Builder .............................................. 8 A Quick Tour of Flash Builder ...................................... 8 Creating a Simple Application .................................... 11 Saying “Hello” to the World ...................................... 12 Deploying Web Applications ..................................... 14 The Open Source Alternative .................................... 15 Installation and Setup ........................................... 17 Creating a Simple Application .................................... 20 Saying “Hello” to the World ...................................... 21 Deploying Web Applications ..................................... 22 Creating Desktop Applications .................................. 24 A Word on Certificates ........................................... 24 Desktop Applications in Flash Builder ............................ 24 Desktop Applications the Open-Source Way ...................... 28 vi CONTENTS Getting Help .................................................... 32 On the Web ..................................................... 32 Within Flash Builder ............................................. 34 Chapter Two: User Interface Basics ........................................ 36 Things to Know ................................................. 37 Comments within MXML ......................................... 37 Adding Components ............................................ 37 Debugging ...................................................... 40 Component Types and Terminology .............................. 41 Customizing the Application .................................... 42 Simple Controls ................................................ 44 Text Controls .................................................... 45 Media Controls ................................................. 47 Other Controls .................................................. 50 Controlling the Layout .......................................... 51 Layout Classes .................................................. 52 Layout Containers ............................................... 53 Constraint-Based Layout ........................................ 55 Creating Forms ................................................. 56 Putting It All Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Chapter Three: ActionScript You Need to Know ........................... 64 Data Binding ................................................... 64 OOP Fundamentals ............................................. 66 ActionScript and MXML ......................................... 69 The Compilation Process ........................................ 69 Including ActionScript ........................................... 70 Importing ActionScript .......................................... 72 ActionScript Comments ......................................... 74 Simple Data Types .............................................. 75 Making Variables Bindable ...................................... 77 Constants ...................................................... 78 Operators ...................................................... 79 Creating Functions .............................................. 80 CONTENTS vii Looking Ahead: the Click Event .................................. 82 Control Structures .............................................. 85 Arrays .......................................................... 89 Loops .......................................................... 93 for Loops ....................................................... 93 while Loops ..................................................... 95 Manipulating Components ...................................... 95 Debugging Techniques .......................................... 99 Chapter Four: Event Management ......................................... 102 Fundamental Concepts ......................................... 103 The Event Object ............................................... 105 Event Flow ..................................................... 107 Inline Event Handling .......................................... 109 Functions as Event Handlers ................................... 110 Creating Simple Event Handlers .................................. 111 Sending Values to Event Handlers ............................... 112 Sending Events to Functions .................................... 112 Using Specific Events ........................................... 117 System Events ................................................. 118 User Events ................................................... 120 Keyboard and Mouse Events .................................... 120 Keyboard and Mouse Event Objects ............................. 122 Other User-Driven Events ....................................... 123 Managing Event Handlers with ActionScript .................... 124 Watching for Phases ........................................... 126 Removing Event Handlers ...................................... 129 PART TWO: DATA AnD COMMUnICATIOnS .......................... 133 Chapter Five: Displaying Data ............................................. 134 Representing Data ............................................. 134 In ActionScript ................................................. 135 In MXML ....................................................... 139 Providing Data to Components ................................. 144 ComboBox and DropDownList Components ..................... 146 Events ......................................................... 147 An Example .................................................... 149 viii CONTENTS The List Component ............................................ 152 List Basics ..................................................... 152 List Events ..................................................... 154 The Tree Component ........................................... 155 Tree Events .................................................... 157 An Example .................................................... 157 The DataGrid Component ...................................... 160 DataGrid Events ................................................ 162 Updating Data in a DataGrid .................................... 162 Chapter Six: Manipulating Data ........................................... 168 Using Label Functions ......................................... 168 ComboBox, DropDownMenu, List, and Tree Label Functions ...... 169 DataGrid and DataGridColumn Label Functions .................. 171 Item Renderers ................................................ 174 External Item Renderers ........................................ 176 Declared Item Renderers ....................................... 177 Inline Renderers ............................................... 178 Drop-In Item Renderers ......................................... 179 Comparing Component Renderers .............................. 180 Changing the Editor ........................................... 181 The DataGroup Component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 Creating a DataGroup .......................................... 182 Controlling the Layout .......................................... 183 Formatting Data ............................................... 184 Creating Formatters ............................................ 185 Applying Formatters ............................................ 187 Validating Data ................................................ 189 Validator Fundamentals ........................................ 190 Validators in More Detail ....................................... 192 The DateValidator .............................................. 193 The CreditCardValidator ........................................ 195 Creating Validators in ActionScript .............................. 196 An Example .................................................... 198 CONTENTS ix Chapter Seven: Common Data Formats ................................... 202 The Client-Server Relationship ................................. 203 Four Data Formats ............................................. 204 Plain Text ...................................................... 205 XML ........................................................... 205 JSON .......................................................... 208 AMF ........................................................... 210 Data Formats in PHP ........................................... 211 Data Types in ActionScript ..................................... 223 Plain Text ...................................................... 223 Debugging .................................................... 228 Chapter Eight: Using Simple Services .................................... 230 Flash Security Model .......................................... 231 Setting Up a Local Environment ................................ 233 Creating the PHP Scripts ....................................... 236 The MySQL Script .............................................. 237 Retrieving Employees .......................................... 237 Adding Employees ............................................. 240 Flex Networking Components .................................. 243 The HTTPService Component ................................... 244 Creating ....................................................... 244 Invoking a Service .............................................. 246 Handling the Response ......................................... 246 Handling Response Errors ...................................... 248 Putting It All Together .......................................... 248 Sending Data to a Server ....................................... 251 Flash Builder Data Wizards .................................... 260 Creating a Client-Server Application ............................. 261 Adding Some MXML ............................................ 262 Creating Services .............................................. 263 Testing Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266 Making Changes ............................................... 267 Configuring Services .......................................... 268 Using the Services ............................................. 271 Generating Forms .............................................. 273 Using the Network Monitor .................................... 278

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.