Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Flex Developer Center / Flex Test Drive /

Flex Test Drive: Build an application in an hour

by Adobe

Adobe logo

Modified

2 May 2011

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
Flash Builder Flex RIA

Video | Code | Tutorial | Links

Note: Flex Test Drive requires Flex 4.5 SDK and Flash Builder 4.5; download a 60-day trial version of Flash Builder 4.5 before continuing if you haven't already.

Build the user interface

 

This content requires Flash To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player. To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.
  • Download Flash Builder 4.5 Trial
  • Download the Test Drive solution files (ZIP, 14 MB)

Code

<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> <s:Label x="50" y="50" color="maroon" fontSize="20" fontWeight="bold" text="XYZ Corporation Directory"/> <s:Button id="empBtn" x="50" y="100" label="Employees"/> <s:Button id="deptBtn" x="140" y="100" label="Departments"/> <s:DataGrid id="empDg" x="50" y="130" requestedRowCount="4"> <s:columns> <s:ArrayList> <s:GridColumn dataField="dataField1" headerText="Column 1"></s:GridColumn> <s:GridColumn dataField="dataField2" headerText="Column 2"></s:GridColumn> <s:GridColumn dataField="dataField3" headerText="Column 3"></s:GridColumn> </s:ArrayList> </s:columns> <s:typicalItem> <fx:Object dataField1="Sample Data" dataField2="Sample Data" dataField3="Sample Data"></fx:Object> </s:typicalItem> <s:ArrayList> <fx:Object dataField1="data1" dataField2="data1" dataField3="data1"></fx:Object> <fx:Object dataField1="data2" dataField2="data2" dataField3="data2"></fx:Object> <fx:Object dataField1="data3" dataField2="data3" dataField3="data3"></fx:Object> <fx:Object dataField1="data4" dataField2="data4" dataField3="data4"></fx:Object> </s:ArrayList> </s:DataGrid> </s:Application>

Tutorial

In this Test Drive, you are going to create a Flex application that retrieves, displays, and modifies database records (see Figure 1). A Flex application does not connect directly to a remote database. Instead, you connect it to a data service written in your favorite web language (PHP, ColdFusion, Java, or any other server-side web technology).  You will build the front-end Flex application; the database and the server-side code to read, add, edit, and delete database records is provided for you as a PHP class, a ColdFusion component, or Java classes.

The completed Test Drive application.
Figure 1. The completed Test Drive application.

In this module, you are going to build a Flex project and a Flex application that retrieves data from the database and displays it. Employee data will be displayed on one "page" in the application and Department data on another.

The first task is to create a new Flex project for your application server and create the user interface. You'll retrieve data from the server and display it in the next tutorial.

Step 1: Install the server files on a local application server.

Follow the instructions in one of the sections below.

  • Setup for PHP
  • Setup for ColdFusion
  • Setup for Java

The setup files include a database and server-side files to manipulate data in the database. Your Flex application will call methods of one of these server-side files, EmployeeService.

Note: If you installed the server files for the Flex 4.5 Test Drive for Mobile (add link) or  the Flex 4.5 trial email sample applications, you can skip this step. The same server-side files are used for all three.

Setup for PHP

  1. Download the Test Drive setup archive (ZIP; 15.7 MB) archive and unzip  testdrive_setup_PHP file. It contains a Database and a Test Drive folder.
  2. Create a testdrive_db database on your MySQL installation using the testdrive_db.sql file located in the Database folder. If you do not have permissions to create a database, use the testdrive_table.sql file instead to create two tables in an existing database. After the database is created, set user privileges for it.
  3. Move the TestDrive folder, which contains the PHP service file, to your PHP server.
  4. Open /TestDrive/test/test.php in an editor and change the username, password, server, and database name properties to the correct values for your server setup. Test the setup by browsing to http://{your server:your port}/TestDrive/test/test.html. For example, browse to http://localhost/TestDrive/test/test.html. You should see a list of the names of the employees in the database successfully displayed.
  5. Open /TestDrive/services/EmployeeService.php in an editor and change the username, password, server, port, and databasename properties to the correct values for your server setup. This class file contains the methods you will call from your Flex application.

Setup for ColdFusion

  1. Download the Test Drive setup archive (ZIP; 15.7 MB) archive and unzip the testdrive_setup_CF file. It contains two CAR files (testdrive_mac.car and testdrive_win.car) and a ZIP file (testdrive.zip).
  2. If you have ColdFusion Enterprise or ColdFusion Developer, deploy one of the CAR files.
    o    In the ColdFusion Administrator (http://localhost:8500/CFIDE/administrator/ for the default standalone installation), navigate to Packaging & Deployment > ColdFusion Archives and browse to and deploy one of the CAR files.
    o    In the Deploy Wizard, change the deploy locations to reflect the locations of the db and wwwroot folders on your server. For example, on a Mac: /Applications/ColdFusion9/wwwroot/TestDrive and  /Applications/ColdFusion9/db/testdrive or on Windows: C:\ColdFusion9\wwwroot\TestDrive and C:\ColdFusion 9\db\testdrive.
    o    After deploying, check that you have a new data source called testdrive_db and a new folder in wwwroot called TestDrive. If your datasource verification fails, delete the datasource and recreate it: testdrive_db, Apache Derby Embedded, and point to the /ColdFusion/db/testdrive database just installed. 
  3. If you have ColdFusion Standard, you need to manually place the server files and create a datasource.
    o    Unzip testdrive.zip. It contains TestDrive and db folders.
    o    Place the TestDrive folder in the ColdFusion webroot, /ColdFusion/wwwroot/.
    o    Open the db folder. It contains a folder called testdrive.
    o    Place this testdrive folder in the ColdFusion db folder, /ColdFusion/db/.
    o    In the ColdFusion Administrator (http://localhost:8500/CFIDE/administrator/ for the default standalone installation), navigate to Data & Services > Data Sources and create a new data source called testdrive_db with an Apache Derby Embedded driver and the database folder set to the testdrive folder you just placed in the /ColdFusion/db/ folder.
  4. Open /ColdFusion/wwwroot/TestDrive/services/EmployeeService.cfc in an editor and examine the code. This class file contains the methods you will call from your Flex application. Note that the methods have the access argument set to remote so that they can be called from a Flex application.
  5. Open /ColdFusion9/wwwroot/WEB-INF/flex/services-config.xml in an editor. This file is used when calls are made to the server from your application. Locate the <property-case> tag and change all three values to true as shown below:
<property-case> <!-- cfc property names --> <force-cfc-lowercase>true</force-cfc-lowercase> <!-- Query column names --> <force-query-lowercase>true</force-query-lowercase> <!-- struct keys --> <force-struct-lowercase>true</force-struct-lowercase> </property-case>

    Note: If you are using an earlier version of ColdFusion, your configuration file may not have these tags and you will need to add them. For details, refer to the documentation on using Flash Remoting with your particular server.

  1. Restart the ColdFusion server.
  2. Test the setup by browsing to:

    http://{your server:your port}/TestDrive/test/test.html

    For a default standalone ColdFusion installation, browse to:

    http://localhost:8500/TestDrive/test/test.html

    You should see employee data from the database successfully displayed in a datagrid.

Setup for Java

  1. Download the Test Drive setup archive (ZIP; 15.7 MB) archive and unzip the testdrive_setup_JAVA file. It contains a WAR file for a web application called testdrive.
  2. Deploy the WAR file to your web server. It contains the Java classes, an Apache Derby embedded database, and BlazeDS 4 files.
  3. Open /{your server wepapps folder}/testdrive/WEB-INF/src/services/EmployeeService.java in an editor. This class file contains the methods you will call from your Flex application. It must have a no argument constructor.

    Note: For Windows, the ConnectionHelper.java file assumes the testdrive web app is deployed on the C drive. If it is not deployed on the C drive, you need to modify this file appropriately and recompile it, replacing /{your server webapps folder}/testdrive/WEB-INF/classes/services/ConnectionHelper.class.

  4. Open /WEB-INF/flex/remoting-config.xml in an editor and examine the code. This file is used when calls are made to the server from your application. Note the definition for the destination called employeeService which points to the services.EmployeeService class.
  5. Test the setup by browsing to:

    http://{your server:your port}/testdrive/test/test.html

    For example, for the BlazeDS turnkey server, browse to:

    http://localhost:8400/testdrive/test/test.html

    You should see employee data from the database successfully displayed in a datagrid.

Step 2: Create a new Flex project.

Follow the instructions in one of the sections below.

  • Project settings for PHP with Flash Builder 4.5 for PHP
  • Project settings for Java, ColdFusion, or PHP with Flash Builder 4.5

Project settings for PHP with Flash Builder 4.5 for PHP

  1. In Flash Builder 4.5 for PHP, select File > New > Flex and PHP Project and create a PHP project called TestDrive at an existing location (see Figure 2). Be sure to set the location to where you saved the TestDrive folder on your PHP server in step 1.
  2. Set the appropriate server location settings (see Figure 2) and validate the configuration. Example settings for a Zend server on a Mac are shown in the figure; be sure to use the correct values for your specific PHP server (it doesn't have to be Zend), including the correct web root and url for it!
Create a new PHP project with Flash Builder 4.5 for PHP.
Figure 2. Create a new PHP project with Flash Builder 4.5 for PHP.
  1. Click the Next button and create a Flex project called FlexWebTestDrive and store the project files locally (see Figure 3). You can usually use the default value for the output folder, which is where the compiled application and associated files will be stored on your application server.
Create a new Flex project with Flash Builder 4.5 for PHP.
Figure 3. Create a new Flex project with Flash Builder 4.5 for PHP.

Project settings for Java, ColdFusion, or PHP with Flash Builder 4.5

  1. In Flash Builder 4.5, select File > New > Flex Project and create a Flex project called FlexWebTestDrive and store the project files locally (see Figure 4).
Create a new Flex project with Flash Builder 4.5.
Figure 4. Create a new Flex project with Flash Builder 4.5.
  1. Click the Next button and select your application server,  set the appropriate server location settings (see Figures 5 and 6), and validate the configuration. Example settings for Java with BlazeDS and ColdFusion servers are shown in the figures; be sure to use the correct values for your server setup! You can usually use the default value for the output folder, which is where the compiled application and associated files will be stored on your application server.
Specify Java server settings.
Figure 5. Specify Java server settings.
Specify ColdFusion server settings.
Figure 6. Specify ColdFusion server settings.

Step 3: Examine the generated project(s) and files.

Use the Package Explorer to explore the generated project(s) and files.

When you create a new Flex project, Flash Builder creates an MXML file with the same name as the project (see Figure 7). This is the main application file where you add your code. You create Flex applications using two languages: ActionScript and MXML. Typically, you use MXML and Flex components to create application interfaces and ActionScript and events to program application logic. MXML tags and ActionScript code can reference each other, similar to HTML tags and JavaScript code.

 Explore the FlexWebTestDrive.
Figure 7. Explore the FlexWebTestDrive.

In FlexWebTestDrive.mxml, the first line of code is the XML declaration for the parser. The next line is the <s:Application> tag, which defines the Application container that must be the root tag for a Flex application. When the application is compiled, a SWF file, an HTML wrapper page that references the SWF file, and other files are created and placed in the bin-debug folder on your application server so you can browse to the application. When you browse to the HTML file that references the application SWF, the SWF file is downloaded and rendered by Flash Player (available as a browser plugin or ActiveX control).

If you created a Flex and PHP project with Flash Builder 4.5 for PHP, you will also have a PHP project (see Figure 8) for viewing and modifying your PHP code.

Explore the PHP TestDrive project.
Figure 8. Explore the PHP TestDrive project.

Step 4: Use Design mode to add components and set properties.

Switch to Design mode and drag out Label, DataGrid, and Button components from the Components view to create the interface shown in Figure 9. Use the Properties view to assign component ids of empBtn, deptBtn, and empDg and set other properties.

Arrange components as shown here.
Figure 9. Arrange components as shown here.

HTML applications are built from document elements such as headings, paragraphs, and tables. Flex applications are built from components such as Buttons, CheckBoxes, and DataGrids. The Flex 4.5 framework includes over 100 components, including user interface controls to display content and provide user interaction and containers to manage the layout.

Switch to Source mode and take a look at the generated code. You will see a new tag for each of the components you added. The order of the tags does not matter because the Application container uses absolute positioning by default so component positions are set by their x and y properties.

The <s:Label> tag represents a Label control, a very simple user interface component that displays text. Its text property is set to "XYZ Corporation Directory" and its x and y properties are set to where it will appear in the interface. The color, fontSize, and , and fontWeight attributes change the style of the font used. In Flex, you can set color styles to a string for any of the 16 colors in the VGA color set (for example, red or blue) or an RGB triplet in hexadecimal format (for example, #FF0000 or #0000FF).

<s:Label x="50" y="50" text="XYZ Corporation Directory" color="maroon" fontSize="20" fontWeight="bold"/>

For each component, you can specify properties and styles. Properties apply only to that particular component instance. Styles can be set inline as done here or using CSS to create style rules to apply to your components.

Step 5: Change component attributes in MXML.

Use the Flash Builder Content Assist to select and set values for various properties and styles.

When you place your cursor inside a tag and press the spacebar or Ctrl+spacebar, you get code hinting with the Flash Builder Content Assist (see Figure 10). It shows a list of all the attributes you can set for that tag, including properties, styles, events, and more. Different symbols are used for each different type of attribute. This is the same list you see in the Alphabetical view of the Design mode Properties view.

Use Content Assist to see a list of all possible tag attributes.
Figure 10. Use Content Assist to see a list of all possible tag attributes.

You can get more complete descriptions for each of the attributes in the component's API, its application programming interface. To navigate to a component's API, select Help > Dynamic Help and then click a component tag in your code. You will see a link to that component's API in the Help view, which you click to open the API (see Figure 11).

View a component's API.
Figure 11. View a component's API.

Step 6: Browse the application.

Use the Run button or the Run menu to compile the application and view it in an HTML page in a browser window.

Your application appears in the browser inside a generated HTML wrapper page (see Figure 12).

View the application in a browser.
Figure 12. View the application in a browser.

PHP developers using Flash Builder for PHP: The first time you run an application, you get a Run As dialog box. If you select Web Application, an HTML wrapper file is run. If you select Web (PHP) Application, a PHP wrapper file is run. The code for both files is the same so you can choose either option. If you want to debug your PHP service code when running this application (debugging is covered in Debug client-side code), you need to launch a PHP wrapper page, so choose Web (PHP) application. You can change which file is run at any time by selecting Run > Run As > Web (PHP) Application or Web Application or creating run configurations.

You will retrieve and display data in the DataGrid in the next tutorial and add application "pages" and wire up the buttons later.

Learn more

Refer to the following resources to learn more about this topic:

Documentation: Using Flash Builder 4.5

  • Working with projects
  • Building a user interface with Flash Builder

Documentation: Using Flex 4.5

  • Developing applications in MXML
  • Building the user interface

ActionScript 3 Reference

  • Label
  • Button

Flex Developer Center

  • Flex Quick Starts

Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License+Adobe Commercial Rights

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

More Like This

  • Flex Test Drive: Modify the database
  • Flex Test Drive: Build an application in an hour
  • Flex Test Drive: Build an application in an hour
  • Flex Test Drive: Modify the database
  • Flex Test Drive: Add charts and graphs
  • Flex Test Drive: Build an application in an hour
  • Flex Test Drive: Change the appearance of your application
  • Flex Test Drive: Change the appearance of your application
  • Flex Test Drive: Add charts and graphs
  • Flex Test Drive: Test and debug your code

Tutorials and samples

Tutorials

  • Flex mobile performance checklist
  • Flex and Maven with Flexmojos – Part 3: Journeyman
  • Migrating Flex 3 applications to Flex 4.5 – Part 4

Samples

  • Twitter Trends
  • Flex 4.5 reference applications
  • Mobile Trader Flex app on Android Market

Flex user forum

More
07/25/2011 Flash Player Debug Issues - Safari 5.1 & Chrome 13
04/22/2012 Loader png - wrong color values in BitmapData
04/22/2012 HTTPService and crossdomain.xml doesn't work as expected
04/23/2012 Memory related crashes in Flex application

Flex Cookbook

More
04/06/2012 How to detect screen resize with a SkinnableComponent
02/29/2012 Embed Stage3D content inside Flex application components
02/15/2012 Custom WorkFlow Component
02/09/2012 Using Camera with a MediaContainer instead of VideoDisplay

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement