download / 3.3 mb zip
version : 1.1.9
updated : February 18, 2011
open all | close all
upcoming HYPE events
No events.
let's keep in touch.
Keep us informed what you're working on using HYPE by connecting with us, either via e-mail or through twitter.

hype@hypeframework.org
twitter.com/hypeframework
Branden Hall

automatastudios.com
twitter.com/waxpraxis
Joshua Davis

joshuadavis.com
twitter.com/joshuadavis
flickr.com/photos/joshuadavis

Alternative content

Get Adobe Flash player

ObjectPool / 03_objectPool
import hype.extended.behavior.FixedVibration;
import hype.extended.behavior.VariableVibration;
import hype.extended.color.ColorPool;
import hype.extended.trigger.ExitShapeTrigger;
import hype.framework.core.ObjectPool;
import hype.framework.core.TimeType;
import hype.framework.display.BitmapCanvas;
import hype.framework.rhythm.SimpleRhythm;

MyExitShape.visible = false;

var myWidth = stage.stageWidth;
var myHeight = stage.stageHeight;

var bmc:BitmapCanvas = new BitmapCanvas(myWidth, myHeight);
addChild(bmc);

var clipContainer:Sprite = new Sprite();

var color:ColorPool = new ColorPool(
	0x587b7C, 0x719b9E, 0x9FC1BE, 0xE0D9BB, 0xDACB94, 0xCABA88, 0xDABD55, 0xC49F32, 0xA97409
);

var pool:ObjectPool = new ObjectPool(MyCircle, 200);

function addNextClip(r:SimpleRhythm) {
	pool.request();
}

var rhythm:SimpleRhythm = new SimpleRhythm(addNextClip);
rhythm.start(TimeType.TIME, 1);

pool.onRequestObject = function(clip) {
	clip.x = myWidth / 2;
	clip.y = myHeight / 2;
	clip.scaleX = clip.scaleY = 0;

	// target Object, property, spring, ease, vibrationRange
	
	var xVib:VariableVibration = new VariableVibration(clip, “x”, 0.99, 0.01, 100);
	var yVib:VariableVibration = new VariableVibration(clip, “y”, 0.99, 0.01, 100);
	xVib.start();
	yVib.start();

	// target Object, property, spring, ease, min, max, isRelative
	
	var aVib:FixedVibration = new FixedVibration(clip, “alpha”, 0.9, 0.05, 0.0, 1.0, false);
	var sVib:FixedVibration = new FixedVibration(clip, “scale”, 0.9, 0.05, 0.05, Math.ceil(Math.random() * 3) * 0.3, false);
	var rVib:FixedVibration = new FixedVibration(clip, “rotation”, 0.9, 0.05, 0, 360, false);
	aVib.start();
	sVib.start();
	rVib.start();

	// exit callback function, target Object, shape, shapeFlag

	var onExit:ExitShapeTrigger = new ExitShapeTrigger(onExitShape, clip, MyExitShape, true);	
	onExit.start();
	
	color.colorChildren(clip);
	
	clipContainer.addChild(clip);
}

function onExitShape(clip):void {
	pool.release(clip);
	clipContainer.removeChild(clip);
}

bmc.startCapture(clipContainer, true);





Leave a Comment
alex said, on November 7th, 2009 at 5:43 am

just badass

Felipe said, on November 13th, 2009 at 10:50 am

This is beautiful!

First try (hype contest) | New world order said, on December 3rd, 2009 at 5:12 pm

[...] examples would be the best to learn how the code works. My first attempt was at this example http://hype.joshuadavis.com/02_examples/objectpool/03_objectpool/ Share this [...]

[...] and sets it aside in you memory before the file even start running. So when you make a call to the object pool, the movieclip is ready to go, no questions asked. But if you reach the maximum number, you can set [...]