Hi,
I have been looking for a solution for this several days now but can not find a solution.
Basicaly, this is what the program does :
it opens a netconnection and a netstream for a life webcam. Once the netstream is openend, I am polling (with setInterval) a webpage for a certain value to change, so I making each two seconds a query to a webpage and anaylsing the XML answer.
Now the problem I am having is that once I start polling my webpage, the active netstream is closed (sooner or later) without any further indications. it just disappears in the FMS console.
To make things weirder, the netstream is closed almost instantly (after a few seconds) when I run the program in the Flash CS3 Debug tool, and stays up longer but dies anyway when I test the application with the Flash CS3 Test Movie option. When I publish the movie and run it directly in the Flash 9 player, it also dies very fast. But it is very inconsistent because sometimes it stays up longer. When I take out the setInterval and just call the website polling once, it seems to stay live, but there are situations that it still dies.
Here the code of my test program :
stop();
var locations_id = 2;
var myInterval = “”;
// LOCATION WEBCAM HANDLING
var user_mic = Microphone.getMicrophone();
var user_cam = Camera.getCamera();
content_vid.attachCamera(user_cam);
var nc:NetConnection = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
nc.connect(“rtmp://209.190.33.154/security/”,locations_id);
function sendCommand()
{
var params:URLVariables = new URLVariables();
params.action = “test”;
sendData(“http://www.antunez.b iz/surveyATM/test.php”,params);
}
function sendData(url:String, _vars:URLVariables):void
{
var request:URLRequest = new URLRequest(url);
var loader:URLLoader = new URLLoader();
// loader.dataFormat = URLLoaderDataFormat.VARIABLES; --> XML
request.data = _vars;
request.method = URLRequestMethod.POST;
loader.addEventListener(Event.COMPLETE, handleComplete);
loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
trace(“send data”);
loader.load(request);
}
function handleComplete(event:Event):void
{
var loader:URLLoader = URLLoader(event.target);
var dataXML:XML = XML(loader.data);
trace(dataXML);
if(dataXML.conf.@action.toStri ng() == “test”)
{
trace(“All fine”);
clearInterval(myInterval);
}
else
{
trace(“continue”);
}
}
function onIOError(event:IOErrorEvent):void
{
trace(“Error loading URL.”);
}
function connectStream():void
{
var ns:NetStream = new NetStream(nc);
ns.attachAudio(user_mic);
ns.attachCamera(user_cam);
ns.addEventListener(NetStatusE vent.NET_STATUS, onStreamStatus);
ns.addEventListener(AsyncError Event.ASYNC_ERROR, onStreamAsyncError);
ns.addEventListener(IOErrorEve nt.IO_ERROR, onStreamIOError);
ns.publish(“security/” + locations_id, “live”);
}
function onNetStatus(evt:NetStatusEvent):void
{
switch(evt.info.code)
{
case “NetConnection.Connect.Success”:
trace(evt.info.code);
connectStream();
myInterval = setInterval(sendCommand,2000);
break;
case “NetConnection.Connect.Failed”:
trace(evt.info.code);
break;
case “NetStream.Play.StreamNotFound”:
trace(“not found”);
break;
}
}
function onStreamStatus(evt:NetStatusEvent):void
{
trace(“Stream Status”)
trace(evt.info.code);
}
function onStreamAsyncError(evt:AsyncErrorEvent):void
{
trace(“Stream Async Error”)
}
function onStreamIOError(evt:IOErrorEvent):void
{
trace(“Stream IO Error”)
}
and the output it generates :
NetConnection.Connect.Success
Stream Status
NetStream.Publish.Start
send data
<session>
<conf action=“test2”/>
</session>
continue
send data
<session>
<conf action=“test2”/>
</session>
continue
send data
<session>
<conf action=“test2”/>
</session>
continue
send data
<session>
<conf action=“test2”/>
</session>
continue
etc
Any help would be widely appreciated, even if it are just ideas to put me in the right direction to esolve this