Flex 3 with Java Develop Rich Internet applications using Adobe Flex 3 and ActionScript 3.0, and integrate them with a Java backend using BlazeDS 3.2 Satish Kore BIRMINGHAM - MUMBAI This material is copyright and is licensed for the sole use by Mauricio Esquenazi on 21st July 2009 10 Kenmare St. #4, , New York, , 10012Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Flex 3 with Java Copyright © 2009 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: June 2009 Production Reference: 1220609 Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK. ISBN 978-1-847195-34-0 www.packtpub.com Cover Image by Vinayak Chittar ( vinayak.chittar@gmail.com ) This material is copyright and is licensed for the sole use by Mauricio Esquenazi on 21st July 2009 10 Kenmare St. #4, , New York, , 10012Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Credits Author Satish Kore Reviewers Wim Bervoets Trevor Burton Acquisition Editor James Lumsden Development Editor Swapna Verlekar Technical Editor Dhiraj Bellani Copy Editor Sneha Kulkarni Indexer Hemangini Bari Editorial Team Leader Abhijeet Deobhakta Project Team Leader Lata Basantani Project Coordinator Neelkanth Mehta Proofreaders Laura Booth Lynda Sliwoski Production Coordinator Aparna Bhagat Cover Work Aparna Bhagat This material is copyright and is licensed for the sole use by Mauricio Esquenazi on 21st July 2009 10 Kenmare St. #4, , New York, , 10012Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. About the Author Satish Kore is a software engineer, an amateur blogger, and a dreamer based in a beautiful city Bangalore in India. He has worked on a variety of technologies including Adobe Flex, Java, and J2ME over the past eight years. He has always been passionate about Rich Internet application (RIA) technologies and loves working on Adobe Flex. He always enjoyed writing software applications and solving common problems using technology. You can keep up with his work by visiting his blog at http://blog.satishkore.com , or by following him on Twitter http://twitter.com/satishkore . I thank my family for being encouraging and supportive and special thanks to my friends for always inviting me on parties even though I constantly refused to join them by giving them the same boring reason that I am busy with writing. This book means a lot to me since I have spent all my weekends and free time writing this book for the past 6-7 months. However, this book would not have been possible without some individuals who have worked alongside me during the writing, reviewing, and publishing phases. I would thank James Lumsden for giving me the opportunity to write this book. I would also like to thank Neelkanth Mehta, Swapna Verlekar, Dhiraj Bellani, and all my technical reviewers for proofreading, reviewing, and rening the content of this book; without their efforts, this book wouldn’t have been completed. This material is copyright and is licensed for the sole use by Mauricio Esquenazi on 21st July 2009 10 Kenmare St. #4, , New York, , 10012Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. About the Reviewers Wim Bervoets is a Senior J2EE/Java software engineer and architect from Belgium, Europe, who helps organizations to implement complex web-based business applications. Since 2000, Wim Bervoets has specialized in developing and architecting web-based solutions in various companies and industries (for example, banks, pharmacy, and so on) and in various roles (as a lead developer, architect, consultant, designer, and so on). Since 2008, he has also started working with Adobe Flex RIA Technologies in combination with existing Java applications. Wim Bervoets is also no stranger to Web2.0, internet marketing and web site launches. He created successful international web sites, such as http://www. javablog.be —a blog about Java and Flex , http://www.dancevibes.be —a blog about music, and http://www.wimsbios.com —a site for PC tech enthusiasts. To contact Wim Bervoets, please email to wim@javablog.be or go to his blog at http://www.javablog.be . Trevor Burton is a software developer based in London, UK. He works primarily in Actionscript and Java. He has been working with Flash since the release of Flash 4 and Flex since the release of version 3 and has a wealth of experience developing Flash games from the banner advergames to multi-million pound online gambling applications. He currently works for Infrared5, developing a wide range of web applications. In his spare time, he experiments with multi-user interaction and human—computer interaction. This material is copyright and is licensed for the sole use by Mauricio Esquenazi on 21st July 2009 10 Kenmare St. #4, , New York, , 10012Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. This material is copyright and is licensed for the sole use by Mauricio Esquenazi on 21st July 2009 10 Kenmare St. #4, , New York, , 10012Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Dedicated to my beautiful wife, Archana. I remain thankful to her for being supportive and understanding. This material is copyright and is licensed for the sole use by Mauricio Esquenazi on 21st July 2009 10 Kenmare St. #4, , New York, , 10012Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. This material is copyright and is licensed for the sole use by Mauricio Esquenazi on 21st July 2009 10 Kenmare St. #4, , New York, , 10012Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Table of Contents Preface 1 Chapter 1: Installing and Configuring Adobe Flex 7 Installing open source Flex 3 SDK 8 Installation directory structure 8 About configuration files 9 Flex compilers 10 Using compc—the component compiler 10 Using mxmlc—the application compiler 11 Installing Flex Builder 3 12 Creating a Flex project 18 UI designer and source code editor 22 Flex LiveDocs 23 Summary 24 Chapter 2: Introduction to Flex 3 Framework 25 How Flex works 26 Compiling and running an application 26 About MXML 28 Understanding namespaces 29 Using namespaces in your code 30 Containers 31 Layout manager 31 Layout containers 34 Using Box, HBox, and VBox containers 35 Navigator containers 36 Form containers 38 Constraint-based layout 39 Using events in MXML 41 Creating custom events 44 This material is copyright and is licensed for the sole use by Mauricio Esquenazi on 21st July 2009 10 Kenmare St. #4, , New York, , 10012Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Table of Contents [ ii ] Validating and formatting data 45 Restricting user entry 50 Formatting 51 Data binding 52 Using the [Bindable] metadata tag 55 Creating MXML custom components 57 Understanding Flex itemRenderers 63 Drop-in itemRenderers 64 Inline itemRenderers 64 External itemRenderers 65 Summary 66 Chapter 3: Introduction to ActionScript 3.0 67 ActionScript 3.0 language features 67 Strict data typing 68 Runtime exceptions 68 Sealed classes and dynamic classes 68 Method closure 68 XML and E4X 68 New primitive data types 68 Regular expressions 69 Object-oriented programming 69 ActionScript 3.0 fundamentals 69 Variables 69 Access modifiers 71 Packages 71 Classes and interfaces 72 Classes 72 Interfaces 73 Implementing an interface in a class 73 Inheriting classes 74 Functions and methods 75 Named functions 76 Anonymous functions 76 Function parameters 77 Setter and getter methods 79 Flow control and looping 80 If/else statement 81 switch statement 81 Looping 82 Exceptions and error handling 84 try…catch…finally statements 84 Create your own custom Error class object 86 Reserved words and keywords 87 This material is copyright and is licensed for the sole use by Mauricio Esquenazi on 21st July 2009 10 Kenmare St. #4, , New York, , 10012Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. [...]... Summary The general anatomy of the application Let's start coding The Flex code The Java code Directories and files Summary 233 234 234 234 234 235 235 242 246 247 250 251 272 276 278 Index 279 [] This material is copyright and is licensed for the sole use by Mauricio Esquenazi on 21st July 2009 Please purchase PDF Split-Merge on www.verypdf.com10012 10 Kenmare St #4, , New York, , to remove this watermark... integration with Java and BlazeDS, styling and formatting, and how to package and deploy Flex applications Finally, this book provides a step-by-step tutorial for developing e-commerce applications using Flex 3, ActionScript 3. 0, BlazeDS, and Java You will start with downloading, installing, and configuring Flex 3 SDK and Flex Builder 3 and learn basic concepts, such as what is Macromedia Flex Markup... basics of Flex programming, that is, downloading, installing, and configuring Flex SDK and Flex Builder 3 Chapter 2: Introduction to Flex 3 Framework—This chapter will introduce you to the MXML scripting for laying out User Interfaces (UI) in the Flex world This chapter also provides hands-on examples required to get you started with MXML programming Chapter 3: Introduction to ActionScript 3. 0—This... purchase PDF Split-Merge on www.verypdf.com10012 10 Kenmare St #4, , New York, , to remove this watermark Installing and Configuring Adobe Flex In this chapter, you will learn how to install and configure Basic Flex 3. 0 SDK (Software Development Kit) and Flex Builder 3 The Adobe Flex SDK contains everything you need to build and deploy Flex Rich Internet applications (RIAs) You can write Flex programs... http://www.adobe.com/support/documentation/en /flex/ 3/ releasenotes_ flex3 _fb.html for installation instructions This material is copyright and is licensed for the sole use by Mauricio Esquenazi on 21st July 2009 Please purchase PDF Split-Merge on www.verypdf.com10012 10 Kenmare St #4, , New York, , to remove this watermark Installing and Configuring Adobe Flex Installing open source Flex 3 SDK Flex SDK comes in different... book, I will be using this Flex Builder IDE for demonstrating Flex code examples Also, make a note that if you are installing Flex Builder 3, then you need not install Flex SDK separately because Flex Builder 3 installs Flex SDK automatically as a part of its installation You will learn more about the directory structure that the installer creates when you install Flex Builder in Flex Builder installation... specialized IDE for developing and designing Flex applications known as Flex Builder Flex Builder is built on top of Eclipse platform So if you are familiar with the Eclipse development paradigm, it will be very easy for you to use Flex Builder Although you do not need Flex Builder to write and compile Flex applications, Flex Builder does facilitate development with powerful tools, such as debugger, profiler,... source Flex SDK, Flex Builder is a licensed product from Adobe which you need to buy But you can download a 60-day evaluation copy from Adobe's web site at http://www.adobe.com/go /flex_ trial Flex Builder 3 is available on Windows, Mac OS, and Linux operating systems Flex Builder comes with two different installation options They are: • Flex Builder as a standalone IDE: This option installs Flex Builder... Please purchase PDF Split-Merge on www.verypdf.com10012 10 Kenmare St #4, , New York, , to remove this watermark Chapter 1 Once the installation is finished, you can launch Flex Builder 3 from Windows | Program Files | Adobe | Flex Builder 3 Adobe has a unique program called Free Flex Builder Pro for Education, where students and faculties can get a free licensed copy of Flex Builder 3 Professional... possible with typical web technologies, such as HTML Flex 3 is a leading technology for developing RIAs for the Web, as well as for the desktop This book gives you an insight into, and provides a hands-on experience in, programming in Flex 3 by utilizing your existing knowledge of Java programming This book includes comprehensive information on various concepts of Flex 3 and ActionScript 3. 0, such . Flex 3 with Java Develop Rich Internet applications using Adobe Flex 3 and ActionScript 3. 0, and integrate them with a Java backend using BlazeDS 3. 2. Summary 231 Chapter 12: Internationalization and Localization 233 Internationalization (i18n) and localization (l10n) 233 Language 234 Assets 234 Culture 234