Deprecated: Assigning the return value of new by reference is deprecated in /var/www/omflash.dk/public_html/wp-includes/cache.php on line 33

Deprecated: Assigning the return value of new by reference is deprecated in /var/www/omflash.dk/public_html/wp-content/plugins/sem-subscribe-me2/sem-subscribe-me.php on line 511

Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method UltimateTagWarriorActions::ultimate_query_vars() should not be called statically in /var/www/omflash.dk/public_html/wp-includes/functions.php on line 1252

Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method UltimateTagWarriorActions::ultimate_posts_where() should not be called statically in /var/www/omflash.dk/public_html/wp-includes/functions.php on line 1252

Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method UltimateTagWarriorActions::ultimate_posts_join() should not be called statically in /var/www/omflash.dk/public_html/wp-includes/functions.php on line 1252

Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method UltimateTagWarriorActions::ultimate_tag_templates() should not be called statically in /var/www/omflash.dk/public_html/wp-includes/functions.php on line 1329
webcamhelper - omFlash();
Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method UltimateTagWarriorActions::ultimate_add_ajax_javascript() should not be called statically in /var/www/omflash.dk/public_html/wp-includes/functions.php on line 1329

WebcamHelper - Nemmere adgang til webcam i ActionScript 3

Kategori: Tips og tricks | Kommentarer (0)
Gemt: 2009-11-17 10:46



Deprecated: preg_replace() [function.preg-replace]: The /e modifier is deprecated, use preg_replace_callback instead in /var/www/omflash.dk/public_html/wp-includes/functions-formatting.php on line 83

Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method UltimateTagWarriorActions::ultimate_the_content_filter() should not be called statically in /var/www/omflash.dk/public_html/wp-includes/functions.php on line 1252

Strict Standards: Non-static method UltimateTagWarriorActions::regExEscape() should not be called statically in /var/www/omflash.dk/public_html/wp-content/plugins/UltimateTagWarrior/ultimate-tag-warrior-actions.php on line 638

Strict Standards: Non-static method UltimateTagWarriorActions::regExEscape() should not be called statically in /var/www/omflash.dk/public_html/wp-content/plugins/UltimateTagWarrior/ultimate-tag-warrior-actions.php on line 638

Strict Standards: Non-static method UltimateTagWarriorActions::regExEscape() should not be called statically in /var/www/omflash.dk/public_html/wp-content/plugins/UltimateTagWarrior/ultimate-tag-warrior-actions.php on line 639

Strict Standards: Non-static method UltimateTagWarriorActions::regExEscape() should not be called statically in /var/www/omflash.dk/public_html/wp-content/plugins/UltimateTagWarrior/ultimate-tag-warrior-actions.php on line 639

Strict Standards: Non-static method UltimateTagWarriorActions::replaceTagWithLink() should not be called statically in /var/www/omflash.dk/public_html/wp-content/plugins/UltimateTagWarrior/ultimate-tag-warrior-actions.php on line 643

I forbindelse med Hit the Bitch, som vi lancerede i sidste uge, var en af de ting der drillede mig, at få webcam-integrationen til at virke gnidningsløst.
Her tænker jeg ikke på selve motion-detection tingen, men den basale funktionalitet med at finde ud af om man har adgang til brugerens webcam og hvis ikke, så at spørge om den.

Og, hvad nu hvis brugeren har givet en adgang til webcammet, men senere fjerner muligheden igen, eller ikke giver tilladelsen fra start og efetrfølgende slår det til?

Der er en lang række if’er, som gjorde det enormt besværligt at bygge det smidigt ind i den kode som jeg havde i forvejen, så derfor blev resultatet en lille WebcamHelper-klasse.

Med denne klasse, så foregår adgang til webcammet på denne måde:

public function CamTest():void {
	webcamHelper = new WebcamHelper();
	webcamHelper.addEventListener(StatusEvent.STATUS, webcamAvailable);
	webcamHelper.getWebcam();
}

public function webcamAvailable(_e:StatusEvent):void {
	trace("isAvailable: " + webcamHelper.isAvailable);
	if (webcamHelper.isAvailable && myVideo == null) {
		myVideo = new Video(320, 240);
		myVideo.attachCamera(webcamHelper.camera);
		addChild(myVideo);
	}
}

Det der gør det lidt interessant er, at der kommer en StatusEvent fra klassen hver gang at adgangen til webcammet ændrer sig, hvilket gør det nemt at lave noget kode som tager højde for hvad der så skal ske (ikke en del af eksemplet).

Hvis du synes det lyder interessant, så kan klassen og eksemplet downloades her:
WebcamHelper.zip