It is very simple to create this syntax yourself. Every function should return the instance of the class itself (return this).
Create an as3 class called Chainer
package
{
public class Chainer
{
public static function create():Chainer
{
return new Chainer();
}
public function next(func:Function, ...rest):Chainer
{
func.call(this, rest); // call the function with params
return this; // returns itself to enable chaing
}
}
}
Now use the class with your next-function. You could call it like this:
Chainer.create()
.next(function():void {
trace("1")
} )
.next(function():void {
trace("2")
} );
There could be problems if you want to extend the Chainer class, since you cannot change the return type:
OOP problem: Extending a class, override functions and jQuery-like syntax
I have used this type of code to create a little helper class:
http://blog.stroep.nl/2010/10/chain-tween/
http://blog.stroep.nl/2009/11/delayed-function-calling-chain/
BTW this tween library is based on jQuery like syntax too:
http://code.google.com/p/eaze-tween/