ActionScript 3 基本FMS连接AS3

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 基本FMS连接AS3相关的知识,希望对你有一定的参考价值。

package  {
	
	import flash.display.Sprite;
	import flash.net.NetConnection;
	import flash.events.Event;
	import flash.events.NetStatusEvent;
	import flash.events.IOErrorEvent;
	import flash.events.SecurityErrorEvent;
	
	
	public class FMSConnection extends Sprite {
		public static const CONNECTED:String = 'connected';
		private var nc:NetConnection;
		
		public function FMSConnection() {
			// constructor code
			connect('rtmp://YOUR-SERVERSIDE-APP', 'USERNAME');
		}
		
		public function connect(url:String, username:String):void 
		{
			// Create new net connection
			nc = new NetConnection();
			// Set this instance/class to receive callback functions.
			nc.client = this;
			// Call the connect method on the FMS and pass in the username.
			nc.connect(url, username);
			
			nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
			nc.addEventListener(IOErrorEvent.IO_ERROR, onIoError);
			nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
		}
		
		private function onNetStatus(event:NetStatusEvent):void
		{
			if(event.info.code == "NetConnection.Connect.Success")
			{
				trace("Connected To server");
				// Dispatch event letting the application know it connected.
				// Do Stuff here!
				dispatchEvent(new Event(FMSConnection.CONNECTED, true));
			}else{
				throw new Error("Failed to connect to server!");
			}
		}
		
		private function onIoError(event:IOErrorEvent):void
		{
			throw new Error("IO Error on connection.");
		}
		
		private function onSecurityError(event:SecurityErrorEvent):void
		{
			throw new Error("Security Error on connection.");
		}
	}
	/////////////////////////////////////////
	/* Brian Shantz -- 2010 */
	/* http://www.brianshantz.com */
	/* Flash Media Server Connection Script */
	/////////////////////////////////////////
}

以上是关于ActionScript 3 基本FMS连接AS3的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript 3 检查AS3中的连接

ActionScript 3 AS3 | KCComponent |基本组件

ActionScript 3 AS3:基本计时器示例

ActionScript 3 AS3 ComboBox极其基本的例子

ActionScript 3 AS3:正则表达式基本示例

ActionScript 3 AS3:基本多点触控示例