Question
actionscript 3 and rtmp
Hi all:
I'm trying to create a simple connection to my FMS sever using actionscript 3 and the Flash 9 Alpha. The code below *kind of works,* but I know it's wrong - I don't know where it's wrong, but I know that it's wrong. I've been googling, reading the articles here (state machine), and going through the AS3 cookbook, but I'm this is the closest I can get by myself.
Any help would be really appreciated.
package {
import flash.display.Sprite;
import flash.events.NetStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.net.defaultObjectEncoding.*;
public class VideoExample extends Sprite {
private var videoUrl:String = "1";
private var connection:NetConnection;
private var stream:NetStream;
//private function init():void{
// Create the NetConnection and listen for NetStatusEvent and SecurityErrorEvent events
//nc = new NetConnection();
//nc.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
//nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, netSecurityError);
//nc.connect("rtmp:/myApplication");
//}
public function VideoExample():void {
NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;
connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
connection.connect("rtmp://...videosource/");
}
private function netStatusHandler(event:NetStatusEvent):void {
switch (event.info.code) {
case "NetConnection.Connect.Success":
connectStream();
break;
}
}
private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
private function connectStream():void {
var stream:NetStream = new NetStream(connection);
var video:Video = new Video();
video.attachNetStream(stream);
stream.play(videoUrl);
addChild(video);
}
}
}
I'm trying to create a simple connection to my FMS sever using actionscript 3 and the Flash 9 Alpha. The code below *kind of works,* but I know it's wrong - I don't know where it's wrong, but I know that it's wrong. I've been googling, reading the articles here (state machine), and going through the AS3 cookbook, but I'm this is the closest I can get by myself.
Any help would be really appreciated.
package {
import flash.display.Sprite;
import flash.events.NetStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.net.defaultObjectEncoding.*;
public class VideoExample extends Sprite {
private var videoUrl:String = "1";
private var connection:NetConnection;
private var stream:NetStream;
//private function init():void{
// Create the NetConnection and listen for NetStatusEvent and SecurityErrorEvent events
//nc = new NetConnection();
//nc.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
//nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, netSecurityError);
//nc.connect("rtmp:/myApplication");
//}
public function VideoExample():void {
NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;
connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
connection.connect("rtmp://...videosource/");
}
private function netStatusHandler(event:NetStatusEvent):void {
switch (event.info.code) {
case "NetConnection.Connect.Success":
connectStream();
break;
}
}
private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
private function connectStream():void {
var stream:NetStream = new NetStream(connection);
var video:Video = new Video();
video.attachNetStream(stream);
stream.play(videoUrl);
addChild(video);
}
}
}
