BulkLoader Note

November 8th, 2009

Worked w/ br.com.stimuli’s BulkLoader today… was looking for a way to access the contentLoaderInfo property of one of the items, turns out the method to use is getDisplayObjectLoader. This method will return a Loader object; I can then use getDisplayObjectLoader(’whatever’).contentLoaderInfo to grab LoaderInfo properties.

This was helpful in grabbing dynamically loaded fonts (fonts embedded in several swfs) where i needed to access the applicationDomain.getDefinition method to grab the class associated w/ the font.

I’ll post some source code showing how I implemented a BulkLoader with dynamic font loading in the future…

Update: when doing the font classes (loading a SWF with an embedded font as a class)… use BulkLoader.getContent, which returns an untyped object (*).

Note: hasItem, checks if an item has loaded yet…

Papervision3D – VideoStreamMaterial (Looping FLV)

October 6th, 2009

to loop a VideoStreamMaterial (VSM) in P3D, i had to destroy the plane’s old material using the Plane.destroy method. then create a new VSM and (re)apply it to the primitive Plane.

remember to force VideoStreamMaterial’s animated and smooth properties to true

also be wary of VSM clipping parts of the video! to fix this simply override the VideoStreamMaterial.rect property with a new Rectangle of appropriate dimensions.

vm.rect = new Rectangle(0, 0, vp.width, vp.height + 27);

OH! almost forgot… not sure if this is applicable with my above fix anymore, but worth mentioning:

in org.papervision3d.materials.VideoStreamMaterial the onStreamStatus private function event handler must be updated!!! animated needs to be true for the “NetStream.Pause.Notify” case in the switch.

case "NetStream.Pause.Notify":
	animated = true; // this line used to be animated = false;
	break;

Random Class v1.0

September 21st, 2009

Randomizer… explained in the code. Packaged, ready for imports via a “zammit” directory, name the file Random.as and import:

import zammit.Random;

here’s the package:

package zammit {
 
	/**
	 * The Random class contains methods to randomize certain classes.
	 *
	 * @author Andrew Zammit
	 * @version 1.0
	 */
 
	public class Random {
 
		/**
		 * Returns a randomized Array based on input Array.
		 * @param	targetArray		The array to be randomized (not passed by reference).
		 * @return	Array			Returns the newly randomized array.
		 */
		public static function randomizeArray(targetArray:Array):Array {
			var randomNum:Number;
			var newArray:Array		= new Array();
			var numIterations:uint		= targetArray.length;
			for ( var i:uint = 0; i < numIterations; i++ ) {
				randomNum = range(0, targetArray.length - 1);
				newArray.push(targetArray[randomNum]);
				targetArray[randomNum] = null;
				targetArray = reIndexArray(targetArray);
			}
			return newArray;
		}
 
		/**
		 * @private
		 */
		private static function reIndexArray(targetArray:Array):Array {
			var newArray:Array = new Array();
			for ( var i:String in targetArray ) {
				if ( targetArray[i] != null )
					newArray.push(targetArray[i]);
			}
			return newArray;
		}
 
		/**
		 * Returns a random number between minNum and maxNum with optional rounding.
		 * @param	minNum		A Number representing the lowest possible number (inclusive).
		 * @param	maxNum		A Number representing the highest possible number (inclusive).
		 * @param	round		A boolean to round a number (make an integer).
		 * @return	Number		Returns the random number based on given criteria.
		 */
		public static function range(minNum:Number, maxNum:Number, round:Boolean = true):Number {
			if (minNum < 0) {
				if (round) return Math.floor(Math.random() * ((minNum * -1) + maxNum - 1)) - (minNum * -1);
				else return Math.random() * ((minNum * -1) + maxNum - 1) - (minNum * -1);
			} else {
				if (round) return Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
				else return Math.random() * (maxNum - minNum + 1) + minNum;
			}
		}
 
	}
 
}

Oscilloscope Sound Visualizer

September 21st, 2009

Okay, wrote this thing a few days ago after work… no package definition (was writing this in the IDE).

But really this post is a trial w/ the WP-Syntax plugin, let us see if it works now.

var PLOT_HEIGHT:Number	= 200;
 
var s:Sound			= new Sound(new URLRequest('justice_genesis.mp3'));
var c:SoundChannel		= s.play();
var t:SoundTransform		= c.soundTransform;
var v:Timer			= new Timer(20,0);
var mainSprite:Sprite		= new Sprite();
var lastLoc:Number		= 0;
var spriteArray:Array		= new Array();
var byteArray:ByteArray	= new ByteArray();
var tempSprite:Sprite;
 
for ( var i:Number = 0; i<256; i++ ) {
	spriteArray[i] = drawSquare();
	spriteArray[i].x = i+lastLoc;
	lastLoc += spriteArray[i].width;
	mainSprite.addChild(spriteArray[i]);
}
 
mainSprite.x = (stage.stageWidth-mainSprite.width)/2;
mainSprite.y = (stage.stageHeight-mainSprite.height)/2;
 
this.addChild(mainSprite);
v.addEventListener(TimerEvent.TIMER,moveParts);
v.start();
 
function moveParts(e:TimerEvent):void {
	SoundMixer.computeSpectrum(byteArray,false,0);
	var bVal:Number = 0;
	for ( var j:Number = 0; j<256; j++ ) {
		bVal = (byteArray.readFloat())*PLOT_HEIGHT;
		spriteArray[j].y = bVal;
	}
}
 
function drawSquare():Sprite {
	var newSprite:Sprite = new Sprite();
	newSprite.graphics.beginFill(0x000000,1);
	newSprite.graphics.drawRect(0,0,2,30);
	newSprite.graphics.endFill();
	return newSprite;
}

Got this thing rolling…

September 21st, 2009

Okay, just just put up the latest version of WP. Gotta get SEO stuff working, actually really don’t care about SEO, I just wanna see rewritten URIs.

[edit] … and we’re good, tags in sidebar ‘n all! [/edit]