Тема: RemoteObject
Показать сообщение отдельно
Старый 23.09.2009, 18:00
Alex_41 вне форума Посмотреть профиль Отправить личное сообщение для Alex_41 Найти все сообщения от Alex_41
  № 2  
Ответить с цитированием
Alex_41

Регистрация: Aug 2009
Сообщений: 27
Мб не "best practice", но я вижу так (на работоспособность после копи-паста не проверял):

Код AS3:
package service
{
  import mx.controls.Alert;
 
	import mx.messaging.ChannelSet;
	import mx.messaging.channels.AMFChannel;
 
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
 
	public class MyService extends RemoteObject
	{
		private	var amfChannel: AMFChannel;
 
		public function MyService(){
			initRemoteObject();
		}
 
		private function initRemoteObject():void{
			channelSet = new ChannelSet();
			amfChannel = new AMFChannel("Your destination", "Your uri");			
			channelSet.addChannel(amfChannel);
 
			destination = "Your destination";
			source = "Your source";
 
			getOperation("MethodName").addEventListener(ResultEvent.RESULT, rhMethodName);
			getOperation("MethodName").addEventListener(FaultEvent.FAULT, faultHandler);
		}
 
		public function callMethodName():void{
		    getOperation("MethodName").send();        	
		}
 
		private function rhMethodName(event: ResultEvent):void{
		     // your code here	
		}
 
		private function faultHandler(fault: FaultEvent):void{
		    // your code here
		    Alert.show("Method name: " + fault.currentTarget.name + "\n \n" + fault.message.toString(), "Fault Message");
		}
	}
}
Код AS3:
package service
{
	public class MyServiceSingleton 
	{
		private static var ms: MyService;
 
		public static function getInstance():MyService{
			if(ms == null){
				ms = new MyService();
			}
			return ms;
		}
	}
}
Код AS3:
var myService: MyService = MyServiceSingleton.getInstance();
myService.callMethodName();


Последний раз редактировалось Alex_41; 23.09.2009 в 18:04.