Skip to content

Instantly share code, notes, and snippets.

@Nutrox
Nutrox / GameKeyboard.as
Created May 3, 2011 01:39
GameKeyboard Class
package com.retromodular
{
import com.retromodular.listeners.IKeyboardListener;
import flash.events.KeyboardEvent;
import flash.utils.Dictionary;
/**
*/
public final class GameKeyboard extends GameSystem
@Nutrox
Nutrox / Singleton.as
Created May 2, 2011 22:06
Easy Singleton Example
package
{
public class Singleton
{
static public const instance:Singleton = new Singleton();
public function Singleton()
{
if( instance )
{
var Example = new function() {
var anotherWord = "banana";
return function ExampleConstructor( word ) {
this.word = word;
//
this.toString = toString;
this.getStatic = getStatic;
}
@Nutrox
Nutrox / gist:860290
Created March 8, 2011 14:05
JavaScript - Flash Player Plugin Detection
var o;
var v;
var x = /([0-9]+).([0-9]+).[\w]?([0-9]+)/;
try {
o = navigator.plugins["Shockwave Flash"];
v = o.description.match( x );
}
catch( error ) {
try {
o = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
package {
import com.adobe.utils.AGALMiniAssembler;
import flash.display.Bitmap;
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageQuality;
import flash.display.StageScaleMode;
@Nutrox
Nutrox / gist:820192
Created February 10, 2011 09:25
JavaScript - Array Cast Utility
Array.cast = function( o ) {
return Array.prototype.slice.call( o, o );
}
//
// EXAMPLES
//
function foo() {
// arguments to array
@Nutrox
Nutrox / gist:818368
Created February 9, 2011 12:06
JavaScript - Media Playback Detection
// this is part of my core javascript code, it detects flash and MP4 media playback capabilities
window.core = new function() {
var document = window.document;
var navigator = window.navigator;
var flashVersion = null;
var flashAvailable = false;
var audioAvailable = false; // MP4
var videoAvailable = false; // MP4
@Nutrox
Nutrox / gist:812170
Created February 5, 2011 03:16
JavaScript - HTML5/MP4 Media Detection
o = document.createElement( "audio" );
if( o.canPlayType ) {
audioAvailable = o.canPlayType( 'audio/mp4; codecs="mp4a"' ) == "probably";
}
o = document.createElement( "video" );
if( o.canPlayType ) {
videoAvailable = o.canPlayType( 'video/mp4; codecs="avc1,mp4a"' ) == "probably";
}
// NOTE: The codecs must be double-quoted
@Nutrox
Nutrox / gist:804886
Created January 31, 2011 21:44
JavaScript - Handy getEvent() Function
// This function SHOULD be called directly by an event listener (see example).
// Works in Chrome, Firefox, MSIE, Opera and Safari.
window.getEvent = function() {
var event = getEvent.caller.arguments[0];
return event ? event : window.event;
}
//
// Example
//
@Nutrox
Nutrox / gist:804358
Created January 31, 2011 16:54
JavaScript - Partial HTML5 element rendering fix for MSIE
if( /MSIE [6-8]\./.test(navigator.userAgent) ) {
// These elements will be treated like <span> elements by MSIE,
// but you can use CSS to style them like any other element.
var elements = [
"article",
"aside",
"footer",
"header",
"nav",
"section"