For the complete experience, please enable JavaScript in your browser. Thank you!

  • Creative Cloud
  • Photoshop
  • Illustrator
  • InDesign
  • Premiere Pro
  • After Effects
  • Lightroom
  • See all
  • See plans for: businesses photographers students
  • Experience Cloud
  • Advertising Cloud
  • Analytics Cloud
  • Marketing Cloud
  • See all solutions for enterprise
  • Experience Manager Campaign Analytics Audience Manager
  • Document Cloud
  • Acrobat DC
  • Sign
  • Stock
  • Elements
  • Acrobat Reader DC
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player
  • All products
  • Creative Cloud
  • Individuals
  • Photographers
  • Students and Teachers
  • Business
  • Schools and Universities
  • Creative Cloud
  • Experience Cloud
  • Document Cloud
  • Stock
  • Elements
  • All products
  • Get Support
    Find answers quickly. Contact us if you need to.
    Start now >
  • Learn the apps
    Get started or learn new ways to work.
    Learn now >
  • Ask the community
    Post questions and get answers from experts.
    Start now >
Adobe is changing the world through digital experiences. Our creative, marketing and document solutions empower everyone — from emerging artists to global brands — to bring digital creations to life and deliver them to the right person at the right moment for the best results.
    • About Us
    • Newsroom
    • Careers At Adobe
    • Privacy
    • Security
    • Corporate Responsibility
    • Customer Showcase
    • Investor Relations
    • Events
    • Contact Us
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:
vat included
Subtotal
Promotions
Estimated shipping
Tax
Calculated at checkout
Total
Review and Checkout
Adobe Developer Connection / Flash Builder Developer Center /

Building a data-centric application with Flash Builder for PHP – Part 1: Setting up and connecting

by Ryan Stewart

Ryan Stewart
  • blog.digitalbackcountry.com

Content

  • An overview of Flash Remoting
  • Setting up
  • Your first Flex/PHP application
  • Connecting to the PHP service
  • Connecting service operations to the UI

Created

4 May 2011

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
data managementdata-centric developmentDataGridPHPRIA
Was this helpful?
Yes   No

By clicking Submit, you accept the Adobe Terms of Use.

 
Thanks for your feedback.

Requirements

Prerequisite knowledge

Some experience with Flash Builder and PHP is required.

User level

Intermediate

Required products

Sample files

  • fbphp_demo.zip

Additional required other products

  • Apache with PHP installed
  • MySQL (This tutorial uses MAMP.)

Flash Builder for PHP builds upon the features introduced in Flash Builder 4 to make it easy to connect to PHP servers and bring data into your Flex applications. Created in cooperation with Zend, Flash Builder for PHP brings the best of Flash Builder and Zend Studio together to streamline the process of connecting, debugging, and optimizing your Flex and PHP applications.

This is Part 1 of a two-part tutorial. In this part of the tutorial I’ll walk you through getting set up and bringing in data from a PHP server using Zend AMF. Flash Builder for PHP was optimized to work with Zend Server and you’ll get the best integration if you’re using the tool in conjunction with it. However this tutorial will walk you through the steps to set up a Flex and PHP application for any generic PHP server.

In Part 2, I’ll show you some of the advanced data features of Flash Builder for PHP, such as data management and paging, so you can add advanced functionality to your Flex application.

An overview of Flash Remoting

Before diving into the tutorial, it will help to have a basic understanding of Flash Remoting.

When you’re using XML or a similar format to send data to your client applications, much of the data you’re transferring is not absolutely necessary. Think of all of the extra characters that are in an XML document. Think of how many times you have to send the attributes and nodes, as well as the beginning tags and the end tags. XML is a great format but there is a great deal of overhead when you’re just trying to get data to your client.

Action Message Format

Action Message Format (AMF) works over HTTP, but instead of sending lots of extra information like XML, AMF essentially strips out the extra characters and reduces the data to a bare minimum. AMF serializes the data into a binary format that uses much less bandwidth and space than XML does for the same data. This is particularly important when you're sending large sets of data. Instead of sending multiple redundant tags in XML, you're sending the smaller, serialized AMF records. Another benefit of AMF is that it's a native data type for Flash Player. As a result, Flash Player doesn't have to parse the results to pull out the information; the data is available to Flash Player as native ActionScript objects as soon as it is received from the server.

Flash Remoting uses AMF to expose objects and web services on an application server as if they were local ActionScript objects. The only catch is that to use Flash Remoting with PHP you have to be working with PHP objects and classes. The AMF gateway helps translate those PHP objects into ActionScript objects in Flash Player. As a result you can create your own typed objects in PHP and work with those exact custom-typed objects in ActionScript.

Flash Remoting and the Zend Framework

Adobe partnered with Zend to provide support for Flash Remoting with AMF in the Zend Framework. There are other projects out there, including AMFPHP for other PHP frameworks, but Zend AMF has the most up-to-date support for Flash Remoting. The Zend Framework is a robust PHP framework that can be used for some very complex projects.

For some PHP developers who just want to connect PHP with Flex it may seem like a lot to chew off. But you don't have to use the entire Zend Framework or change the structure of your project to use Zend AMF. Zend AMF relies on a small but powerful subset of the Zend Framework that can be easily integrated into any PHP project.

Setting up

The easiest way to get started using Flash Builder for PHP is with Zend Server, a complete, enterprise-ready Web Application Server for running and managing PHP applications. Flash Builder for PHP will recognize your Zend Server installation and configure itself accordingly. However, you can also use any server you want. I use a version of MAMP, which includes everything you need to connect Flex and PHP and I’ll use that in this tutorial.

To get started, download the sample file for this article and unzip it. You can use the included php_demos.sql file to create the database and table used in this tutorial. If you’re using MySQL, follow these steps:

  1. From the command line type mysql -u root -p and type your password when prompted.

    To build the database, at the mysql prompt, type SOURCE php_demos.sql; and press Enter.

  2. Type quit and press Enter.

Your first Flex/PHP application

Before creating the application, you’ll want to set up the server you’re going to use in Flash Builder.

  1. Choose Window > Preferences and then expand PHP > PHP Servers.
  2. Click New.
  3. Type a name for the server (this can be whatever you want).
  4. Type the server’s Base URL.
  5. Specify the server’s Local Web Root.
  6. Click Finish.
  7. Click OK to close the Preferences dialog box.

The next step is to create linked Flex and PHP projects, which is exceptionally easy in Flash Builder for PHP.

  1. Choose File > New > Flex and PHP Project.

    The PHP project is configured first.

  2. Type MyFirstPHPProject as the name.
  3. Select Create Project On A Local Server.
  4. Leave the Zend Framework Version as its default value.
  5. Specify the server you created above.
  6. Click Validate Configuration.
  7. Once your configuration has been validated, click Next (see Figure 1).
Creating a new PHP project.
Figure 1. Creating a new PHP project.
  • Next, the Flex project is configured.
  1. Type MyFirstFlexApplication as the name.
  2. Select the Use Default Location option.
  3. Leave the default Output Folder setting. This is automatically set based on the settings you created in the PHP Project.
  4. Use the default Flex SDK.
  5. Click Finish (see Figure 2).
Creating a new Flex project.
Figure 2. Creating a new Flex project.

Flash Builder for PHP will create both the PHP and Flex projects in your workspace. The two PHP files you are going to use in this tutorial are ForestServiceTyped.php and NationalForest.php. Both of these rely on a database named national_forests, which you created in Setting up.

  1. Copy ForestServiceTyped.php and NationalForest.php to the services directory of your PHP project.
  2. Open ForestServiceTyped.php and update the MySQL server location, port, and authentication settings for your setup.
  3. Take a quick look at ForestServiceTyped.php and NationalForest.php.

Connecting to the PHP service

You probably noticed that both PHP files have been commented using PHPDoc syntax. The new version of Flash Builder for PHP uses that documentation to help it introspect the classes. In the next step, the Service wizard will use PHPDoc comments to help it determine the types for specific functions and classes so it can map those to their corresponding ActionScript classes.

  1. Select MyFirstFlexApplication.mxml in the Package Explorer.
  2. Open the Data/Services view.
  3. Click Connect To Data/Service.
  4. Verify the PHP By Zend service is selected, and click Next.
  5. For the PHP File Location, browse to and select the ForestServiceTyped.php file in your PHP project (see Figure 3).
Setting up the PHP service.
Figure 3. Setting up the PHP service.
  1. Click Next.

    You’ll see that, using the PHPDoc syntax, Flash Builder for PHP has already detected some of the types for the functions (see Figure 4).

Service operations immediately detected by Flash Builder for PHP.
Figure 4. Service operations immediately detected by Flash Builder for PHP.
  1. Click Finish.

For the getAllForests() and getForestsPaged() operations, you’ll want to define the return type.

  1. Right-click getAllForests() in the Data/Services view.
  2. Select Configure Return Type.
  3. Select Use An Existing Data Type.
  4. Select NationalForest[].
  5. Click Finish.
  6. Repeat steps 1 through 5 for the getForestsPaged() method.

Connecting service operations to the UI

Now that your service operations are defined, you can bind them to the user interface elements of the Flex application.

  1. Open MyFirstFlexApplication.mxml and switch to Design view.
  2. From the Components view in the lower left-hand, drag a DataGrid control to the Design area.
  3. Drag the getAllForests method from the Data/Services view and drop it on the DataGrid control.
  4. Click OK when Flash Builder for PHP notifies you the component is already bound.
  5. In the Bind To Data dialog box, click OK to generate the service call and bind the result to the DataGrid control (see Figure 5).
The Bind To Data dialog box.
Figure 5. The Bind To Data dialog box.
  1. Save your changes, build the project, and run the application.

    You should see your data grid loaded with the results from the database.

    The next step is to make the data editable.

  2. Back in Flash Builder for PHP right-click updateForest() in the Data/Services view and select Generate Form.
  3. Deselect Form For Return Type.
  4. Click Finish (see Figure 6).
Generating a form for updateForest().
Figure 6. Generating a form for updateForest().
  • Flash Builder for PHP will generate a form, which will likely overlap your data grid.
  1. Move the form over by using the Arrow keys until it no longer obscures the data grid (see Figure 7).
The data grid and newly generated form.
Figure 7. The data grid and newly generated form.
  • Next you want the item selected in the data grid to correspond to the form. The form is bound to a NationalForest object in the code, so by setting the NationalForest object to the selected item on the data grid, the form will automatically show the selected data.
  1. Right-click the DataGrid control and select Generate Selection Change Handler.
  2. Flash Builder for PHP will switch from Design view to Code view and highlight the data grid code.
  3. Use the Tab key to tab through the selection handler properties until you get to the line right below // TODO Auto-generated method sub.
  4. Edit the code so that it looks like this:
protected function dataGrid_selectionChangeHandler(event:GridSelectionEvent):void { nationalForest = dataGrid.selectedItem as NationalForest; }
  1. Save your changes, build the project, and run the application.

Now when you select an item it will show in the form. You can update the properties in the database by changing them in the form and clicking the update button.

Where to go from here

In this tutorial, you learned how to connect a Flex application to a PHP service using Flash Remoting. In Part 2, you’ll build on these steps using the advanced data features in Flash Builder for PHP to make your applications more responsive and more intuitive.

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

More Like This

  • Flash Builder Design View extension FAQ
  • Using the profiling tools in Flash Builder to improve the performance of Flash Professional projects
  • Building an Android and iOS mobile mapping application using the ArcGIS API for Flex
  • Introducing Flash Builder 4.5 for PHP
  • Streamlining Flex and PHP development with Flash Builder for PHP
  • What's new in Flash Builder 4.6
  • Building a data-centric application with Flash Builder for PHP – Part 2: Incorporating advanced data features
  • Data paging with Flex and PHP using Flash Builder 4.5
ccm-ste-promo-AU-NZ-200x92
Choose your region United States (Change)   Products   Downloads   Learn & Support   Company
Choose your region Close

Americas

Europe, Middle East and Africa

Asia Pacific

  • Brasil
  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Cyprus - English
  • Česká republika
  • Danmark
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Greece - English
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • Malta - English
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • 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
  • 台灣

Commonwealth of Independent States

  • Includes Armenia, Azerbaijan, Belarus, Georgia, Moldova, Kazakhstan, Kyrgyzstan, Tajikistan, Turkmenistan, Ukraine, Uzbekistan

Copyright © 2017 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

AdChoices