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

    <mx:RemoteObject endpoint="http://127.0.0.1:8080/gateway" 
                     destination="Services" id="remoteObj"
                     result="displayResult(event)" fault="remoteFault(event)">
        <mx:method name="scramble" result="scrambleResult(event)"/>
    </mx:RemoteObject>

    <mx:Button click="remoteObj.echo('Hello, There!')" label="Hello"/>

    <mx:HBox width="100%">
        <mx:Button click="remoteObj.sum(new Number(a.text), new Number(b.text))" label="Sum"/>
        <mx:TextInput id="a" text="47"/>
        <mx:TextInput id="b" text="99"/>
    </mx:HBox>
    <mx:HBox width="100%">
        <mx:Button click="remoteObj.scramble(c.text)" label="Scramble"/>
        <mx:TextInput id="c" text="She sells seashells by the seashore" width="100%"/>
    </mx:HBox>

    <mx:Text id="result" width="100%" height="100%" />

    <mx:Script>
    <![CDATA[
        import mx.utils.ObjectUtil;
        import mx.rpc.events.ResultEvent;
        import mx.rpc.events.FaultEvent;

        private function displayResult(re:ResultEvent): void {
            result.text += ObjectUtil.toString(re.result) + "\n";
        }

        private function scrambleResult(re:ResultEvent): void {
            c.text = re.result as String;
        }

        private function remoteFault(fault:FaultEvent): void {
            result.text = fault.fault.faultDetail;
        }
    ]]>
    </mx:Script>
</mx:Application>