all groups > macromedia flash flashcom > september 2005 >
You're in the

macromedia flash flashcom

group:

NetStream problem in AS Class file


NetStream problem in AS Class file flash-hero
9/17/2005 12:41:03 PM
macromedia flash flashcom:
I have a class like this:
import mx.utils.Delegate;
class showFCS extends MovieClip {
private var nc:NetConnection;
private var menuItem:Array;
private var videoToLoad:String;
private var myInputStream:NetStream;
function showFCS()
{
nc = new NetConnection();
nc.onStatus=Delegate.create(this,onNCResult);
myInputStream = new NetStream(nc);
myInputStream.setBufferTime(1);
myVideo.attachVideo(myInputStream);
myInputStream.onStatus=Delegate.create(this,onStreamResult);
nc.connect("rtmp://URL-Here");
}
....more code
}
My problem is that I can delegate nc perfectly to the function, but the
netstream returns nothing/do not delegate to the function when i call,
myInputStream.play(videoToLoad);

Any ideas?

fh

Re: NetStream problem in AS Class file andre.fuller
9/20/2005 12:00:00 AM
Off the top of my head, you shouldn't create the netstream until you're
connected to flashcom (so after you receive "NetConnection.Connect.Success")

Here's some quick as to get you going, albeit untested:

import mx.utils.Delegate;
class ShowFCS extends MovieClip
{
private var nc:NetConnection;
private var menuItem:Array;
private var videoToLoad:String = "";
private var myInputStream:NetStream;

public function ShowFCS()
{
//Initialize Array
menuItem = new Array();

//Create connection
nc = new NetConnection();
nc.onStatus = Delegate.create(this, onNCResult);

//Start the fcs ball rolling
nc.connect("rtmp://URL-Here");
}

private function onNCResult(infoObj:Object):Void
{
if (infoObj.code == "NetConnection.Connect.Success")
{
myInputStream = new NetStream(nc);
myInputStream.setBufferTime(1);
myVideo.attachVideo(myInputStream);

myInputStream.onStatus = Delegate.create(this, onStreamResult);

//Play recorded stream
myInputStream.play(videoToLoad, 0);
}
}

private function onStreamResult(infoObj:Object):Void
{

}
}
Re: NetStream problem in AS Class file flash-hero
9/20/2005 12:00:00 AM
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
}
}
AddThis Social Bookmark Button