Reputation: 413
I am having a lot of problems with setting up a webcam connection. I read that I should use a class for the connection, so that the onBWDone() method is defined and I don't get an error about this method.
The actionscript class:
package cam {
public class WebcamSetup {
public var appURL:String;
public function setConnection():NetStream
{
nc:NetConnection = new NetConnection();
nc.client = this;
nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncError);
nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
nc.connect(appURL);
ns:NetStream = new NetStream(nc);
return ns;
}
public function onBWDone():void{
}
}
}
In the flash file, I do this:
import cam.WebcamSetup;
var wc:WebcamSetup = new WebcamSetup();
wc.appURL = "rtmp://xxxxx";
var nss:NetStream = wc.setConnection();
var camera = Camera.getCamera();
if (camera != null){
myVid.attachCamera(camera);
nss.attachCamera(camera);
}
I get loads of "undefined method" and "undefined property" errors. And can I not do a return like this? I get the error "return value must be undefined".
Upvotes: 0
Views: 432
Reputation: 4434
i've answered almost the same question yesterday (you should wait for NetConnection to connect before creating a NetStream)
and btw your nss
and camera
variables have no type declaration and var nss = wc.setConnection();
means nothing as long as setConnection()
returns void
Upvotes: 0
Reputation: 4698
The first problem I see is that your function setConnection has the return type void (which means that the function returns nothing).
public function setConnection():void
should be
public function setConnection():NetStream
Then AS3 knows that the object returned from the setConnection function will be of the type NetStream.
It would be useful if you pasted the errors you're getting.
Is getCamera a static function within the Camera class? It's hard to know what's happening.
Upvotes: 1