A small example of flex communication with java

Source: Internet
Author: User

Simple small example, suitable for beginners to understand

1. JavaFlex. java

View plaincopy to clipboardprint?
  1. Package flex;
  2. Public class JavaFlex {
  3. Public String helloJavaFlex (String name ){
  4. Return name;
  5. }
  6. }

Package flex; public class JavaFlex {public String helloJavaFlex (String name) {return name ;}}

Remoting-config.xml 2

View plaincopy to clipboardprint?
  1. <? Xml version = "1.0" encoding = "UTF-8"?>
  2. <Service id = "remoting-service" class = "flex. messaging. services. RemotingService">
  3. <Adapters>
  4. <Adapter-definition id = "java-object"
  5. Class = "flex. messaging. services. remoting. adapters. JavaAdapter"
  6. Default = "true"/>
  7. </Adapters>
  8. <Default-channels>
  9. <Channel ref = "my-amf"/>
  10. </Default-channels>
  11. <Destination id = "firstJavaFlex">
  12. <Properties>
  13. <Source> flex. JavaFlex
  14. </Source>
  15. </Properties>
  16. </Destination>
  17. </Service>

<? Xml version = "1.0" encoding = "UTF-8"?> <Service id = "remoting-service" class = "flex. messaging. services. remotingService "> <adapters> <adapter-definition id =" java-object "class =" flex. messaging. services. remoting. adapters. javaAdapter "default =" true "/> </adapters> <default-channels> <channel ref =" my-amf "/> </default-channels> <destination id =" firstJavaFlex "> <properties> <source> flex. javaFlex </source> </properties> </destination> </service>

3, testflex. mxml

View plaincopy to clipboardprint?
  1. <? Xml version = "1.0" encoding = "UTF-8"?>
  2. <S: Application xmlns: fx = "http://ns.adobe.com/mxml/2009"
  3. Xmlns: s = "library: // ns.adobe.com/flex/spark"
  4. Xmlns: mx = "library: // ns.adobe.com/flex/mx" minWidth = "955" minHeight = "600">
  5. <Fx: Declarations>
  6. <! -- Place non-visual elements (such as services and value objects) Here -->
  7. <S: RemoteObject id = "selectHello" destination = "firstJavaFlex" fault = "error (event)"/>
  8. </Fx: Declarations>
  9. <Fx: Script>
  10. <! -- [CDATA [
  11. Import mx. collections. ArrayCollection;
  12. Import mx. controls. Alert;
  13. Import mx. events. ResizeEvent;
  14. Import mx. rpc. events. FaultEvent;
  15. Import mx. rpc. events. ResultEvent;
  16. [Bindable]
  17. Private var arraylist: ArrayCollection = new ArrayCollection ([
  18. {Name: "hello", data: "Hello! "},
  19. {Name: "hello", data: "Hello! "},
  20. {Name: "Hello everyone", data: "Hello everyone! "},
  21. ]);
  22. Private function changehandler (event: Event): void {
  23. SelectHello. helloJavaFlex (selected. selectedItem. data );
  24. SelectHello. addEventListener (ResultEvent. RESULT, remoteResult );
  25. }
  26. Private function remoteResult (event: ResultEvent): void {
  27. Alert. show (event. result. toString ());
  28. Resultmess. text = event. result. toString ();
  29. }
  30. Private function error (event: FaultEvent): void {
  31. Alert. show (event. message. body. toString ());
  32. Resultmess. text = event. message. body. toString ();
  33. }
  34. ] -->
  35. </Fx: Script>
  36. <S: DropDownList x = "113" y = "83" id = "selected" labelField = "name" dataProvider = "{arraylist}" change = "changehandler (event) "/>
  37. <S: RichText x = "321" y = "227" id = "resultmess" text = "RichText"/>
  38. </S: Application>

<? Xml version = "1.0" encoding = "UTF-8"?> <S: Application xmlns: fx = "http://ns.adobe.com/mxml/2009" xmlns: s = "library: // ns.adobe.com/flex/spark" xmlns: mx = "library: // ns.adobe.com/flex/mx "minWidth =" 955 "minHeight =" 600 "> <fx: Declarations> <! -- Place a non-visual element (such as a service or value object) Here --> <s: RemoteObject id = "selectHello" destination = "firstJavaFlex" fault = "error (event) "/> </fx: Declarations> <fx: Script> <! -- [CDATA [import mx. collections. arrayCollection; import mx. controls. alert; import mx. events. resizeEvent; import mx. rpc. events. faultEvent; import mx. rpc. events. resultEvent; [Bindable] private var arraylist: ArrayCollection = new ArrayCollection ([{name: "hello", data: "Hello! "}, {Name:" hello ", data:" Hello! "},{ Name:" Hello everyone ", data:" Hello everyone! "},]); Private function changehandler (event: Event): void {selectHello. helloJavaFlex (selected. selectedItem. data); selectHello. addEventListener (ResultEvent. RESULT, remoteResult);} private function remoteResult (event: ResultEvent): void {Alert. show (event. result. toString (); resultmess. text = event. result. toString ();} private function error (event: FaultEvent): void {Alert. show (event. message. body. toString (); resultmess. text = event. message. body. toString () ;}]] --> </fx: Script> <s: dropDownList x = "113" y = "83" id = "selected" labelField = "name" dataProvider = "{arraylist}" change = "changehandler (event) "/> <s: RichText x =" 321 "y =" 227 "id =" resultmess "text =" RichText "/> </s: Application>

Source code download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.