

|
|
| |
HOME > Flex > Flex Example
In this example I shall be showing a very simple step by step
method of working out with a Flash-based and browser-based
user interface communicating with the code running in the server
part of this example. So basically there will be a HTTP request
from the Flash component to the server side JSP (JavaServer Pages)
and a HTTP response will be returned back to the Flash UI and
ultimately shown on screen.
Now let us start with this example code walk through, and explore
the Flash MXML file as follows:
Sample.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;
import mx.controls.Alert;
private function submitValue(ev:MouseEvent):void {
//using HTTPService for interacting with
//web server JSP file.
var httpService:HTTPService = new HTTPService();
//adding separate event listeners, one for receiving
//response and the other for handling any exception
//or fault during execution/at runtime.
httpService.addEventListener(ResultEvent.RESULT,acceptResult);
httpService.addEventListener(FaultEvent.FAULT,exceptionHandler);
//creating parameters name and value pair for sending as
//request parameters.
//request name is "txtName" and value is comming from
// the text input box.
var param:Object = new Object();
param.txtName = txtName.text;
httpService.url = "sample.jsp";
httpService.send(param);
}
private function acceptResult(event:ResultEvent):void {
Alert.show(event.result.toString());
}
private function exceptionHandler(event:FaultEvent):void {
Alert.show(event.fault.toString());
}
]]>
</mx:Script>
<mx:Panel>
<mx:HBox>
<mx:TextInput id="txtName"/>
<mx:Button label="Submit" click="submitValue(event)"/>
</mx:HBox>
</mx:Panel>
</mx:Application>
|
This MXML file can be used to create a SWF file using the command line
program such as mxmlc with the command as follows:
mxmlc Sample.mxml -output Sample.swf
So when user clicks the submit button, then the event handler
method submitValue, then the corresponding method will be invoked
and in this example I have choosen to add event listener in this
method only. Once the result and fault event are registered,
these methods will be automatically invoked when these event
will be raised.
The corresponding JSP file "sample.jsp" does nothing but
having a System out println and sends out a response as
"This is from server"
sample.jsp
<%
System.out.println("Received from client: "+
(String)request.getParameter("txtName"));
out.println("This is from server");
%>
|
|
|
DISCLAIMER :
The content provided in this page is not warranted and/or guaranteed by techienjoy.com.
techienjoy.com is not liable for any negative consequences that may result/arise from
implementing directly/indirectly any information covered in these pages/articles/tutorials.
All contents of this site is/are written and provided on an "AS IS" basis,
without WARRANTIES or conditions of any kind, either express or implied, including, without
limitation, merchantability, or fitness for a particular purpose. You are solely responsible
for determining the appropriateness of using or refering this and assume any risks associated
with this.
In spite of all precautions taken to avoid any typo in these pages, there might be some
issues like grammatical mistakes and typos being observed in these pages, techienjoy.com
extends sincerest apologies to all our visitors for the same.
|
|
| 

|