Motion Detection Revisited

July 30th, 2009

About 2 years ago I did some experiments with ActionScript 3 and motion detection.  Looking back I had no idea what what the ActionScript I pieced together was doing.  I have since gained a better understanding of some of the low level bitmap data functions available in AS3.  I threw this together last night and am quite pleased with the result.  It is a virtual drum game.  The game works best if you get out of you chair and position yourself such that your hand is the same size as a drum.  I have separated the motion detection logic so that it can be reused on any DisplayObject.  Also it is not nearly as memory intensive as the first implementation.  I took the sounds from http://www.themaninblue.com/experiment/JS-909/ (thanks Cameron Adams).  Here is a demo.  Here is the source.  This is a proof of concept and certainly not the first AS3 web cam motion detection experiment.  I am curious to hear what you think of my implementation.

Swagger…

July 30th, 2009

Merriam-webster provides the following information with reguard to “swagger’
Inflected Form(s):
swag·gered; swag·ger·ing
Etymology:
probably from 1swag + -er (as in chatter)
Date:
circa 1596
intransitive verb1: to conduct oneself in an arrogant or superciliously pompous manner ; especially : to walk with an air of overbearing self-confidence2: boast, brag

Seven-Year Old Kid Can Dance - Watch more Funny Videos

Congrats Dad

July 23rd, 2009

Congrats on your promotion Dad.

The spices

July 21st, 2009

One day found this gem in my voicemail.  I don’t know if it is a prank call from one of my buddies or if this guy really dialed the wrong number, but I do know it’s super funny.

My first sand sculpture

July 21st, 2009

I went to Pismo beach this weekend.  It was a lot of fun.  While I was there I started “playing” (insert cheap joke here) with the sand.  Here is what came out of it.

I will miss you.

June 26th, 2009

In memory of Michael Jackson.

Flex Module with in a Module Bug (Fixed in Gumbo)

March 7th, 2009

I know I am not the first to encounter this, but I thought it worth a mention anyway.  I ran in to an issue loading a module from with in a module using flex.  The module would load, but the ModuleEvent.READY would not fire.  The instance of the module was ready and setup was true.  WTF!!! why!  After searching the net I came across this bug https://bugs.adobe.com/jira/browse/SDK-14669.  It said a workaround is to load all the modules sequentially.  Now I know this sucks because 1 by 1 is not exactly a model of efficiency.  Anyhoo…I threw the following class together and thought it would help:


/**
* this class is to get around this bug
* https://bugs.adobe.com/jira/browse/SDK-14669
* when we move to gumbo (flex 4) the bug will be fixed
* */

package com.timothyhuertas.utils
{
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
import flash.system.ApplicationDomain;
import flash.system.SecurityDomain;
import flash.utils.ByteArray;

import mx.events.ModuleEvent;
import mx.modules.IModuleInfo;

public class SequentialModuleLoader extends EventDispatcher
{
private static var _instance:SequentialModuleLoader;
private var _pool:Array;
private var _current:IModuleInfo;

public function SequentialModuleLoader(value:SingletonEnforcer)
{
_pool = new Array();
}

public static function get instance() : SequentialModuleLoader
{
if(!_instance)
{
_instance = new SequentialModuleLoader(new SingletonEnforcer());
}
return _instance;
}

public function load(info:IModuleInfo, applicationDomain:ApplicationDomain=null, securityDomain:SecurityDomain=null, bytes:ByteArray=null) : void
{
var queued:Object = new Object;
queued.info = info;
queued.applicationDomain = applicationDomain;
queued.securityDomain = securityDomain;
queued.bytes = bytes;
_pool.push(queued);
processPool();
}

protected function processPool() : void
{
if(_pool.length && _current==null)
{
var queued:Object = _pool[0];
_pool.splice(0,1);
_current = queued.info as IModuleInfo;
_current.addEventListener(ModuleEvent.READY, handleModuleResponse, false,0,true);
_current.addEventListener(ModuleEvent.ERROR, handleModuleResponse, false,0,true);
_current.load(queued.applicationDomain, queued.securityDomain, queued.bytes);
}
}

protected function handleModuleResponse(e:ModuleEvent) : void
{
IEventDispatcher(e.target).removeEventListener(e.type, handleModuleResponse);
_current = null;
processPool();
}

}
}
class SingletonEnforcer{}

An example of its usage is as follows:


var m:IModuleInfo = ModuleManager.getModule("Mod1.swf");
m.addEventListener(ModuleEvent.READY, modLoaded);
SequentialModuleLoader.instance.load(m,ApplicationDomain.currentDomain);

protected function modLoaded(e:ModuleEvent):void
{
IEventDispatcher(e.target).removeEventListener(e.type, modLoaded);
IModuleInfo(e.target).factory.create();
}

I hope this helps

Why?

January 29th, 2009

This is pure comedy

December 12th, 2008

Which comment is more gangster?

December 6th, 2008

Which comment is more gangster?  “Now you’s can’t leave” or “Look at me.  I’m the one who did this to you.  Remember me.”