Flex Blog

Search:
  • Home
  • Examples
    • Thumb

      Flex Examples

      Check out our Flex Examples!

    • Thumb

      Flash Builder Examples

      Check out our Flash Builder Examples!

    • Thumb

      AIR Examples

      Check out our AIR Examples!

    • Thumb

      Flex Mobile Examples

      Check out our Flex Mobile Examples!

    Adobe® Flex, Adobe® Flash Builder and Adobe® AIR are registered trademarks of Adobe Systems.
  • Components
    • Thumb

      WP Flex Contact Form

      Check out our WP Flex Contact Form!

    • Thumb

      Flash CountDown Plugin

      Check out our Flash CountDown Plugin!

    This is an overview of all our Flash/Flex based Components.
  • Jobs
  • Flex Books
  • Forum
  • Contact Us
Subscribe to Flex BlogSubscribe
  • Examples
  • iOS
Browse > Home / Examples / Simple Flex & PHP Example

Simple Flex & PHP Example

14 February 2009

Line Break

Author: Arjan (47 Articles) - Author Website

Arjan is a SAP Consultant specialized in ABAP and Front End development techniques like Web Dynpro, Adobe Interactive Forms, Flex and AIR. In his free time he likes to create examples for Flex-Blog and other applications using Flex, AIR and PHP. Other hobbies are movies and music. He is also the co-owner of Flex-Blog.com.

How do i get my data from Flex to PHP? I wondered about this a year or so ago when I was just getting to know Flex. I have to admit that my PHP skills are not that good, I can get things in and out of MySQL databases and that’s about it. But after figuring it out, I wanted to share. Transferring data can be a mammoth task, and I think we all know that. So to have a quick tutorial allowing you to avoid the traumatic experience of a failed data transfer. Just follow the instructions, and you could repeat the process for anything from your personal blog to o2.co.uk/. I hope it helps, and I know that I found this amazingly useful when I first discovered it. But enough about me, let’s make a simple Flex application that calls some PHP script on the server.

Ok to keep it simple i’m just going to create a function that concatenates two string that are filled in in the Flex application and the result is send back.

First we need a screen with two TextInput fields, One Text output field and a Button to trigger the application to call the script:

1
2
3
4
5
6
7
8
9
10
11
12
13
<mx:VBox top="10" left="10">
    <mx:HBox verticalAlign="middle">
        <mx:Label text="String 1:"/>
        <mx:TextInput id="stringOne"/>
    </mx:HBox>
    <mx:HBox verticalAlign="middle">
        <mx:Label text="String 2:"/>
        <mx:TextInput id="stringTwo"/>
    </mx:HBox>
    <mx:HRule width="100%"/>
    <mx:Button label="Concatenate!" click=""/>
    <mx:Text text=""/>
</mx:VBox>

The click event of the Button doesn’t do anything yet, and the output text is not determined yet. We will get to that later.

Ok let’s do some PHP. Put the following PHP script on your server somewere, let’s call it concat.php:

1
2
3
4
5
6
7
8
<?php

$stringOne = $_POST['stringOne'];
$stringTwo = $_POST['stringTwo'];

print $stringOne . $stringTwo;

?>

Now to call that script, we are going to use the HTTPService component. We have to specify an id, url, message and a resultFormat. Furthermore, we have to specify the request inside the HTTPService tag:

1
2
3
4
5
6
7
8
9
10
11
12
13
<mx:HTTPService
id="concat" url="concat.php"
resultFormat="text"
method="POST">

    <mx:request xmlns="">

        <stringOne>{stringOne.text}</stringOne>
        <stringTwo>{stringTwo.text}</stringTwo>

    </mx:request>

</mx:HTTPService>

The tag names inside the request are very important: they must match the post variables that you’re expecting in your PHP script, and they are ofcourse, case sensitive.

The values of the two input fields appear inside the stringOne and stringTwo tags, using a binding expressing on the text property of the component.

Ok now all we need to do is adding some code to the Button we created earlier. This code will trigger the application to send the HTTPService request to the server:

1
<mx:Button label="Concatenate!" click="concat.send()"/>

Finally, add code to the Text component at the bottom of your application to show the result. We can achieve this by binding the text property to the lastResult property of the HTTPService.

1
<mx:Text fontSize="14" text="{concat.lastResult}"/>

Ok, when we put it all together it should look something like the following example, use right mouseclick > view source to view the complete sourcecode.

Related posts:

  1. TinyURL usage with Flash Builder
  2. Progressbar in Datagrid Example
  3. Flex Custom Event Example

Written by Arjan · Filed Under Examples 

Was this post useful to you?

Please rate this post, follow us @ twitter, or link to this page from your website!

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 4.67 out of 5)
Loading ... Loading ...

e9c3fd319fd2604a4b09cccd8864ee76delicious

Comments

3 Responses to “Simple Flex & PHP Example”

  1. shahzad on October 11th, 2010 8:26 am

    Hi

    you have write great topic for starting flex, its first time i am writing feedback, thanks for publishing nice tipic

  2. Sarah on January 27th, 2011 4:22 am

    Hi Arjan,
    I want to make report my project by Flex, data is get from database. Do I create it with Flex? like that http://flex.stimulsoft.com/DemoFx_Flex.html

    Thank

  3. sagar on June 3rd, 2011 10:50 am

    i want to make blog in php how do i do that….

Get Adobe Flash player

  • +1?

  • Support Flex Blog!

  • $ 13 raised
    • 2012/01/13 8:22 PM Russell Brown donated $ 3.00
    • 2011/10/31 4:43 PM Steve Dakin donated $ 5.00
    • 2011/05/11 3:37 PM Roelof Albers donated $ 5.00
  • Stay in touch!

  • Popular Tags

    • AdvancedDataGrid
    • AIR
    • ArrayCollection
    • baseColor
    • Button
    • CursorManager
    • DataGrid
    • Dynamic
    • Effects
    • File
    • FileStream
    • Flash Builder
    • Flash Builder 4
    • Flex 4
    • Flex Mobile
    • Framework
    • Icon
    • Image
    • itemRenderer
    • LinkBar
    • Mobile
    • PHP
    • ProgressBar
    • Repeater
    • Style
    • SWIZ
    • Timer
    • Tree
    • Twitter
    • ViewStack
  • Advertisements

  • Recent Posts

    • Spooky Frenzy – iPad Game
    • Fountain Example
    • Reading & Writing files in Adobe AIR
    • CheckBox in List using MobileIconItemRenderer for Flex Mobile
    • Data Dependent decoratorClass in MobileIconItemRenderer Example
    • Flex 4 Resize Effect Example
    • Jump to next field using the Focus Manager
    • Searching Data using a Class Example
    • Flex Mobile: Two finger tap gesture to toggle actionBar visibility in a View (AIR for Android)
    • TabbedMobileApplication Example in Flex Mobile (AIR for Android)
  • Categories

    • Examples
    • Guest Poster
    • iOS
  • Archives

    • September 2011
    • July 2011
    • May 2011
    • March 2011
    • February 2011
    • November 2010
    • October 2010
    • September 2010
    • August 2010
    • June 2010
    • May 2010
    • April 2010
    • March 2010
    • February 2010
    • January 2010
    • December 2009
    • November 2009
    • October 2009
    • March 2009
    • February 2009
  • Blogroll

    • Adobe Flex Jobs
    • NL for Business
  • Meta

    • Register
    • Log in
    • WordPress
    • XHTML

Copyright © 2010 Flex Blog · Adobe® and Adobe® Flex are registered trademarks of Adobe Systems.

WordPress Adobe Flex Adobe Flash Builder Adobe AIR Creative Commons License

  • Popular Posts

    • Progressbar in Datagrid Example 13 votes, average: 5.00 out of 513 votes, average: 5.00 out of 513 votes, average: 5.00 out of 513 votes, average: 5.00 out of 513 votes, average: 5.00 out of 5 (5.00 out of 5)
    • Data Dependant Tree Icon with Tree in AdvancedDataGrid with iconFunction 8 votes, average: 5.00 out of 58 votes, average: 5.00 out of 58 votes, average: 5.00 out of 58 votes, average: 5.00 out of 58 votes, average: 5.00 out of 5 (5.00 out of 5)
    • List Directory with AIR in Flex 4 7 votes, average: 5.00 out of 57 votes, average: 5.00 out of 57 votes, average: 5.00 out of 57 votes, average: 5.00 out of 57 votes, average: 5.00 out of 5 (5.00 out of 5)
    • Flex FlashVars in AS3 Example 7 votes, average: 5.00 out of 57 votes, average: 5.00 out of 57 votes, average: 5.00 out of 57 votes, average: 5.00 out of 57 votes, average: 5.00 out of 5 (5.00 out of 5)
    • Flex Dynamic Chart Example 4 votes, average: 5.00 out of 54 votes, average: 5.00 out of 54 votes, average: 5.00 out of 54 votes, average: 5.00 out of 54 votes, average: 5.00 out of 5 (5.00 out of 5)