Book Image

Flex 3 with Java

Book Image

Flex 3 with Java

Overview of this book

Flex 3 is a great technology for developing Rich Internet Applications for the Web as well as for the desktop. If you are a developer looking to design great-looking and sophisticated user interfaces that resemble desktop-based applications, and want to utilize an existing server technology such as Java to develop RIAs, this book is for you. Targeting developers who want to get started with Adobe Flex 3 programming, this simple and clear handbook introduces Flex technology quickly and straightforwardly. Utilizing your existing knowledge of Java, it gives you the insight and hands-on experience to program with Flex 3. This book provides comprehensive information on various aspects of Flex 3 and ActionScript 3.0. These include developing simple applications, handling events, creating custom components and events, using RPC services, integration with Java and BlazeDS, styling and formatting, and how to package and deploy Flex applications. You will start with downloading, installing and configuring Flex 3 SDK and Flex Builder 3 and learn basic concepts such as what MXML and ActionScript are, understanding UI components, controls, compilers, and more. Further you will develop simple applications and slowly advance into more depth where you will learn advanced concepts such as creating custom components, debugging, integrating with Java, using RPC services, styling, internationalizing, and deploying Flex applications, and more. One of the things you're really going to love about this book is that you will develop a full-blown e-commerce application using a combination of Flex 3, ActionScript 3.0, BlazeDS 3.2, and Java. At the end of the book you will have the knowledge and experience needed to develop Rich Internet Applications.
Table of Contents (18 chapters)
Flex 3 with Java
Credits
About the Author
About the Reviewers
Preface
8
Communicating with Server-side Java

Installing open source Flex 3 SDK


Flex SDK comes in different types such as licensed Free Adobe Flex SDK (with a mixture of open source and closed open source components) and open source Flex SDK. The latter package contains entirely open source components under the Mozilla Public License version 1.1 (MPL) agreement, which includes its binaries. To know more about the available types of SDKs, visit http://opensource.adobe.com/wiki/display/flexsdk/Downloads. In this chapter, I will cover open source Flex SDK as an example.

In order to install Flex 3 SDK, download the latest open source SDK from Adobe's web site at http://opensource.adobe.com/flex/. Adobe is continuously working on improving and fixing bugs in Flex SDK and they release nightly builds on a regular basis. You can download them from http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+3 and install them in order to stay updated with the latest feature and bug fixes in Flex 3 SDK.

Note

At the time of writing this book, Adobe was actively working on Flex 4, code named Gumbo. For more information, you can visit http://opensource.adobe.com/wiki/display/flexsdk/Gumbo .

Installation directory structure

Once you have downloaded the latest SDK in a ZIP format, extract it at your desired location, for example, C:\Flex3.1_SDK. That's it; you are done with the Flex SDK's installation. Now before you jump into coding, let's first understand the Flex SDK's installation directory structure.

When you install Flex SDK, the installer creates the following directory structure under the installation directory:

Directory

Description

/ant

Contains the Flex Ant tasks, which provide a convenient way to build your Flex projects

/asdoc

Contains ASDoc, a command-line tool that you can use to create API language reference documentation as HTML pages from the classes in your Flex application

/bin

Contains the executable files, such as the mxmlc and compc compilers

/frameworks

Contains configuration files, such as flex-config.xml and default.css

/frameworks/libs

Contains the library (SWC files); you use the files to compile your application

/frameworks/locale

Contains the localization resource files.

/frameworks/projects

Contains the Flex framework source code

/frameworks/rsls

Contains the Runtime Shared Libraries (RSLs) for the Flex framework

/frameworks/themes

Contains the theme files that define the basic look and feel of all Flex components

/lib

Contains JAR files

/runtimes

Contains the standard and debugger versions of Adobe ® Flash® Player and the Adobe® AIR™ components

/samples

Contains sample applications

/templates

Contains template HTML wrapper files

In order to compile your Flex application, you need to set your bin folder in the Windows PATH environment variable under your System settings, so that you can use mxmlc and compc compilers from your project root folder.

About configuration files

There are a couple of important configuration files that you need to be aware of before you start using SDK. They are as follows.

The flex-config.xml file defines the default compiler options for the compc and mxmlc command-line compilers. You can set and tweak many compiler- and application-related configuration parameters in the flex-config.xml file located under the sdk_install_directory/frameworks/ folder such as namespaces, library path, accessibility, and locale for application internationalization.

All of the Flex component names are defined in the mxml-manifest.xml file. This manifest file maps Flex component namespaces to class names with complete package names. This is similar concept as XML namespaces. The mxml-manifest.xml file is used to avoid element name conflicts and it also helps in organizing your source files. Don't worry about these files right now. You will learn more about them and their usage in a better manner further in the book.

Example:

<?xml version="1.0"?>
<componentPackage>
<component id="HelloLabel" class="usa.hello.HelloLabel"/>
<component id="NamasteLabel" class="ind.namaste.NamasteLabel"/>
</componentPackage>

In a manifest file, the id property of each<component> tag must be unique. That id is the name you use for the tag in your Flex applications, for example:

<local:HelloLabel label="Hello!"/>

You will learn more about how to use namespaces in Chapter 2 of this book.

The Flex compiler requires Java Runtime Environment (JRE) to compile Flex source code; configuring Java Virtual Machine (JVM) parameters can actually result in much faster and optimized compilation in some cases. Without JRE you cannot use Flex compilers, such as mxmlc and compc.

You can configure JVM settings in the jvm.config file, which is typically located under the sdk_install_dir/bin folder. The most common JVM configuration you may ever need is the JVM heap size. The Java heap is the amount of memory reserved for a particular JVM instance for faster performance; for example:

java.args=-Xms256m -Xmx512m