Log In  
  Getting Started  
----------------------------------------

Resources

 

Part II: Exchanging Data Tutorial

Application Overview

User rating?

Show / Hide hints for:

Use Design view to lay out the user interface

1. Create an application file named PlainText.mxml.

2. Switch to the Design mode.

3. From the Components view, drag a Label component from the Controls folders to the upper-left corner of the design area. Keep the default values of the component.

4. Double-click the label and rename it Zip Code.

5. Drag a second Label component below the first, and rename it Weight.

6. Use the blue guide lines to reposition the Weight label so that its right edge aligns with the right edge of the Zip Code label.

7. Add two TextInput components to the right of each Label component. Use the blue guide lines to help you position the elements.

8. Select the first TextInput component and then locate the Flex Properties view.

9. Set the ID property of the TextInput component to zipcode.

10. Select the second TextInput component. Set the value of the& ID property to weight_lb.

11. Add a Button component below the TextField components.

12. Double-click the button and change its label to Get Shipping Options.

13. Drag a TextArea component to the right of the form so that your display appears similar to the following image. Resize it as necessary.

14. Select the TextArea component and then locate the Flex Properties view.

15. Set the ID property of the TextArea component to shippingOptions.

LEARN MORE
ColdFusion
  • For more information, see the Flex and ColdFusion area of the ColdFusion Developer Center.
  • Download a ZIP file that contains the completed application and includes the related CFML files.
ASP
Java
  • Adobe LiveCycle Data Services ES provides sophisticated ways to integrate Flex clients with J2EE infrastructure, ColdFuson, and LiveCycle document and process services.
  • Download a ZIP file that contains the completed application and includes the related JSP and Java files.
  • To import the project into Flex Builder, select File > Import Flex Project.
PHP
  • For information on integrating PHP and Flex using AMF to encode the data, and general information on using PFP with Flex, see the Adobe Flex PHP developer center
  • And the PHP pages of flex.org.
  • Download a ZIP file that contains the completed application and includes the related PHP files.
  • To import the project into Flex Builder, select File > Import Flex Project.

16. Switch to Source mode.

17. Your code appears as follows:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">


	<mx:Label x="54" y="25" text="Zip Code"/>
	<mx:Label x="65" y="51" text="Weight"/>
	<mx:TextInput x="128" y="23" id="zipcode"/>
	<mx:TextInput x="128" y="49" id="weight_lb"/>
	<mx:Button x="128" y="79" label="Get Shipping Options"/>
	<mx:TextArea x="339" y="24" width="198" height="77" id="shippingOptions"/>

</mx:Application>

18. Click the Run button to compile and run the application.

The form does not submit yet, but your form appears as it did in Design mode.

Format the application display

19. In the first <mx:Application> tag, add the backgroundColor attribute with a value of white (#FFFFFF) and set the backgroundImage attribute to the entry string (otherwise you may get a gradient).

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute"
    backgroundColor="#FFFFFF"
    backgroundImage="" >

20. Run the application; the background color of the application is now white.

Create the HTTPService object

1. After the first <mx:Application> tag but before the form display, create an <mx:HTTPService> tag code block.

2. Add an id attribute with a value of plainRPC to the opening <mx:HTTPService> tag.

3. Add a url attribute with a value of http://www.tipsandapps.com/quickstart/PlainHttpService.aspx.

Alternatively, you can use the following ColdFusion, PHP, or Java URLs:
http://www.coldfusionportal.org/flex3cf/PlainHTTPService.cfm
http://examples.adobe.com/flex3/exchangingdata/text/plainHttpService.php
http://examples.adobe.com/flex3app/flex3samples/exchangingdata/text/PlainHttpService.jsp

4. Define a result event handler named handlePlain() and a fault event handler named handleFault().

5. Ensurethat you pass the event object to each of the handlers.

6. Set the resultFormat attribute to text. Your code appears as follows:

<mx:HTTPService id="plainRPC"
	    url="http://www.tipsandapps.com/quickstart/PlainHttpService.aspx"
		result="handlePlain(event);"
		fault="handleFault(event);"
		resultFormat="text">
	</mx:HTTPService>

7. Between the <mx:HTTPService> tags, create an <mx:request> tag code block.

8. Pass the zipcode and pounds XML values bound to the zipcode.text and weight_lb.text TextInput component values, respectively. Your code appears as follows:

<mx:HTTPService id="plainRPC"
	    url="http://www.tipsandapps.com/quickstart/PlainHttpService.aspx"
		result="handlePlain(event);"
		fault="handleFault(event);"
		resultFormat="text">
	    <mx:request xmlns="">
	        <zipcode>{zipcode.text}</zipcode>
	        <pounds>{weight_lb.text}</pounds>
	    </mx:request>
	</mx:HTTPService>

Create the result and fault event handlers

9. Above the HTTPService component, create an <mx:Script> tag code block.

<mx:Script>
<![CDATA[

]]>
</mx:Script>

10. In the <mx:Script> tag, import the mx.rpc.events.ResultEvent, mx.rpc.events.FaultEvent and mx.controls.Alert classes.

<mx:Script>
<![CDATA[
	import mx.rpc.events.ResultEvent;
	import mx.rpc.events.FaultEvent;
	import mx.controls.Alert;
]]>
</mx:Script>

11. Create a private event handler named handlePlain() that accepts a ResultEvent argument named event. Make sure the return type is void.

12. Create a private event handler named handleFault() that accepts a FaultEvent argument named event. Make sure the return type is void. Your code appears as follows:

<mx:Script>
		<![CDATA[
			import mx.rpc.events.ResultEvent;
			import mx.rpc.events.FaultEvent;
			import mx.controls.Alert;

	        private function handlePlain(event:ResultEvent):void
	        {

	        }

	        private function handleFault(event:FaultEvent):void
	        {

	        }
		]]>
	</mx:Script>

13. In the result handler, use the event.result.toString() method to convert the results to a string data type and then assign it to the htmlText property of the shippingOptions Text control.

14. In the fault handler, populate the Alert dialog box using the show() method and set the word Error for the header and the event.fault.faultString value for the body text. Your code appears as follows:

<mx:Script>
		<![CDATA[
			import mx.rpc.events.ResultEvent;
			import mx.rpc.events.FaultEvent;
			import mx.controls.Alert;

	        public function handlePlain(event:ResultEvent):void
	        {
	            shippingOptions.htmlText = event.result.toString();
	        }

	        public function handleFault(event:FaultEvent):void
	        {
	           Alert.show(event.fault.faultString, "Error");
	        }
		]]>
	</mx:Script>

Create the submit button click event handler

15. Using the Outline view, locate the Button component.

16. To the button, add the click attribute with a value of plainRPC.send(); to tell the plainRPC HTTPService object to send the request.

<mx:Button x="128" y="79" label="Get Shipping Options" click="plainRPC.send();"/>

17. Save your file and run the application.

18. Enter a Zip Code and a weight. Your results appear similar to the following image:

I tried this tutorial with the cfm link:

http://www.coldfusionportal.org/flex3cf/PlainHTTPService.cfm

and an error is returned: security error accessing url.

It seems to work fine with the .asp example though.

Please explain.

Steven -

 I finally got this to work but it doesn't point to coldfusionportal.org. I put the flex3 files (assets) and those cfm/cfc onto one of our dev servers and it works. I point to our dev server in the mxml file instead of the other url ( coldfusionportal.org ). That error is caused because of a cross-domain error, (flex on your PC) and cfm/cfc on that other server. I'm going to look at a solution to the cross-domain problem. Hope this helps.

In Step 8 there is an extra closing tag in the middle of the mx:HTTPService that should be removed.  Thanks for posting this tutorial!

I get the same error as Steven B. Please publish good code for CF. But it works for PHP. Most of these example are missing details on Adobe's site. Be professional.

I also got the same error as Steven. I got HTTP request error for asp and jsp and for php got 0s for the returned information.

I, too, got an HTTP request error. I believe that this code is correct:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
    backgroundColor="#FFFFFF" backgroundImage="" >
    <mx:Label x="27" y="30" text="Zip Code:"/>
    <mx:Label x="38" y="56" text="Weight:"/>
    <mx:TextInput x="95" y="28" id="zipcode"/>
    <mx:TextInput x="95" y="58" id="weight_lb"/>
    <mx:Button x="95" y="102" label="Get Shipping Options" id="getOptions" click="plainRPC.send()"/>
    <mx:TextArea x="276" y="29" width="214" height="95" id="shippingOptions"/>
    
    <mx:HTTPService id="plainRPC"
            url="http://www.tipsandapps.com/quickstart/PlainHttpService.aspx"
            result="handlePlain(event);"
            fault="handleFault(event);" resultFormat="text">
        <mx:request xmlns="">
            <zipcode>{zipcode.text}</zipcode>
            <pounds>{weight_lb.text}</pounds>
        </mx:request>
    </mx:HTTPService>
    
    <mx:Script>
        <![CDATA[
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            import mx.controls.Alert;
            
            private function handlePlain(event: ResultEvent): void {
                shippingOptions.htmlText = event.result.toString();
            }
            
            private function handleFault(event: FaultEvent): void {
                Alert.show(event.fault.faultString, "Error");
            }
        ]]>
    </mx:Script>
</mx:Application>

Sean, I don't know how much it matters - I am just learning Flex syntax - but in the instructions as they stand today (June 4, 2008 4:00 p.m.), they are giving directions of how to order the mx:Script and mx:HTTPService code locations. Did you ever get this worked out? (Because I am curious if order matters - which often it does, but again, I am new to Flex.)

Thanks for any light you can shed on this nuance of Flex coding!

The httpservice url http://examples.adobe.com/flex3app/flex3samples/exchangingdata/text/PlainHttpService.jsp&nbsp;does not work. Any one knows the correct url kindly share the same

Did anyone get this to work? - The "error" is related to the "HTTPservice" still..... anyone...."Bueller, Buller" 

It works smoothly for me .. the URLs work too !


With the ASP.NET url (www.tipsandapps.com/quickstart/PlainHttpService.aspx) - as suggested in the tutorial text seen today - I get (likely) the same error Laurence Moore reports.

With the PHP url (examples.adobe.com/flex3/exchangingdata/text/plainHttpService.php), I get no completed calculations - all values reporting 0.

With the ColdFusion url (www.coldfusionportal.org/flex3cf/PlainHTTPService.cfm), I now get an error report in the output box:

Error Occurred While Processing Request

function showHide(targetName) {
if( document.getElementById ) { // NS6\+
             target = document.getElementById(targetName);
}else if( document.all ) { // IE4\+
             target = document.all\[targetName\];
}
if( target ) {
	if( target.style.display == "none" ) {
        target.style.display = "inline";
        }else{
                 target.style.display = "none";
         }
    }
}
The web site you are accessing has experienced an unexpected error.

Please contact the website administrator.

The following information is meant for the website developer for debugging purposes.
Error Occurred While Processing Request

The value (zipCode.text) cannot be converted to a number.

Earlier, with the same ColdFusion url, I got a ColdFusion screen dump of error information. (I didn't capture at the time because I thought I goofed somewhere - sorry about that.)

With the JSP url (examples.adobe.com/flex3app/flex3samples/exchangingdata/text/PlainHttpService.jsp), I get the same error dialog box that I get with the ASP.NET url: Title: Error - Message: HTTP request error. - Button: OK.

I am currently re-rechecking my mx Application code to make sure I've entered everything as given today, Wednesday, June 4, 2008 at 3:48 p.m. EDT.

I agree with Janel... I did double-check my code, finally, and the capital "C" in the zipCode argument did get me (whereas the zipcode tag is with a lower case "c"), as well as the curly braces in the mx:request section, around the .text arguments.

I have tested my code (as entered by the tutorial above) and the only url that does not work now for the HTTPService is the ASP.NET one, I still get the error dialog box with the HTTP request error message (as previously mentioned by Laurence). Otherwise, the PHP, CFM, and JSP urls work just fine. (Although the cfm version must have poorly formed code on it's end because the br tags show up in the text as text, not invisibly as carriage returns.)

I was unable to get the jsp url version to work either, so I compared the tutorial instructions to the downloadable example that functioned as expected.   There are a number of differences between them, but I found the problem was the zipcode tag name.  The tutorial spells it zipCode instead of zipcode (all lower case).  The jsp version worked well after that change.

Looks like they've fixed the zipCode / zipcode issue in the tutorial - all instances now read zipcode.

All of these URLs they mention work (without the parameters on the end obviously):

http://examples.adobe.com/flex3/exchangingdata/text/plainHttpService.php?zipcode=12345&pounds=34
http://www.coldfusionportal.org/flex3cf/PlainHTTPService.cfm?zipcode=91171&pounds=4
http://examples.adobe.com/flex3app/flex3samples/exchangingdata/text/PlainHttpService.jsp?zipcode=91171&pounds=4

The only one that doesn't is, ironically, the one they recommend using, ie:

http://www.tipsandapps.com/quickstart/PlainHttpService.aspx?zipcode=91171&pounds=4

Might be nice if this was fixed.  Unless this is intended to force anyone doing the tutorial to do some extra thinking. 

Added by Mark Nichoson , last edited by Randy Nielsen on May 07, 2008  (view change)
Labels: 
(None)

Powered by Atlassian Confluence 2.7.1, the Enterprise Wiki. Bug/feature request - Atlassian news - Contact administrators