Slowly but surely I am getting my head around Actionscript 2 and OOP. Here's the result of my first attempt at writing a component - please don't hold me responsible for any bad practices or other bugs as I am still on a very steep learning curve.

If there is anything you think could be improved or added to this then please do drop me an email and I will add your comments to this article.
NOTE: Just to clarify, this is not a 'traditional' communication component, there is no serverside code involved and neither can you or should you connect this component by using simpleconnect.

What does the component look like?
It looks like a simple combobox with label. Here you can see it used alongside a video object to demo its functionality.

What does it do for me?
It automatically populates itself with all available camera drivers so may save you a little time and effort in your next project. I personally keep finding myself right clicking movies and selecting the correct camera - for example the camera of my regularly used Logitech cam is 1 not 0.

How do I use it?
To install the swc compiled component simply copy it to your user level components folder. You may want to create a new folder in there and copy the swc into that.
Typical paths to the user level components folder are as follows:

  • Windows: \Documents and Settings\username\Local Settings\Application Data\Macromedia\Flash MX 2004\language\Configuration\Components
  • Macintosh: HD/Users/username/Library/Application Support/Macromedia/Flash MX 2004/language/Configuration/Components

Next reload your components panel and you should see the new component.

Then just drag and drop it on stage, give it an instance name such as camchooser and you can access the camera index programmatically via [yourcomponentinstance].camindex or [yourcomponentinstance].camera

camchooser.camindex (this will return a number indicating the index of the currently selected camera in the combobox) (this will return the actual camera object selected in the combobox)

To hook that camera up to a video object on stage with the instance name myvid do this:

The component also broadcasts a change event which you can trap like this:
camListener = new Object();
camListener.change = function(eventObject){
camchooser.addEventListener("change", camListener);

No big deal, I could have written such a simple component myself
Fair enough but you're missing the point. This was a learning exercise for me and I hope it will encourage other developers to get started with writing their own components. I am hooked and I promise the next component will be more involved :-)

Where can I download it?
You can download all sources as well as the finished component here.

Many thanks to Jesse Warden for his excellent Captivate presentation on building a login component. Without it I wouldn't have been able to write this component. Check out his tutorial and you will understand why I have been slick today ;-)