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”.
The first problem I see is that your function setConnection has the return type void (which means that the function returns nothing).
should be
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.