Managing a webcam


The purpose is to manage a webcam using Swishmax. This example will use a very simple script.
I suppose you know well how to create objects, thus I will not insist on.
Let's say : it's do-it-yourselfing. As a matter of fact, Swishmax doesn't handle video objects as Flash MX does.
For that reason, I have used Flash MX, creating a scene in which I placed a video object, then I exported the stuff and ... that's it !
ActionScript inside the stage is very simple. No test of camera, it's just to demonstrate the purpose..

Here is the ActionScript in Flash MX :
a_stream = Camera.get(); // new stream
webcam.attachVideo(a_stream); // assign video to stream

At first, Download the file created with MX.

Creating Objects

Set up the movie sizes 356x270 (any background color). Frame Rate 12.
I consider the webcam 'll give us 320x240 images
Insert a sprite on the stage, name it webcam
This 'll be the container for the stream provided by the camera.
Be sure to set up the following parameters to get images in a good place.

sprite webcam   transform sprite webcam


In Outline, select Scene_1. Write the following script :

// afterPlacedObjectEvents apparaît dans la version 2004
onFrame (1,afterPlacedObjectEvents)
    tellTarget ( { loadMovie("cameraMX.swf"); }

Export after having chosen SWF6 option, plug your usb webcam in, then open the associated web page.
( Don't forget to put cameraMX.swf in the same directory )
It works locally and on a web server as well.

Conclusion :
This a workaround to get a webcam inside SwishMax while using the capabilities of this software. In other words, even you don't know Flash MX, you 'll get it.

Remark :
For those who are curious, you have to know that some ActionScript codes are readable by SwishMax but the SWF can only be tested with Flash player, not with SwihMax.
In ActionScript, I have put the 2 lines you read at the beginning, but a more sophisticated script could contain : (see Help in Flash MX)

a_stream = Camera.get();
a_mic = Microphone.get();
a_stream.setMode(320,240,8); // setup 320x240 8fps
// setup bandwidth in bytes per second and image qualitybr /> // 16384 is the default value ; quality : from 0 (lowest) to 100 (highest)
a_stream.setQuality(15000, 80);

The video object (webcam) was dropped down in the stage thru a library in Flash MX, this is missing in Swishmax.
We could have tested whether the camera is granted or not :

a_stream.onStatus = function( infoMsg )
if( infoMsg.code == "Camera.Muted") // Camera.Unmuted = granted access
{ AlertMsg = "Acces Webcam denied. Click right button and Parameters." }
else { ........ }

and many other stuffs.


Page chargée en 0.001 sec.

Dernière Modification : Jeu 12 Mai 2022 10:33
Copyright © 1999-2022 Jean-Paul Molina Tous droits réservés.


to Google