Browse > Home > Archive: 九月 2008

| Subcribe via RSS

GlowTween:一个发光的效果类

九月 9th, 2008 | 6 Comments , 902 views | Posted by flashlizi in Flash CS3/AS3

源文件(FlashDevelop项目)下载:

点击下载此文件

Camera.getCamera()的Bug

九月 8th, 2008 | No Comments , 575 views | Posted by flashlizi in Flash CS3/AS3

帮助文档上说:“如果 getCamera() 返回 null,则表明摄像头正由另一个应用程序使用,或者系统上没有安装摄像头。 ”而实际上是,只要系统上安装了摄像头,getCamera()都能返回摄像头,而不是返回null。搜索发现已经有人把这个bug报告给了adobe,不过到了flash player 10 依然没有修正。

另外,帮助文档说使用names.length来确定是否安装了任何摄像头,其实这个也是不能完全信任的。一个明显的bug就是不管你用getCamera()或是names.length都无法在Firefox中准确确定是否安装了摄像头,在安装了摄像头驱动但却没有连上摄像头或临时拔掉摄像头的情况下,上面两种方法都会返回已安装摄像头。不过,在IE下是正常的。

还有,如果用户安装了电视捕捉卡之类的,同样有可能被识别为camera对象,但实际上是无效的camera。

这里还有一些在使用camera的时候值得注意的问题:

Tip 1.

When initiating a connection to the Camera it’s best to do this through the Microphone class. Sounds odd I know! The reason for this is when this code is called :

var camera:Camera = Camera.getCamera();
ns.attachCamera(camera);

there’s a hang just after the allow button is selected on the security dialog panel. This is rationalled in the Adobe Flash help as ‘Scanning the hardware for cameras takes time’. So it’s best to trigger the security panel via

var microphone:Microphone = Microphone.getMicrophone();
ns.attachAudio(microphone);

then listen for the Status Event of UnMuted or later in your application call

var camera:Camera = Camera.getCamera();
ns.attachCamera(camera);

There will always be a delay on this code ns.attachCamera(camera); but at least via activating the Microphone first you won’t get a bug like delay of the security panel not disappearing immediately after the allow button is pressed.

Tip 2.

When recording to a Flash Media Server make sure the camera has activity via the Activity Status Event before publishing the stream. Otherwise you may get a static or black frame at the beginning of the recorded stream.

Tip 3.

To disable/turn off the Camera after a recording is complete do so via :

ns.attachCamera(null);

Though this is actually documented for AS3 it wasn’t in AS2. Once this has been done the Camera will need to be reconnected for a new recording and users will experience this delay again as the Camera starts as mentioned above.

Tip 4.

When embedding your Flash do not change the wmode from default. Otherwise you will get problems on specific browser configurations i.e. Firefox PC . These problems include that the allow button on the security dialog box will not hide on click.

Tip 5.

When detecting wether the user has a web camera you can’t rely on Camera.names.length(). This is because there are scenarios whereby devices will appear in the list which may not be webcameras but devices like TV capture cards and can not be used as a camera. The solution for this is when the camera is attached via

var camera:Camera = Camera.getCamera();
ns.attachCamera(camera);

Then add a time out catch which can be cleared via the camera’s activity event, so that if camera activity occurs within the time out of say 5 seconds then clear the timeout. Otherwise if the timeout happens handle the error scenario.

Tip 6.

Further to the above it’s good at the point of displaying the error message to give the user an option to fix this problem. This is because it may simply be a matter of the user changing the default camera selected. This can be done via adding a button and firing the Camera devices security dialog by the following :

Security.showSettings(SecurityPanel.CAMERA);

It’s interesting to know that when the user is selecting options from the Camera devices list it’s possible to detect wether the option selected is actually a Camera. Once again this is done via camera.activityLevel>0 on the Camera’s activity event. Sadly there is not yet a reliable way to detect when the dialog panel close event occurs. So with this in mind when the user has picked a camera, you should make a noticible visual change somewhere behind the dialog box (and overlay screen) so the user will proceed to the close button – happy days.