Last active
December 10, 2015 16:28
-
-
Save JulianG/4460785 to your computer and use it in GitHub Desktop.
General purpose AS3 Object Pool class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
/** | |
* ObjectPool Class | |
* @author Julian | |
*/ | |
public class ObjectPool | |
{ | |
private var _list:Array; | |
public function ObjectPool(object_type:Class, qty:uint) | |
{ | |
for (var i:int = 0; i < qry; i++) | |
{ | |
_list.push( new object_type() ); | |
} | |
} | |
public function getNextObject():* | |
{ | |
var obj:* = _list.shift(); | |
_list.push(obj); | |
return obj; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice one! There's a typo on line 13, qry instead of qty :)