Tải bản đầy đủ (.pdf) (50 trang)

Tài liệu Flash Builder 4 and Flex 4 Bible- P1 docx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.67 MB, 50 trang )

David Gassner
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!
Adobe
®
Flash
®
Builder

4
and Flex
®
4
Gassner
Master these skills and flex your
development muscles
Deliver rich applications for the Web or desktop with
Adobe’s new Flash Builder 4 integrated development
environment, Flex 4, and the comprehensive tutorials in
this packed guide. You’ll first get up to speed on Flex
basics and Flash Builder 4’s new development tools.
From there, learn how to use Flex 4’s new Spark com-
ponent skinning capability, deploy desktop apps with
AIR, model and manage data, integrate your app with
popular application servers, and much more!
• Understand the differences between Flex and Flash development


• Master Flex 4 and Flash Builder 4 fundamentals
• Create and use custom MXML components in a Flex application
• Work with text, Cascading Style Sheets (CSS), and layout containers
• Integrate your Flex apps with BlazeDS, Java
®
, ColdFusion
®
, and PHP
• Create cross-operating system desktop applications with AIR
Companion
Web Site
Access code files for all projects in
the book, as well as additional
information, useful links, and more
from www.wiley.com/go/flex4.
David Gassner
is the President of Bardo Technical
Services, an Adobe Solutions
Network Training Provider. He holds
Adobe developer certifications in
Flex, AIR, ColdFusion, Flash, and
Dreamweaver. He is the author of
Flex 3 Bible
(Wiley) and of technical
training videos from lynda.com on
Adobe Flex, AIR, ColdFusion, and
Dreamweaver. He is also a regular
contributor to Adobe Systems’
Certified Courseware for Flex.
Shelving Category:

COMPUTERS / Web / Page Design
Reader Level:
Beginning to Advanced
$49.99 USA
$59.99 Canada
www.wiley.com/compbooks
Integrate Flex applications
into Web pages
Learn the Flash Builder 4
interface
Synchronize complex data
Companion
Web Site
Companion Web Site
• Code files for all projects in the book, useful links, and more
Adobe
®
Ado
b
b
e
Flash
®
Builder

4
and Flex
®
4
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.

01_488959-ffirs.indd ii01_488959-ffirs.indd ii 3/5/10 2:16 PM3/5/10 2:16 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
Flash
®
Builder

4 and
Flex
®
4 Bible
01_488959-ffirs.indd i01_488959-ffirs.indd i 3/5/10 2:16 PM3/5/10 2:16 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
01_488959-ffirs.indd ii01_488959-ffirs.indd ii 3/5/10 2:16 PM3/5/10 2:16 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
Flash
®
Builder

4 and
Flex
®
4 Bible
David Gassner
01_488959-ffirs.indd iii01_488959-ffirs.indd iii 3/5/10 2:16 PM3/5/10 2:16 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
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
/>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.
01_488959-ffirs.indd iv01_488959-ffirs.indd iv 3/5/10 2:16 PM3/5/10 2:16 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
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.
01_488959-ffirs.indd v01_488959-ffirs.indd v 3/5/10 2:16 PM3/5/10 2:16 PM

Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
Credits
Senior Acquisitions Editor
Stephanie McComb
Executive Editor
Jody Lefevere
Project Editor
Katharine Dvorak
Technical Editor
Drew Falkman
Copy Editor
Lauren Kennedy
Editorial Director
Robyn Siesky
Business Manager
Amy Knies
Senior Marketing Manager
Sandy Smith
Vice President and Executive Group
Publisher
Richard Swadley
Vice President and Executive Publisher
Barry Pruett
Project Coordinator
Patrick Redmond
Graphics and Production Specialists
Nikki Gately
Amy Hassos
Joyce Haughey
Quality Control Technicians

Laura Albert
John Greenough
Melanie Hoffman
Lindsay Littrell
Lauren Mandelbaum
Proofreading
Christine Sabooni
Indexing
BIM Indexing & Proofreading Services
Media Development Project Manager
Laura Moss
Media Development Assistant Project
Manager
Jenny Swisher
Media Development Associate Producer
Shawn Patrick
01_488959-ffirs.indd vi01_488959-ffirs.indd vi 3/5/10 2:16 PM3/5/10 2:16 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
viivii
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
02_488959-ftoc.indd vii02_488959-ftoc.indd vii 3/5/10 2:17 PM3/5/10 2:17 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
viii
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
02_488959-ftoc.indd viii02_488959-ftoc.indd viii 3/5/10 2:17 PM3/5/10 2:17 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
ix
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
02_488959-ftoc.indd ix02_488959-ftoc.indd ix 3/5/10 2:17 PM3/5/10 2:17 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
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 <fx:Script> 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
02_488959-ftoc.indd x02_488959-ftoc.indd x 3/5/10 2:17 PM3/5/10 2:17 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
xi
Contents
Chapter 5: Using Bindings and Components..................... 135
Using Binding Expressions 136

Shorthand MXML binding expressions 136
Using <fx:Binding> 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
02_488959-ftoc.indd xi02_488959-ftoc.indd xi 3/5/10 2:17 PM3/5/10 2:17 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
xii
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
02_488959-ftoc.indd xii02_488959-ftoc.indd xii 3/5/10 2:17 PM3/5/10 2:17 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
xiii
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
02_488959-ftoc.indd xiii02_488959-ftoc.indd xiii 3/5/10 2:17 PM3/5/10 2:17 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
xiv
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 <fx:Style> 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
02_488959-ftoc.indd xiv02_488959-ftoc.indd xiv 3/5/10 2:17 PM3/5/10 2:17 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
xv
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
02_488959-ftoc.indd xv02_488959-ftoc.indd xv 3/5/10 2:17 PM3/5/10 2:17 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
xvi
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 <fx:Model> 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
02_488959-ftoc.indd xvi02_488959-ftoc.indd xvi 3/5/10 2:17 PM3/5/10 2:17 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.

xvii
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
02_488959-ftoc.indd xvii02_488959-ftoc.indd xvii 3/5/10 2:17 PM3/5/10 2:17 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
xviii
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
02_488959-ftoc.indd xviii02_488959-ftoc.indd xviii 3/5/10 2:17 PM3/5/10 2:17 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
xix
Contents

Chapter 24: Managing XML with E4X ........................... 749
Using XML Classes 750
Creating an XML object 751
Using the XMLList class 754
Using the XMLListCollection class 755
Using E4X Expressions 756
Extracting data from XML objects 758
Modifying data in XML objects 765
Working with Namespaces 770
Summary 774
Part IV: Integrating Flex Applications
with Application Servers 775
Chapter 25: Working with SOAP-Based Web Services.............. 777
Understanding SOAP 778
Understanding WSDL 780
Using the WebService Component 783
Installing ColdFusion 783
Creating a WebService object 784
Handling Web service results 786
Passing parameters to Web service operations 796
Using Web Service Data Connections 798
Defining a data connection 799
Managing Web service data connections 801
Summary 805
Chapter 26: Integrating Flex Applications with BlazeDS and Java...... 807
Using BlazeDS 808
Understanding supported platforms 808
Getting started with BlazeDS 809
Creating Flex Projects for Use with BlazeDS 814
Using the Proxy Service 817

Configuring the Proxy Service 817
Using the default destination 818
Using named destinations 822
Using the Remoting Service 824
Creating and exposing Java classes 825
Configuring Remoting Service destinations 828
Using the RemoteObject Component 830
Instantiating the RemoteObject component 830
Calling remote methods 830
Handling RemoteObject results 831
Passing arguments to remote methods 838
02_488959-ftoc.indd xix02_488959-ftoc.indd xix 3/5/10 2:17 PM3/5/10 2:17 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
xx
Contents
Passing data between ActionScript and Java 840
Using value object classes 841
Working with BlazeDS Data Connections in Flash Builder 4 845
Enabling RDS with BlazeDS 846
Defining BlazeDS data connections 847
Summary 848
Chapter 27: Using the Message Service with BlazeDS .............. 849
Understanding the Message Service 850
Configuring Messaging on the Server 851
Configuring channels for messaging 851
Configuring messaging adaptors and destinations 854
Creating a Flex Messaging Application 856
Creating a Flex project 856
Sending messages 857
Receiving and processing messages 858

Sending and Receiving Complex Data 862
Filtering Messages on the Server 865
Using the selector property 865
Using subtopics 866
Tracing Messaging Traffic 871
Summary 872
Chapter 28: Integrating Flex Applications with ColdFusion .......... 873
Understanding Flash Remoting and ColdFusion 874
Creating a Flex project for use with ColdFusion 875
Configuring Flash Remoting on the server 877
Creating ColdFusion Components for Flex 878
Using CFCs with the RemoteObject Component 880
Setting the source property 881
Creating a RemoteObject instance 881
Calling CFC functions 882
Handling CFC Function Results 883
Using binding expressions 883
Using the result event 884
Handling results from multiple CFC functions 888
Passing Arguments to CFC Functions 891
Using explicit arguments 891
Using bound arguments 892
Using named arguments 892
Using Value Object Classes 894
Creating a ColdFusion value object 894
Creating an ActionScript value object 895
Returning value objects from ColdFusion to Flex 896
02_488959-ftoc.indd xx02_488959-ftoc.indd xx 3/5/10 2:17 PM3/5/10 2:17 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
xxi

Contents
Receiving value objects from ColdFusion 897
Passing value object arguments to CFC functions 899
Working with RemoteObject Faults 900
Handling the fault event 900
Generating custom exceptions from a CFC function 901
Working with Data Connections in Flash Builder 903
Calling ColdFusion 9 Services 905
Configuring ColdFusion security 905
Using ColdFusion 9 client-side service components 907
Summary 910
Chapter 29: Integrating Flex Applications with PHP................ 911
Installing PHP 912
Installing WampServer on Windows 913
Managing WampServer 914
Installing MAMP on Mac OS X 916
Managing MAMP servers 917
Creating a Flex Project for Use with PHP 919
Using PHP with HTTPService and XML 922
Using the PHP SimpleXML extension 922
Retrieving XML data with HTTPService 923
Using PHP and Remoting with Zend AMF 924
Installing Zend AMF 925
Creating a service class in PHP 927
Calling a PHP class with RemoteObject 928
Returning complex data from Zend AMF 929
Understanding ActionScript to PHP data serialization 932
Using PHP Data Connections in Flash Builder 932
Defining data connections 932
Generating a service based on a database table structure 935

Summary 938
Part V: Additional Subjects 939
Chapter 30: Localizing Flex 4 Applications....................... 941
Using Locales to Select Application Resources 941
Changing locales at compile time 943
Changing locales at runtime 944
Using Custom Resource Bundles 947
Creating resource bundles at runtime 947
Using external resource bundles 950
Summary 954
02_488959-ftoc.indd xxi02_488959-ftoc.indd xxi 3/5/10 2:17 PM3/5/10 2:17 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
xxii
Contents
Chapter 31: Deploying Desktop Applications with Adobe AIR ........ 955
Understanding AIR Architecture 956
Installing Adobe AIR 958
Downloading the AIR installer 958
Installing and uninstalling AIR on Windows 958
Installing and uninstalling AIR on Mac OS X 959
Creating a Flex Desktop Application 960
Creating a Flex desktop application project 960
Using the application descriptor file 963
Packaging a release version of an AIR application 967
Installing AIR applications 969
Uninstalling AIR applications 971
Flex Application Tips and Tricks with AIR 971
Debugging AIR applications in Flash Builder 972
Working with HTML-based content 973
Using the WindowedApplication component 977

Creating Remoting channels at runtime 978
A Conclusion about Adobe AIR 980
Summary 981
Index ................................................... 983
02_488959-ftoc.indd xxii02_488959-ftoc.indd xxii 3/5/10 2:17 PM3/5/10 2:17 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
xxiii
W
hen 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 ser-
vices, but would solve many of the nagging issues that had been inherent in browser-based appli-
cations since the mid-1990s. Using Flash Player to host graphically rich applications delivered as
Flash documents would address issues such as the ongoing differences between Web browsers in
implementation of Cascading Style Sheets (CSS) and JavaScript. And because such applications
would be able to leverage Flash Player’s original strengths, including animation and delivery of rich
media (audio and video) to the desktop, the applications could be both functional and visually
compelling.
The first push into the new frontier of RIAs met with mixed success. Many applications built and
delivered with Flash MX and ColdFusion MX (Macromedia’s recommended middleware applica-
tion server software at the time) were very impressive. Perhaps the best known of this class is the
iHotelier hotel reservations application, which is still used by many large hotels around the world.
The application presents customers with a Flash-based interface they can use to find and reserve
hotel rooms from a visually intuitive single-screen interface. A customer can input information and
get a nearly instantaneous response without having to navigate the multi-page interface of classic
HTML-based Web applications.
Meanwhile, developers who were creating these applications were madly pulling their hair out.
Building data-centric applications in Flash meant that they were working with a binary source file,
making it difficult to integrate with source control systems. At the time, ActionScript wasn’t partic-

ularly object-oriented (although this part of the situation improved drastically with the release of
ActionScript 2 in Flash MX 2004), and there was no enforcement of code placement standards. Its
loose data typing and lack of strong compile-time error checking or debugging tools led to phe-
nomena such as “silent failure” — the moment when something that’s supposed to happen doesn’t,
and no information is offered as to the reason.
In large multi-developer environments, figuring out where to put the code in a Flash document
was a significant part of the application planning process, because the product wasn’t really
designed for application development. And the ActionScript editor built into Flash gave experi-
enced developers fits. Java developers, in particular, were used to sophisticated code editors, and
working in Flash slowed their productivity and increased their frustration.
03_488959-fpref.indd xxiii03_488959-fpref.indd xxiii 3/5/10 2:17 PM3/5/10 2:17 PM
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.

×