PHP Data with Flex Applications Part 2: Receiving the Data in the Flex Application

| No Comments | No TrackBacks
So, if you have not seen part 1 of this series and are just now seeing part 2, the link to part 1 can be found here. Now for part 2. This part will be shorter, because there is less to talk about. Part 3 will be quite long and in depth, so keep up.

So now, you have a functioning PHP script that will generate XML code that Flex can interpret. So, for the sake of simplicity, lets say your XML consists of this code. 
<?xml version="1.0" encoding="utf-8"?>
<customer>
     <first>John</first>
     <last>Doe</last>
</customer>

So, that's the script that will be generated by your PHP script if you poke it. But, how do you get flex to poke it? Well, Flex has a built in component to handle this request. It is called an HTTPService. The HTTPService allows you to connect to a web page (PHP, XML, HTML, whatever..) and pull the results. So, to get the result from the PHP script, all you have to do is define an HTTPService component that connects to the PHP script. It would be done like so:
<mx:HTTPService method="POST" url="http://www.me.com/script.php" id="webService" /> 

This HTTPService call will ask the PHP script for a result, which will be supplied to it. The result will be enclosed in the result of the HTTPService. This is accessed by simply getting the name of the HTTPService, in this case webService and attach another identifier to it. This example would require somthing like this: webService.lastResult. Now, a certain tag in the XML code can be accessed by a different method. So, if you want to get the customer name, in this case John, you would do something like this: webService.lastResult.customer.first. Notice the names of the XML tags in the access tag. To access anything deeper, you would have to just add the next tag down and go from there. 

That concludes part 2, and part three will be here on Sunday. Hang on for then.

No TrackBacks

TrackBack URL: http://www.ajobi.net/mt/mt-tb.cgi/166

Leave a comment

About this Entry

This page contains a single entry by Arthur Lockman published on April 22, 2009 2:02 PM.

PHP Data with Flex Applications: Part 1 was the previous entry in this blog.

Great Session on Flash Catalyst is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.