mardi 8 juin 2010

Using a webcam

Today we will be fooling around with webcam and microphone.

First of all we can load a webcam on the screen (or stage). This is done in a function.

The webcam can trigger loading of images and playing of sounds etc, so can the microphone.

The structure of the script is not too difficult: you add an object (there is the box again), this object is a webcam for tonight. Then you add an eventlistener. And the eventlisteners triggers a function when the event happens.

So we have:
  • webcam
  • eventlistener
  • function on event
This is the same as:
  • keyboard - eventlistener - function on event
  • mouse - eventlistener - function on event
In the function you can put what you want, it can be loading an image, playing a sound...starting a movie......

The making of the webcam is also a function. This is like the functions of loading an image or streaming a sound. In principle you can copy paste these functions and use them like black boxes.

The working examples can be found here:
http://www.contrechoc.com/flash/flash-fun.zip


Some funny examples from former classes:
http://www.contrechoc.com/flash/DanutasSnorrenShow/webcam.html
Made by Danuta, in her movie your mustache is changed when moving around!

Security setting
Flash is played from website on your computer. So flash movies are not supposed to be able to get data from your computer. Nor are flash movies supposed to activate your webcam without your consent. So every time you use the webcam you have to give permission to do this.

So there is a possibility that when you start the movie with the webcam it wont play immediately.
If nothing is playing or the mic does not respond, first verify if the computer has a mic or webcam, and then try clicking right in the flash window and look at the settings.

More can be done with the webcam than you think: Augmented Reality Flash, or Multitouch Flash is done also with this simple webcam.

Remark: close scrutiny showed that the activity handler is always triggering two times before tting into the normal waiting for a trigger mode. So to do it well,

used:

* webcam activity: eventlistener
* microphone activity: eventlistener

Aucun commentaire:

Enregistrer un commentaire