Flash Builder 4 and Flex 4 Bible- P1

Chia sẻ: Cong Thanh | Ngày: | Loại File: PDF | Số trang:50

0
93
lượt xem
44
download

Flash Builder 4 and Flex 4 Bible- P1

Mô tả tài liệu
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Flash Builder 4 and Flex 4 Bible- P1: When Macromedia first released Flash MX in 2002, the product was branded as the new way to build Rich Internet Applications (known by the acronym RIA). The term was invented at Macromedia to describe a new class of applications that would offer the benefits of being connected to the Internet, including access to various types of Web-based services, but would solve many of the nagging issues that had been inherent in browser-based applications since the mid-1990s....

Chủ đề:
Lưu

Nội dung Text: Flash Builder 4 and Flex 4 Bible- P1

  1. Companion Web Site • Code files for all projects in the book, useful links, and more David Gassner Adobe ® Flash Builder 4 ® ™ and Flex 4 ® Master all the tools in the Flex 4 SDK Integrate with BlazeDS, ColdFusion, and PHP Rapidly develop cross-platform Web apps The book you need to succeed!
  2. Flash Builder 4 and ® ™ Flex 4 Bible ®
  3. Flash Builder 4 and ® ™ Flex 4 Bible ® David Gassner
  4. Flash® Builder™ 4 and Flex® 4 Bible Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2010 by Wiley Publishing, Inc., Indianapolis, Indiana Published by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-0-470-48895-9 Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, 201-748-6011, fax 201-748- 6008, or online at http://www.wiley.com/go/permissions. LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ. For general information on our other products and services or to obtain technical support, please contact our Customer Care Department within the U.S. at (877) 762-2974, outside the U.S. at (317) 572-3993 or fax (317) 572-4002. Library of Congress Control Number: 2010922565 Trademarks: Wiley and the Wiley logo are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. Flash, Builder, and Flex are trademarks or registered trademarks of Adobe Systems, Inc. All other trademarks are the property of their respective owners. Wiley Publishing, Inc. is not associated with any product or vendor mentioned in this book. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.
  5. For Jackie About the Author David Gassner is president of Bardo Technical Services, an Adobe training partner in Seattle, Washington, and serves as Content Manager for Developer Titles for lynda.com. As an author for lynda.com, he has recorded video training titles on Flex, AIR, ColdFusion, Dreamweaver, and ASP. NET. He holds Adobe developer and instructor certifications in Flex, ColdFusion, Flash, and Dreamweaver, is an Adobe Master Instructor, and has been a regular speaker at Allaire, Macromedia, and Adobe conferences. David earned a BA from Pitzer College in Claremont, California (his home town), and an MFA from the Professional Theatre Training Program at U.C. San Diego. In his copious free time (and putting his MFA to good use), he is an active director and actor in Seattle’s live theater scene. He shares his home with his wonderful wife, Jackie (Go Mets!), and he receives occasional visits from his thoroughly adult kids, Thad, Jason, and Jenny.
  6. Credits Senior Acquisitions Editor Project Coordinator Stephanie McComb Patrick Redmond Executive Editor Graphics and Production Specialists Jody Lefevere Nikki Gately Amy Hassos Project Editor Joyce Haughey Katharine Dvorak Quality Control Technicians Technical Editor Laura Albert Drew Falkman John Greenough Melanie Hoffman Copy Editor Lindsay Littrell Lauren Kennedy Lauren Mandelbaum Editorial Director Proofreading Robyn Siesky Christine Sabooni Business Manager Indexing Amy Knies BIM Indexing & Proofreading Services Senior Marketing Manager Media Development Project Manager Sandy Smith Laura Moss Vice President and Executive Group Media Development Assistant Project Publisher Manager Richard Swadley Jenny Swisher Vice President and Executive Publisher Media Development Associate Producer Barry Pruett Shawn Patrick
  7. Preface ....................................................................................................................................... xxiii Acknowledgments .................................................................................................................... xxvii Part I: Flex Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Chapter 1: About Flex 4 .................................................................................................................3 Chapter 2: Using Flash Builder 4 ..................................................................................................31 Chapter 3: Building a Basic Flex Application ................................................................................73 Chapter 4: Understanding the Anatomy of a Flex Application ......................................................99 Chapter 5: Using Bindings and Components ..............................................................................135 Chapter 6: Debugging Flex Applications .....................................................................................167 Chapter 7: Working with Events.................................................................................................207 Part II: Designing Flex Applications . . . . . . . . . . . . . . . . . . . 247 Chapter 8: Using Flex Visual Controls ........................................................................................249 Chapter 9: Working with Text ....................................................................................................287 Chapter 10: Using Layout Containers .........................................................................................311 Chapter 11: Using Cascading Style Sheets...................................................................................341 Chapter 12: Controlling Animation and Working with Drag and Drop.......................................371 Chapter 13: Managing View States ..............................................................................................399 Chapter 14: Declaring Graphics with MXML and FXG ...............................................................419 Chapter 15: Skinning Spark Components ...................................................................................443 Chapter 16: Managing Application Navigation............................................................................469 Chapter 17: Working with Pop-up Windows .............................................................................503 Part III: Working with Data. . . . . . . . . . . . . . . . . . . . . . . . . . 531 Chapter 18: Modeling and Managing Data ..................................................................................533 Chapter 19: Using List Controls..................................................................................................571 Chapter 20: Using Advanced List Controls .................................................................................603 Chapter 21: Using the Flex Charting Controls ............................................................................647 Chapter 22: Working with Data Entry Forms .............................................................................675 Chapter 23: Working with HTTPService and XML .....................................................................707 Chapter 24: Managing XML with E4X ........................................................................................749 vii
  8. Part IV: Integrating Flex Applications with Application Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 775 Chapter 25: Working with SOAP-Based Web Services ................................................................777 Chapter 26: Integrating Flex Applications with BlazeDS and Java ...............................................807 Chapter 27: Using the Message Service with BlazeDS..................................................................849 Chapter 28: Integrating Flex Applications with ColdFusion........................................................873 Chapter 29: Integrating Flex Applications with PHP ...................................................................911 Part V: Additional Subjects. . . . . . . . . . . . . . . . . . . . . . . . . . 939 Chapter 30: Localizing Flex 4 Applications .................................................................................941 Chapter 31: Deploying Desktop Applications with Adobe AIR....................................................955 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 983 viii
  9. Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  xxiii Acknowledgments  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvii Part I: Flex Fundamentals 1 Chapter 1: About Flex 4  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 Learning the Fundamentals of Flex .......................................................................................4 Getting to know Flex applications ...............................................................................4 Flex versus Flash development ....................................................................................8 Flex and object-oriented programming .....................................................................11 Understanding Adobe Flash Player .....................................................................................18 Learning a little Adobe Flash Player history ...............................................................19 Understanding Flash Player penetration statistics ......................................................21 Using the debug version of Flash Player ....................................................................21 Flash Player installation .............................................................................................22 Flex 4 Development Tools ..................................................................................................26 Understanding Flash Builder 4 ..................................................................................26 Using the Flex 4 SDK ................................................................................................26 Getting Help .......................................................................................................................29 Summary ............................................................................................................................29 Chapter 2: Using Flash Builder 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Getting Flash Builder ..........................................................................................................31 Installing Flash Builder 4 ....................................................................................................32 Installing Flash Builder with the stand-alone configuration .......................................32 Getting to Know Eclipse Features........................................................................................36 The Eclipse workspace ..............................................................................................37 Configuring Eclipse ...................................................................................................43 Using Flash Builder .............................................................................................................45 Creating a Flex project ..............................................................................................45 Understanding Flash Builder’s user interface .............................................................49 Getting Help .......................................................................................................................55 Exploring the Help contents ......................................................................................55 Searching for Help terms ...........................................................................................56 Using dynamic help ..................................................................................................57 ix
  10. Contents Searching for Code..............................................................................................................58 Using Eclipse search tools .........................................................................................58 Using Flash Builder code model search tools .............................................................60 Generating Code .................................................................................................................64 Generating getter and setter methods ........................................................................64 Generating event handlers .........................................................................................66 Integrating Flash Builder with Flash Professional CS5 .........................................................66 Summary ............................................................................................................................71 Chapter 3: Building a Basic Flex Application . . . . . . . . . . . . . . . . . . . . . . . 73 Creating a “Hello World” Application .................................................................................74 Switching workspaces ...............................................................................................74 Creating the project...................................................................................................75 Saying hello...............................................................................................................78 Understanding the html-template Folder ............................................................................81 The HTML wrapper template ....................................................................................82 History management files ..........................................................................................87 Deploying the Application ..................................................................................................88 Creating a release build .............................................................................................88 Testing the release build ............................................................................................90 Deploying the release build .......................................................................................91 Integrating an application into an existing Web page ................................................91 Integrating Flex applications with Dreamweaver .......................................................93 Summary ............................................................................................................................97 Chapter 4: Understanding the Anatomy of a Flex Application  . . . . . . . . . 99 MXML and ActionScript 3 ................................................................................................101 Understanding MXML ......................................................................................................104 MXML is XML! ........................................................................................................104 MXML and containership ........................................................................................110 MXML and nonvisual classes ...................................................................................112 Understanding ActionScript 3 ...........................................................................................114 ActionScript syntax .................................................................................................114 Declaring variables ..................................................................................................114 Conditional statements ............................................................................................117 Looping...................................................................................................................119 Combining MXML and ActionScript .................................................................................120 Using the element .................................................................................120 Using external ActionScript files ..............................................................................120 Managing ActionScript code with Flash Builder ......................................................124 Using the Application Component ....................................................................................128 Passing application parameters ................................................................................130 Controlling application dimensions.........................................................................130 Setting the layout property ......................................................................................131 Summary ..........................................................................................................................134 x
  11. Contents Chapter 5: Using Bindings and Components . . . . . . . . . . . . . . . . . . . . . 135 Using Binding Expressions ................................................................................................136 Shorthand MXML binding expressions....................................................................136 Using .................................................................................................137 Making expressions bindable ..................................................................................137 Using MXML Components ................................................................................................139 Creating MXML components...................................................................................139 Instantiating MXML components ............................................................................144 Adding Properties and Methods to Components ...............................................................149 Component properties ............................................................................................150 Component methods...............................................................................................152 Using Component Libraries ..............................................................................................155 Creating component libraries ..................................................................................155 Using component libraries ......................................................................................159 Creating Flash-based Components ....................................................................................161 Summary ..........................................................................................................................165 Chapter 6: Debugging Flex Applications  . . . . . . . . . . . . . . . . . . . . . . . . 167 Debugging Basics ..............................................................................................................168 The debug version of the application.......................................................................169 Running an application in debug mode ...................................................................169 Using trace() and the Logging API.....................................................................................172 Using the trace() function........................................................................................172 Using the Logging API.............................................................................................175 Using Breakpoints .............................................................................................................180 Setting and clearing breakpoints .............................................................................180 Setting and removing breakpoints in an MXML or ActionScript editor ....................180 Setting conditional breakpoints ...............................................................................181 Using the Breakpoints view .....................................................................................183 Using breakpoints in a debugging session ...............................................................185 Inspecting variables and expressions .......................................................................187 Controlling application execution with the Debug view ..........................................192 Profiling Flex Applications ................................................................................................194 Using the Network Monitor ..............................................................................................196 Configuring a Flex project for use with ColdFusion ................................................197 Tracing network traffic ............................................................................................201 Summary ..........................................................................................................................206 Chapter 7: Working with Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 The Flex Event Architecture ..............................................................................................208 Handling Events in MXML ................................................................................................210 Declaring event listeners in MXML ..........................................................................210 Working with event objects.....................................................................................213 xi
  12. Contents Handling Events with addEventListener() .........................................................................223 Setting up an event listener .....................................................................................223 Using event name constants ....................................................................................226 Removing an event listener......................................................................................227 Using Event Bubbling .......................................................................................................227 Using Custom Events ........................................................................................................230 Declaring custom events..........................................................................................231 Dispatching custom events ......................................................................................233 Handling custom events ..........................................................................................235 Using Custom Event Classes .............................................................................................237 Creating the ActionScript class ................................................................................238 Dispatching a custom event class.............................................................................242 Handling an event that uses a custom event class ....................................................244 Summary ..........................................................................................................................246 Part II: Designing Flex Applications 247 Chapter 8: Using Flex Visual Controls  . . . . . . . . . . . . . . . . . . . . . . . . . . 249 Instantiating and Customizing Controls ............................................................................250 Instantiating controls with MXML and ActionScript ................................................250 Setting control properties and styles ........................................................................251 Understanding UIComponent and GraphicElement ................................................251 Using Spark Text Controls ................................................................................................253 Using text control properties ...................................................................................254 Text entry controls ..................................................................................................259 Using Layout Controls ......................................................................................................263 The HRule and VRule controls ................................................................................263 The Spacer control ..................................................................................................265 Using Button Controls ......................................................................................................266 The Button control ..................................................................................................266 The LinkButton control ...........................................................................................268 The CheckBox control.............................................................................................268 The RadioButton controls........................................................................................269 Other Data Entry Controls ................................................................................................271 The NumericStepper control ...................................................................................272 Date controls ...........................................................................................................273 The ColorPicker control ..........................................................................................275 Using Interactive Controls.................................................................................................277 The ScrollBar controls .............................................................................................277 The Slider controls ..................................................................................................279 Using the Image and BitmapImage Controls .....................................................................281 Resizing images .......................................................................................................283 Embedding images ..................................................................................................284 Changing images at runtime ....................................................................................285 Summary ..........................................................................................................................286 xii
  13. Contents Chapter 9: Working with Text. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 Using Advanced Text Layout ............................................................................................288 Presenting richly formatted text...............................................................................288 Presenting text in columns ......................................................................................292 Using bidirectional text ...........................................................................................292 Controlling Fonts with Cascading Style Sheets ..................................................................294 Selecting fonts .........................................................................................................295 Using device fonts ...................................................................................................296 Using embedded fonts.............................................................................................297 Manipulating Text.............................................................................................................303 Formatting Text Values .....................................................................................................305 Creating formatter objects .......................................................................................305 Setting formatter properties .....................................................................................306 Using formatters in binding expressions ..................................................................307 Using formatters in static methods ..........................................................................308 Summary ..........................................................................................................................310 Chapter 10: Using Layout Containers . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 Using MX Basic Containers ...............................................................................................312 Using vertical and horizontal layout containers .......................................................312 Using the Canvas container .....................................................................................315 Using MX container styles .......................................................................................317 Using Spark Group Components ......................................................................................319 Using the Group component ...................................................................................320 Using VGroup and HGroup ....................................................................................321 Using the Spark BorderContainer ............................................................................323 Using Panel Containers .....................................................................................................325 Panel properties ......................................................................................................326 Using the MX ControlBar container.........................................................................328 Using Spark panels with control bars ......................................................................329 Using Constraint-Based Layout .........................................................................................330 Positioning components in Design mode.................................................................331 Using constraint properties .....................................................................................332 Sizing Containers and Controls .........................................................................................333 Content-based sizing ...............................................................................................333 Absolute sizing ........................................................................................................334 Percentage sizing .....................................................................................................334 Constraint-based sizing ...........................................................................................335 Creating a Scrolling Region ...............................................................................................337 Summary ..........................................................................................................................339 xiii
  14. Contents Chapter 11: Using Cascading Style Sheets  . . . . . . . . . . . . . . . . . . . . . . . 341 About Cascading Style Sheets............................................................................................341 What Is a Style Sheet? .......................................................................................................343 Using Inline Style Declarations..........................................................................................344 Declaring Style Sheets with ...............................................................................345 Using Style Selectors .........................................................................................................346 Using type selectors.................................................................................................346 Using descendant selectors ......................................................................................350 Using style name selectors .......................................................................................351 Using ID selectors ...................................................................................................352 Using the global selector .........................................................................................352 Using Embedded Style Sheets ...........................................................................................353 Using External Style Sheets ...............................................................................................356 Creating a blank style sheet .....................................................................................356 Exporting existing styles ..........................................................................................359 Using Compiled Style Sheets .............................................................................................363 Compiling style sheets.............................................................................................363 Loading compiled style sheets .................................................................................363 Controlling Styles with ActionScript .................................................................................366 Setting and getting style information .......................................................................366 Modifying style selectors at runtime ........................................................................367 Summary ..........................................................................................................................370 Chapter 12: Controlling Animation and Working with Drag and Drop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371 Using Effects .....................................................................................................................372 Declaring and playing effect classes .........................................................................373 Declaring effects in ActionScript..............................................................................375 Using the new Spark effects.....................................................................................377 Using composite effects ...........................................................................................383 Using easing classes .................................................................................................387 Using Drag-and-Drop Operations .....................................................................................388 Implementing drag-and-drop with List controls ......................................................389 Implementing custom drag-and-drop operations ....................................................391 Summary ..........................................................................................................................398 Chapter 13: Managing View States . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399 Understanding View States................................................................................................400 Defining View States in Design View .................................................................................401 Creating a new state ................................................................................................401 Defining a view state’s overrides ..............................................................................404 Switching View States at Runtime .....................................................................................406 Declaring View States in MXML ........................................................................................407 Adding and removing components..........................................................................408 Overriding properties, styles, and event handlers ....................................................409 xiv
  15. Contents Managing View States in Components ..............................................................................412 Using Transitions ..............................................................................................................414 Declaring a transition ..............................................................................................414 Using Parallel and Sequence effects in transitions ....................................................415 Summary ..........................................................................................................................418 Chapter 14: Declaring Graphics with MXML and FXG . . . . . . . . . . . . . . . 419 Declaring Vector Graphics in MXML .................................................................................420 Drawing lines and shapes ........................................................................................420 Adding visual effects ...............................................................................................425 Using FXG Files ................................................................................................................432 Creating FXG graphics with Creative Suite software ................................................432 Using FXG files in Flex applications ........................................................................439 Summary ..........................................................................................................................442 Chapter 15: Skinning Spark Components . . . . . . . . . . . . . . . . . . . . . . . . 443 Creating and Using Spark Custom Skins ...........................................................................444 Skinning a Spark application ...................................................................................444 Binding a custom skin to a Spark component..........................................................451 Skinning Other Spark Components ..................................................................................455 Creating a new skin.................................................................................................455 Assigning custom skins with CSS ............................................................................461 Customizing the skin ..............................................................................................462 Summary ..........................................................................................................................467 Chapter 16: Managing Application Navigation . . . . . . . . . . . . . . . . . . . . 469 Understanding Classic Web Navigation ............................................................................470 Understanding Flex Navigation .........................................................................................471 Using Navigator Containers ..............................................................................................471 Declaring a ViewStack in MXML .............................................................................472 Using custom components in a navigator container.................................................472 Creating a ViewStack in Design mode .....................................................................473 Working with navigator containers in ActionScript .................................................477 Managing creation policy ........................................................................................482 Managing navigator container dimensions...............................................................484 Using Navigator Bar Containers ........................................................................................484 Using a data collection as a dataProvider .................................................................485 Handling navigator bar events .................................................................................487 Using a ViewStack as a dataProvider .......................................................................487 Managing navigator bar presentation .......................................................................488 Using Menu Controls ........................................................................................................491 Menu data providers ...............................................................................................492 Handling menu events ............................................................................................493 Using the Menu control...........................................................................................494 Using the MenuBar control......................................................................................495 xv
  16. Contents Using Other Navigator Containers ....................................................................................497 The TabNavigator container ....................................................................................498 The Accordion container .........................................................................................500 TabNavigator and Accordion keyboard shortcuts ....................................................501 Summary ..........................................................................................................................502 Chapter 17: Working with Pop-up Windows  . . . . . . . . . . . . . . . . . . . . . 503 Using the Alert Class .........................................................................................................504 Presenting pop-up windows with Alert.show()........................................................504 Controlling Alert window modality .........................................................................504 Managing Alert window buttons .............................................................................506 Handling Alert window events ................................................................................508 Using a custom graphical icon.................................................................................509 Using CSS selectors with the Alert class...................................................................512 Using the PopUpMenuButton Control ..............................................................................514 Creating a data provider ..........................................................................................514 Handling events ......................................................................................................515 Using the PopUpButton control ........................................................................................517 Declaring the pop-up window .................................................................................518 Handling events and managing pop-up behavior ....................................................518 Working with Custom Pop-up Windows ..........................................................................521 Defining a custom pop-up window .........................................................................521 Managing custom pop-up windows with the PopUpManager class..........................524 Summary ..........................................................................................................................530 Part III: Working with Data 531 Chapter 18: Modeling and Managing Data . . . . . . . . . . . . . . . . . . . . . . . 533 Creating a Data Model ......................................................................................................534 Using the element.................................................................................535 Using Value Objects ..........................................................................................................539 Using the New ActionScript Class wizard ................................................................540 Value object class syntax .........................................................................................541 Instantiating value object classes .............................................................................549 Using Data Collections ......................................................................................................552 Declaring an ArrayCollection...................................................................................553 Setting a data collection object’s source property.....................................................554 Accessing data at runtime ........................................................................................555 Managing data at runtime........................................................................................556 Using data cursors ...................................................................................................562 Summary ..........................................................................................................................569 Chapter 19: Using List Controls  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571 Using Data Providers.........................................................................................................574 Using hard-coded data providers ............................................................................575 Using dynamic data providers .................................................................................577 xvi
  17. Contents Controlling List Item Labels ..............................................................................................579 Using the labelField property ..................................................................................579 Using the labelFunction property ............................................................................582 List Control Events and Properties ....................................................................................584 Handling User Data Selections ..........................................................................................585 Using the change event ...........................................................................................585 Using the selectedItem property ..............................................................................585 Using the selectedIndex property ............................................................................587 Selecting complex data objects ................................................................................588 Using Custom Item Renderers...........................................................................................590 Using drop-in item renderers ..................................................................................591 Using inline renderers and editors ...........................................................................593 Using component item renderers ............................................................................597 Customizing Spark item renderers with view states .................................................600 Summary ..........................................................................................................................602 Chapter 20: Using Advanced List Controls . . . . . . . . . . . . . . . . . . . . . . . 603 Using ComboBox and DropDownList Controls .................................................................603 Using the prompt property......................................................................................604 Using the ComboBox control ..................................................................................605 Selecting complex data objects with ActionScript ....................................................607 Using the Spark ButtonBar control ..........................................................................611 Using the DataGrid Control ..............................................................................................613 Customizing the DataGrid display ...........................................................................614 Displaying custom labels in DataGrid column cells .................................................619 Advanced Item Renderers and Editors ..............................................................................622 Using the dataChange event ....................................................................................623 Using Spark item renderers .....................................................................................626 Using item editors ...................................................................................................627 Using List Controls with Horizontal and Tile Layout.........................................................635 Using the AdvancedDataGrid Control ...............................................................................641 Hierarchical data display .........................................................................................641 Grouping flat data ...................................................................................................644 Summary ..........................................................................................................................646 Chapter 21: Using the Flex Charting Controls  . . . . . . . . . . . . . . . . . . . . 647 Understanding Flex’s Types of Charts ...............................................................................648 Declaring Chart Controls ..................................................................................................650 Setting Chart Properties and Styles....................................................................................652 Using pie charts ......................................................................................................652 Using financial charts ..............................................................................................663 Using bar, column, line, and area charts..................................................................666 Summary ..........................................................................................................................673 xvii
  18. Contents Chapter 22: Working with Data Entry Forms . . . . . . . . . . . . . . . . . . . . . . 675 Using the Form Container.................................................................................................676 Using the FormHeading control ..............................................................................678 Using the FormItem container.................................................................................680 Setting a default button ...........................................................................................681 Using Custom Form Components .....................................................................................683 Creating a custom Form component .......................................................................683 Adding controls to a Form component ....................................................................685 Validating Data Entry ........................................................................................................687 Creating a validator object.......................................................................................688 Controlling validation with trigger events................................................................688 Controlling validation with ActionScript .................................................................691 Controlling validation rules and error messages ......................................................695 Sharing Data with the Application.....................................................................................697 Modeling Form data with a value object ..................................................................697 Dispatching a custom event.....................................................................................699 Summary ..........................................................................................................................705 Chapter 23: Working with HTTPService and XML . . . . . . . . . . . . . . . . . . 707 Using RPC and REST Architectures ...................................................................................708 Understanding the Representational State Transfer architecture ..............................708 Understanding the Remote Procedure Call architecture...........................................709 Creating Data-Centric Applications with Flash Builder 4...................................................710 Creating and managing data connections ................................................................710 Defining a return data type......................................................................................714 Binding returned data to visual controls ..................................................................719 Declaring and Configuring HTTPService Objects ..............................................................722 Creating an HTTPService object ..............................................................................722 Essential HTTPService properties ............................................................................723 Sending and Receiving Data ..............................................................................................727 Understanding asynchronous communications .......................................................727 Handling HTTPService responses ............................................................................727 Working with CallResponder and AsyncToken .......................................................736 Working with ItemResponder and AsyncToken ......................................................739 Working with Value Objects .............................................................................................741 Passing Parameters to Server Pages....................................................................................744 Using named parameters .........................................................................................744 Using bound parameters .........................................................................................745 Handling Cross-Domain Policy Issues ...............................................................................746 Summary ..........................................................................................................................748 xviii
Đồng bộ tài khoản