Hi Guys, I have the following code which loads a file from the FLASH MEDIA SERVER. (See below)
When I click on the playVid the video plays perfectly. The FMSConnection is an external AS3 file.
The problem is that when I press the “run_mc” the video suddenly stops.
The “run_mc” loads an XML file. Im just wondering why my video stops when I load the XML ?. Many thanks, Daragh
Any help would be greatly appraciated.
the main time line;
import com.teamSelection.teamSelectionLoader;
import com.teamSelection.MyFlashFile;
import com.teamSelection.createPlayerInfo;
import com.teamSelection.FMSConnection;
import flash.events.MouseEvent;
import flash.events.Event;
// ----------------------------------------------------------------------------------
// set up functions to display teamLineUp calls teamSelectionLoader class
// ----------------------------------------------------------------------------------
run_mc.addEventListener(MouseEvent.CLICK,displayTeam);
play_mc.addEventListener(MouseEvent.CLICK,playVid);
function displayTeam(e:Event):void
{
var todaysTeam:teamSelectionLoader = new teamSelectionLoader();
addChild(todaysTeam);
todaysTeam.x = 400;
todaysTeam.y = 200;
}
function playVid(e:Event):void
{
var fmsCon:FMSConnection = new FMSConnection;
addChild(fmsCon); <------- this adds the class FMSConnection.
}
<<CODE TO PLAY MOVIE FROM FMS>>
package com.teamSelection{
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.net.NetConnection;
import flash.events.Event;
import flash.events.NetStatusEvent;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
import fl.controls.Button;
import fl.controls.NumericStepper;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.AsyncErrorEvent;
import flash.events.NetStatusEvent;
public class FMSConnection extends MovieClip {
public static const CONNECTED:String='connected';
private var nc:NetConnection;
public var vidID="video";
public var consumerVideo:Video=new Video ;
public function FMSConnection() {
connect('rtmp://localhost/dvr/', 'DARAGH_C');
}
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.
dispatchEvent(new Event(FMSConnection.CONNECTED, true));
trace("this is the BOMB !!!");
var _ns=new NetStream(nc);
_ns.client = new Object();
addChild(consumerVideo);
consumerVideo.attachNetStream( _ns );
_ns.play( "video", 0, -1 );
_ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
} 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.");
}
function asyncErrorHandler(event:AsyncErrorEvent):void {
trace(event.text);
}
}
}