HaxeFlixel/flixel — pull request #686 by mrcdk (2013-10-27 23:53:09+00:00)
Title: Force class on FlxTypedGroup.recycle()

I was having problems with FlxTypedGroup.recycle(). The object returned was a super class of the class passed to the function because ```Std.is(object, Class)``` will return ```true``` if ```object``` is ```Class``` or ```Class``` is a super class of the ```object``` class.
For example, before this commit:
```haxe
class Note extends FlxSprite { ... }
class LongNote extends Note { ... }

class PlayState extends FlxState {
override public function create():Void {
var group:FlxTypedGroup = new FlxTypedGroup();
// Add a LongNote and Note objects
group.add(new LongNote());
group.add(new Note());

for (n in group.members) {
n.exists = false;	// Set exists to false so we can recycle them
}

var note:Note = cast(group.recycle(Note), Note);	// Should return a Note object
// but, because the first object
// available is a LongNote and
// its super class is Note, it
trace(Type.getClassName(Type.getClass(note)));	// will return that LongNote object

var long:Note = cast(group.recycle(LongNote), LongNote);	// Should return a LongNote object
// but, because there are no more
// LongNote objects to return, it
trace(Type.getClassName(Type.getClass(long)));	// will return a new LongNote object

super.create();
}
...
}
```
With this commit:
```haxe
class Note extends FlxSprite { ... }
class LongNote extends Note { ... }

class PlayState extends FlxState {
override public function create():Void {
var group:FlxTypedGroup = new FlxTypedGroup();
// Add a LongNote and Note objects
group.add(new LongNote());
group.add(new Note());

for (n in group.members) {
n.exists = false;	// Set exists to false so we can recycle them
}

var note:Note = cast(group.recycle(Note, null, true), Note);
// Should return a Note object.
// The first object available is
// a LongNote but we are forcing it
// to be a Note object. It will return
trace(Type.getClassName(Type.getClass(note)));	// the old Note object

var long:Note = cast(group.recycle(LongNote, null, true), LongNote);
// Should return a LongNote object
// Because the first object available
// is a LongNote it will return
trace(Type.getClassName(Type.getClass(long)));	// will return that Longnote object

super.create();
}
...
}