Показать сообщение отдельно
Старый 26.02.2012, 20:20
ЗлОй ПрОграММер вне форума Посмотреть профиль Отправить личное сообщение для ЗлОй ПрОграММер Найти все сообщения от ЗлОй ПрОграММер
  № 6  
Ответить с цитированием
ЗлОй ПрОграММер

Регистрация: Nov 2010
Сообщений: 434
чтобы не плодить тем отпишусь здесь, надеюсь автор не против всё же задачи одинаковые
мне нужно связать 2 флешки, делал всё по этой теме но нечего не вышло(флешка не видит когда к ней подключатся другая) пожалуйста подскажите в чём ошибка
Код AS3:
package 
 {
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.MouseEvent;
	import flash.net.NetConnection;
	import flash.net.NetStream;
	import flash.events.NetStatusEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;
 
	public class MainClass extends MovieClip 
	{
		private const CirrusAddress: String = "rtmfp://p2p.rtmfp.net/";
		private const DeveloperKey: String = "xxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxx";
 
		private var netConnection: NetConnection = new NetConnection();
		private var nearPeerID: String;
		private var farPeerID: String;
 
		private var sendStream: NetStream;
		private var recvStream: NetStream;
 
		private var notificationText: TextField = new TextField();
 
		public function MainClass(): void 
		{
		//----------------------------------------------------------------------
			if (stage) Initialization()
			else addEventListener(Event.ADDED_TO_STAGE, Initialization);
		//----------------------------------------------------------------------
		}
 
		private function Initialization(e: Event = null): void 
		{
		//----------------------------------------------------------------------	
			addNotificationText();
		//----------------------------------------------------------------------
			netConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
			netConnection.connect(CirrusAddress, DeveloperKey);
		//----------------------------------------------------------------------
			addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
			removeEventListener(Event.ADDED_TO_STAGE, Initialization);
		//----------------------------------------------------------------------
		}
 
		private function mouseDown(e: MouseEvent): void
		{
		//----------------------------------------------------------------------
			sendMessage("P2P");
		//----------------------------------------------------------------------
		}
 
		/*
		 * В случае, если с Cirrus состоялось успешное соединение, у NetStatusEvent.NET_STATUS свойству info.code 
		 * будет присвоена строка «NetConnection.Connect.Success».
		 */
		private function netStatusHandler(e: NetStatusEvent): void
		{
		//----------------------------------------------------------------------		
			trace(e.info.code); 
			if (e.info.code == "NetConnection.Connect.Success")
			{
				nearPeerID = netConnection.nearID;
				farPeerID = netConnection.farID;
				initSendStream();
			}
			if (e.info.code == "NetStream.Publish.Start")
			{
 
			}
		//----------------------------------------------------------------------	
		}
 
		private function initSendStream(): void
		{
		//----------------------------------------------------------------------
			sendStream = new NetStream(netConnection, NetStream.DIRECT_CONNECTIONS);
			sendStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);	
			sendStream.publish("media");
 
			var sendStreamClient: Object = new Object(); 
			sendStreamClient.onPeerConnect = function(farStream: NetStream): Boolean 
			{ 
				initRecvStream(farStream.farID);
				return true; 
			} 
			sendStream.client = sendStreamClient;
		//----------------------------------------------------------------------	
		}
 
		private function initRecvStream(peerID: String): void
		{
		//----------------------------------------------------------------------
			recvStream = new NetStream(netConnection, peerID);
			recvStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
			recvStream.play("media");
			recvStream.client = this;
		//----------------------------------------------------------------------
		}
 
		public function sendMessage(message: String): void
		{
		//----------------------------------------------------------------------
			sendStream.send("recvMessage", message);
			recvMessage(message);
		//----------------------------------------------------------------------
		}
 
		public function recvMessage(message: String): void
		{
		//----------------------------------------------------------------------
			notificationText.appendText(message);
		//----------------------------------------------------------------------
		}
 
		private function addNotificationText(): void 
		{
		//----------------------------------------------------------------------
			var textFormat: TextFormat;
		//----------------------------------------------------------------------
			textFormat = new TextFormat("Courier New", 20, null, true);
			textFormat.align = "center";
			notificationText.x = 0;
			notificationText.y = 0;
			notificationText.width = 800;
			notificationText.height = 700;
			notificationText.defaultTextFormat = textFormat;
			notificationText.wordWrap = true;
			notificationText.selectable = false;
			addChild(notificationText);
		//----------------------------------------------------------------------
		}
 
	}
 
}