Camera Class Quirks with FMS

I did a project recently requiring a web camera recording to Flash Media Server 3. Whilst I was working on this I found out some interesting (annoying) things about the Camera class. These include :


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.

Google, Windows, Yahoo, Ask Maps API for AS3/AS2/Flex

It’s been some time coming though I’ve finally had time to finish the AS3 build of my universal maps code. It’s available for download free of charge (though donations are apreciated) from the same SVN repository and the details for this are below. As well included is the original AS2 version in the legacy.zip file.

It’s been a nice to re-build this project from scratch by taking full advantage of AS3 to simplify the original AS2 universal maps code as it’s now 95 classes from over 500 but still offering almost all the inital functionality! As well not to mention the amazing performance differences between AVM1 and 2. I haven’t gotten around to full documentation (will soon) but there are samples included on all the maps sources to easily get you started.

Here are some examples…

Google Maps

Windows Virtual Earth Maps with Birds Eye View

Windows Virtual Earth Maps

Google Mars Maps

Google Moon Maps

Yahoo Maps

Download the source from the following SVN details
SVN: http://lostinactionscript.unfuddle.com/svn/lostinactionscript_flashmapservices/
username : lostinactionscript_guest
password : guest
Don’t have an SVN client? I recommend you use Tortoise - get it here or if you’re an Eclipse user try Subclipse

To compile with Flex I used the command line arguments on the GoogleMapFlex example class :
-default-size 512 512 -default-frame-rate 31 -default-background-color 0x262B2D -library-path {flexSDK}/frameworks/locale/en_US -verbose-stacktraces
To publish a different example using Flex just make sure the class extends UniMapFlex rather than UniMap and that’s it.

View online documention

You Tube Flash AS3 / AS2 API

Recently I have been working on something involving the use of video content from You Tube. With the lack of a good API out there I created my own. Below is a simple example of this working with sample code to download further below.

AS3 example

Actionscript:
  1. import com.FlashDynamix.services.YouTube;
  2. import com.FlashDynamix.events.YouTubeEvent;
  3. //
  4. var yt:YouTube = new YouTube();
  5. yt.APIKey = "WplekwLy_Nw";
  6. function onLoaded(e:YouTubeEvent) {
  7.     switch (e.method) {
  8.         case YouTube.VIDEOSBYTAG :
  9.         try {
  10.             for each (var video:XML in data) {
  11.                 trace(video.name() + " : " + video);
  12.             }
  13.             trace("Videos For Tag : " + e.request.tag + " : " + e.data.length());
  14.         } catch (evt:ArgumentError) {
  15.             trace("ERROR : No Videos For Tag");
  16.         }
  17.     }
  18. }
  19. //
  20. yt.addEventListener(YouTubeEvent.COMPLETE, onLoaded);
  21. yt.videosbyTag("Top Gear");

AS2 example

Actionscript:
  1. import com.FlashDynamix.services.YouTube;
  2. //
  3. var yt:YouTube = new YouTube();
  4. yt.APIKey = "WplekwLy_Nw";
  5. var obj:Object = new Object();
  6. obj.loaded = function(evt:EventArgs) {
  7.     switch (evt.type) {
  8.         case YouTube.VIDEOSBYTAG :
  9.             var videos = evt.value.video;
  10.         break;
  11.     }
  12. };
  13. //
  14. yt.addListeners(obj);
  15. yt.videosbyTag("Top Gear");

The class I created YouTube.as supports both the legacy and current version of the YouTube API legacy documentation and current documentation.

Download the source here

The Seeker : The Dark Is Rising

The Seeker : The Dark Is RisingFor the last month I have been working on 2 phases of a movie site called the The Seeker : The Dark Is Rising. The Seeker is Eragon meets Harry Potter meets Peter Pan which has been a challenge in it's self. Though additionally to this it's been even more challenging to get through the build as the site is completely multilingual with exchangeable fonts. This sites a big load I know but the guys wanted epic and they got it in file size too - but hey those are some nice animations. One interesting part to the site is the ability for users to unlock site content by codes / sign sequences found on external media. Then like many movie sites people can embed some Flash into there page to track there progress of finding the signs you can see mine below.

There are also 6 mini games which can be embedded in webpages here.

Check out the site

Have your say | Filed Under: Work | The Post ›

Douglas Peuker Line Generalization

Just recently I have been working on some code which required line generalization for Flash from drawings / poly line data. I have posted up sample code and a demonstration SWF to show the results of these tests. I found that the Douglas Peuker algorithm was the simplest to implement the results are pretty good. The only down point is code only usually runs in O(n log m) time where m the number of points is small. I would like to try and speed this up by a technique using the Melkman convex hull algorithm based on a paper written by Hershberger & Snoeyink they split the lower and higher bounds to increase performance on the simplification process.

Download the source code here




Me

I am Shane McCartney a Flash Developer who's currently working in London as a Flash contractor. If you would like me to do contract work for you, why not contact me at shanem@flashdynamix.com.

Donate

If you find the source code or information provided on this site of such use that you would like to donate please do it is appreciated.

Your donation will help us to provide even more source code to the community and cover the cost of time to develop and maintain the source code we provide, thank you.