Thanks for your answer. Your code looks a lot like my first try, but for sure
untested - I thought the same but the stream never returned the onStatus.
Here is my solution. Maybe other can use it. Thanks again. Nice to see
somebody understands.
I worked through the example:
//
http://www.macromedia.com/devnet/flashcom/articles/odopod.html But it was old code, so I changed everything. There also was a problem that
the old code used for-in loop many times. It was complety unneccesary, so i
fixed that to. Now it is much less cpu demanding.
import mx.data.components.XMLConnector;
import mx.utils.Delegate;
import Video;
class showFCS extends MovieClip {
private var menu_xc:XMLConnector;
private var slide:String="";
private var nc:NetConnection;
private var menuItem:Array;
private var videoToLoad:String;
private var myInputStream:NetStream;
private var i:Number;
private var intval:Number;
private var myVideo:Video;
function showFCS()
{
//create empty movieclip for loading slides
this.createEmptyMovieClip("main",2);
i=0; //first number in menuItem XML array
menuItem = new Array();
videoToLoad="modem";
nc = new NetConnection();
nc.onStatus=Delegate.create(this,onNCResult);
nc.connect("rtmp://URL_to_room_here");
myInputStream = new NetStream(nc);
myInputStream.setBufferTime(1);
myVideo.attachVideo(myInputStream);
myInputStream.onStatus=Delegate.create(this,onStreamResult);
menu_xc=new XMLConnector();
menu_xc.addEventListener("result",Delegate.create(this,onmenu_xcResult));
menu_xc.addEventListener("status",Delegate.create(this,onmenu_xcStatus));
menu_xc.direction = "receive";
menu_xc.URL = "xml/start.xml";
menu_xc.ignoreWhite=true;
menu_xc.trigger();
}
private function onNCResult(info):Void
{
if (info.code == "NetConnection.Connect.Success") {
//trace("onNCResult: "+info.code);
myInputStream.play(videoToLoad);
}else if (info.code == "NetConnection.Connect.Rejected") {
// the server has explicitly rejected the connection
//gotoAndStop("server busy");
// reject is followed by a close so you need to clear this out
nc.onStatus=null;
}else if (info.code == "NetConnection.Connect.Closed") {
// the connection has been closed
//gotoAndStop("closed connection");
}
}
private function onStreamResult(info):Void
{
//trace("onStreamResult: "+info.code);
if (info.code == "NetStream.Play.Reset") {
//reset means start
//every 30 milliseconds check if slide must be inserted to screen - function
checkslides
intval=setInterval( this, "interval", 100 );
}else if (info.code == "NetStream.Play.Start") {
//"NetStream.Play.Start," is received each time
netStream.play(),netStream.seek() and netStream.pause(false) are called
}else if (info.code == "NetStream.Buffer.Empty") {
//"NetStream.Buffer.Empty" is received when data is not streamed quickly
enough to continue playing the stream
} else if (info.code == "NetStream.Buffer.Full") {
//"NetStream.Buffer.Full,? is received when the buffer is full and the
video will begin playing.
}
}
private function interval()
{
//trace("run interval");
//retrieve the seconds from xml
var seconds:Number=parseFloat(menuItem.childNodes[3].nodeValue);
//retrieve the minutes from xml
var minutes:Number=parseFloat(menuItem.childNodes[4].nodeValue);
//calculate minutes + seconds
var time:Number=(minutes*60)+seconds;
//trace("xmltime: "+time);
var FCStime:Number=myInputStream.time;
//trace("fcstime: "+FCStime);
var showslide:Boolean=false;
if (FCStime >= time) {
slide=menuItem.childNodes[2].firstChild.nodeValue;
showslide=true;
}
if (showslide==true) {
showslide=false;
this["main"].loadMovie(slide);
this["main"]._x=Math.round(menuItem.childNodes[4].firstChild.nodeValue);
this["main"]._y=Math.round(menuItem.childNodes[5].firstChild.nodeValue);
i++;
if (i>=menuItem.length) {
clearInterval(intval);
}
}
}
private function onmenu_xcResult(evt:Object):Void
{
//trace(evt.target.results);
//start connect to commserver
menuItem=evt.target.results.firstChild.childNodes;
}
private function onmenu_xcStatus(evt:Object):Void
{
//trace("XMLstatus::"+evt.code);
//no xml file - do some usability for user
//check if evt.target.results is empty == undefined
}
}