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

Resources

 

Part II: Exchanging Data Tutorial

Application Overview

previous page next page

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://aspexamples.adobe.com/flex3/exchangingdata/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://aspexamples.adobe.com/flex3/exchangingdata/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:

previous page next page
Added by Mark Nichoson , last edited by Randy Nielsen on May 28, 2009  (view change)
Labels: 
(None)

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