Here is a part of my way to do it.... this is only for the connection,
you have to use "flexComRo.yourjavamethod "and you have to create a
handler for tath if you need to.
you have to put the destination in the remote-config.xml
import flash.events.Event;
import flash.events.EventDispatcher;
import mx.controls.Alert;
import mx.managers.CursorManager;
import mx.messaging.Channel;
import mx.messaging.ChannelSet;
import mx.messaging.channels.AMFChannel;
import mx.messaging.events.ChannelEvent;
import mx.messaging.events.ChannelFaultEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.mxml.RemoteObject;
import mx.utils.ObjectUtil;
public class RemoteObjectProxy extends EventDispatcher {
private static var _instance:RemoteObjectProxy;
private static var flexComRO:RemoteObject;
private static var channelSet:ChannelSet = new ChannelSet();
private static var channel:Channel;
public function RemoteObjectProxy(enforcer:SingletonEnforcer){}
public static function getInstance():RemoteObjectProxy
{
if(RemoteObjectProxy._instance == null)
{
RemoteObjectProxy._instance = new RemoteObjectProxy(new
SingletonEnforcer());
initFlexCom();
//trace('PopUpControl created!')
return RemoteObjectProxy._instance;
}
//trace('PopUpControl returned!')
return RemoteObjectProxy._instance;
}
private static function initFlexCom():void
{
channel = new AMFChannel('my-amf',
'http://{server.name}:{server.port}/flex/messagebroker/amf');
channel.requestTimeout = 10;
channel.connectTimeout = 10;
channelSet.addChannel(channel);
flexComRO = new RemoteObject();
flexComRO.concurrency = Concurrency.LAST;
flexComRO.destination = "FlexComRO";
flexComRO.channelSet = channelSet;
// trace('channelSet: ' + ObjectUtil.toString(channelSet));
channelSet.addEventListener(ChannelFaultEvent.FAULT,
handleChannelFault);
channelSet.addEventListener(ChannelEvent.CONNECT, handleChannelConnect);
channelSet.addEventListener(ChannelEvent.DISCONNECT,
handleChannelDisconnect);
flexComRO.addEventListener(FaultEvent.FAULT, faultHandler);// denne er
for selve objectet som er koblet mot java. men denne 'fault handleren'
er komblet kun mot loginUser.
}
// Handler for Channels and remote Object
private static function handleChannelFault(event:ChannelFaultEvent):void
{//trace('handleChannelFault: ' + event);
CursorManager.removeBusyCursor();
}
private static function handleChannelConnect(event:ChannelEvent):void
{//trace('handleChannelConnect: ' + event);
}
private static function handleChannelDisconnect(event:ChannelEvent):void
{//trace('handleChannelConnect: ' + event);
}
private static function faultHandler (event:FaultEvent):void
{
// Deal with event.fault.faultString on all FlexComRO's methods!
Alert.show(event.fault.faultString + " : " + event.fault.message,
"Server Error: " + event.fault.faultCode);
CursorManager.removeBusyCursor();
}
}//Class
}// Package
class SingletonEnforcer {}
http://www.umbrellacorp.no <http://www.umbrellacorp.no>
--- In [email protected], "blc187" <[EMAIL PROTECTED]> wrote:
>
> I'm trying to move some code out of my MXML into AS classes but having
> trouble with the RemoteObject.
> The following code:
>
> <mx:RemoteObject id="remoteObject" destination="genericDestination">
> <mx:method name="myMethod" result="gotServerData(event)"/>
> </mx:RemoteObject>
>
> How do I go about setting up the remoteObject method programmatically?
>