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 /

Using web services with Data Centric Development in Flash Builder 4 beta

by Srinivas Annam

Srinivas Annam
  • srinivasannam.wordpress.com

Modified

21 December 2009

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
Flash Builder web services

Requirements

Prerequisite knowledge

Previous experience with Flex Builder, Flash Builder, or web services will be helpful, but it is not necessary.

User level

Beginning

Required products

  • Flash Builder (Download trial)

Sample files

  • ZenfolioProject.zip (104 KB)

Data-centric development is an exciting new Rapid Application Development (RAD) feature in Flash Builder 4, which helps traditional web and novice Flex developers to quickly build rich data-centric Flex applications that fetch data from various back-ends including ColdFusion, PHP, BlazeDS, LiveCycle Data Services ES, web services, and HTTP services.

Because web services are such a popular mechanism for exchanging data between different applications and platforms on the Internet, Flash Builder 4 provides easy and efficient ways to import, explore, and use web services. Through its unified workflow wizards, Flash Builder 4 helps developers quickly build Rich Internet Applications that leverage existing corporate or public service infrastructures, including web services.

In this article, I will demonstrate these capabilities by showing you how to build an application (see Figure 1) that uses Zenfolio's web service to display photos.

The sample application
Figure 1. The sample application

Importing the web service

Note: The sample file ZenfolioProject.zip contains the complete source code for the project. Following the steps in this tutorial will result in a complete application, but you can download the sample file as a reference.

Follow these steps to create a new Flex project and import the Zenfolio web service.

  1. Choose File > New > Flex Project
  2. Type a name for the project, for example ZenfolioApp.
  3. For the Application Type select Web, and for the Application Server Type select None/Other.
  4. Click Finish.
  5. Choose Data > Connect To Web Service.
  6. In the dialog box that appears, type http://www.zenfolio.com/api/1.0/zfapi.asmx?WSDL as the WSDL URI. This is the URI of the WSDL file for Zenfolio's web service.
  7. For the Service Name, type ZenfolioService. This is the name that you can use to refer to this service within the current project.
  8. For the Service Package, type services.zenfolioservice. This is the name of the package (folder) in which Flash Builder will generate the required ActionScript classes.
  9. For the Data Type Package, type valueObjects. This is the name of the package in which Flash Builder will generate the required ActionScript files for the custom data types used by this service.
  10. Click Next.

    Flash Builder will introspect the WSDL file and present a list of services, ports, and operations supported by the service.

    Note: A single WSDL file can contain multiple ports for different endpoints exposed over different protocols. The web service wizard in Flash Builder 4 supports the SOAP 1.1 protocol. For this particular WSDL file, the selected port will be ZfApiHttpGet, and as a result you'll see the following notification in the dialog box, “Selected WSDL port is not compliant with SOAP 1.1 protocol. Operations and Entities cannot be read from this port. Please select a different port.”

  11. Select ZfApiSoap as the Port.

    You are presented with a list of web service operations that you can use in this service.

  12. Click Select All for now, and then click Finish.

That's all there is to it. You have just finished importing the Zenfolio web service into your Flex project.

Exploring the web service

Follow these steps to explore the web service you just imported.

  1. Choose Window > Data/Services to display the Data/Services view.
  2. In the Data/Services panel, expand the ZenfolioService service to see the Data Types node and a list of operations. The operations are listed with input argument names, argument types, and return types. You can also expand Data Types to see the custom data types used by the service and the corresponding data structure.
  3. Locate GetPopularPhotos(), the method you will use in this tutorial (see Figure 2).

The GetPopularPhotos() method takes two int parameters, offset and limit, and returns an array of Photo objects.

The Photo custom data type is defined inside the service, and you can see its data structure under the Data Types node of ZenfolioService or by expanding any operation that returns a Photo type.

Web service operations in the Data/Services panel
Figure 2. Web service operations in the Data/Services panel

Connecting components to data

Now that you've seen the operations provided by the web service, you can create a simple UI that will use those operations.

The UI should include the following components:

  • A List to display the list of popular photos with ID lstPhotos
  • An Image to display the high resolution version of the selected image with ID imgPhoto
  • A NumericStepper to enable the user to set the number of photos to display per page
  • A Header and appropriate background color (for example #787878) to make the application attractive
A basic UI for the sample application
Figure 3. A basic UI for the sample application

You can create the UI shown in Figure 3 by copying the following code into ZenfolioApp.mxml:

<s:Rect radiusX="8" radiusY="8" height="67" width="194" x="11" y="17" fill="{new mx.graphics.SolidColor(0x000000,1)}"/> <s:Label x="21" y="34" text="Zenfolio" color="#FFFFFF" fontSize="42"/> <s:Rect radiusX="8" radiusY="8" height="36" width="153" x="181" y="48" fill="{new mx.graphics.SolidColor(0x000000,1)}"/> <s:Label x="189" y="58" text="Popular Photos" color="#00DEFF" fontSize="20"/> <s:Line y="100" x="0" width="100%" stroke="{new mx.graphics.Stroke(0xFFFFFF,1)}"/> <s:List id="lstPhotos" x="10" width="152" contentBackgroundColor="#787878" borderAlpha="0" bottom="10" top="120"> </s:List> <s:Group bottom="10" right="10" left="170" top="120"> <mx:Image id="imgPhoto" horizontalCenter="0" verticalCenter="0"/> </s:Group> <s:Group height="35" width="152" top="57" right="10"> <s:Rect radiusX="8" radiusY="8" width="100%" height="100%" fill="{new mx.graphics.SolidColor(0x000000,1)}"/> <s:Label x="9" text="Per Page" fontSize="14" color="#FFFFFF" y="11"/> <s:NumericStepper id="nsResults" x="76" minimum="10" maximum="200" stepSize="5" value="50" y="6"/> </s:Group>
  •  Switch to Design view.
  • To display the Photo array returned by GetPopularPhotos() in the List component, drag-and-drop the GetPopularPhotos() operation from the Data/Services panel to the List component.

    Note: You can use several alternative approaches for this step. You can right-click the List component and select Bind To Data from the context menu. Or, you can select the List component and then click the Bind To Data icon next to the Data Provider in the Properties panel or click the Bind To Data icon in the Data/Services panel.

  • In the Bind To Data dialog box that appears, select GetPopularPhotos as the Operation and select Title as the Bind To Field setting.
  • Click OK.
  • After Flash Builder 4 generates the required code and switches to Source view, type 1,nsResults.value as the parameters to the GetPopularPhotos() call as shown below:
protected function lstPhotos_creationCompleteHandler(event:FlexEvent):void { GetPopularPhotosResult.token = zefolioService.GetPopularPhotos(1,nsResults.value); }

 

The generated code in ZenfolioApp.mxml calls the web service operation on the creationComplete event of the List component.

The GetPopularPhotos() operation expects two arguments, and you can pass static values or bind them to other UI components. In this case, you are passing 1 as the offset and nsResults.value (the value set in the NumericStepper control) as the limit.

Defining interactions

If you run the project (choose Run > Run ZenfolioApp), you'll see that the photo titles are displayed in the List control, but no photos are displayed even if you select them.

Note: Calls to the web service may take several seconds to complete; some patience is required.

Follow these steps to add a change event handler on the List control that will display the image whenever the user selects an item.

  1. In Design view, right-click the List component and select Generate Change Handler from the context menu.
  2. Edit the lstPhotos_changeHandler() method that was generated as shown below to get the URL of the selected image and assign it to imgPhoto.source:
protected function lstPhotos_changeHandler(event:IndexChangeEvent):void { imgPhoto.source = "http://www.zenfolio.com/" + lstPhotos.selectedItem.UrlCore + "-4.JPG"; }
  •  Choose Run > Run ZenfolioApp, and you will see the high-resolution image displayed when you select an item from the list.
  • To display a thumbnail along with the title of the photo as shown in Figure 1, add an itemRenderer for the List control. In Source view, replace the code for the existing List control with the following MXML code:
<s:List id="lstPhotos" x="10" width="152" contentBackgroundColor="#787878" borderAlpha="0" bottom="10" top="120" creationComplete="lstPhotos_creationCompleteHandler(event)" dataProvider="{GetPopularPhotosResult.lastResult}" labelField="Title" change="lstPhotos_changeHandler(event)"> <s:itemRenderer> <fx:Component> <s:ItemRenderer height="100" width="90%" buttonMode="true"> <s:Group height="90" width="90%"> <s:Rect radiusX="8" radiusY="8" width="100%" height="100%" fill="{new mx.graphics.SolidColor(0x000000,1)}"/> <mx:Image y="5" source="{'http://www.zenfolio.com' + data.UrlCore + '-1.jpg'}" horizontalCenter="0"/> <s:Label text="{data.Title}" y="74" color="0xFFFFFF" width="100%" height="12" textAlign="center"/> </s:Group> </s:ItemRenderer> </fx:Component> </s:itemRenderer> </s:List>

Where to go from here

Data-centric development in Flash Builder 4 helps developers quickly build Rich Internet Applications through unified workflows across various back-end technologies. It enables novice developers to get started quickly, and helps experienced developers be more productive. Data-centric development also makes advanced development methods like client side data management, paging, form generation, and chart generation easier for all Flex developers.

For more information on DCD see my introductory blog post on the topic and Tim Buntel's article Data-centric development with Flash Builder 4 beta. Sujit Reddy G also covers DCD in Flash Builder 4 on his blog.

As next steps for the sample application, you may want to add an event handler to the NumericStepper control to implement the results per page feature, or add Next and Previous buttons to navigate to all the photos from Zenfolio.

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License

More Like This

  • Creating a rich buying experience with a data-driven RIA
  • Building a simple dashboard using Flex 3 with ILOG Elixir
  • Building web service clients with Flex Builder 3

Tutorials & 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