Simple small example, suitable for beginners to understand
1. JavaFlex. java
View plaincopy to clipboardprint?
- Package flex;
- Public class JavaFlex {
- Public String helloJavaFlex (String name ){
- Return name;
- }
- }
Package flex; public class JavaFlex {public String helloJavaFlex (String name) {return name ;}}
Remoting-config.xml 2
View plaincopy to clipboardprint?
- <? 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>
<? 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?
- <? 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 non-visual elements (such as services and value objects) 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>
<? 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