1

JSDeffered is so cool: https://github.com/cho45/jsdeferred/blob/master/test-jsdeferred.js

we can write simplest async call chain .

next(function () { // this `next` is global function
    alert("1");
}).
next(function () { // this `next` is Deferred#next
    alert("2");
}).
next(function () {
    alert("3");
});

our code is so spagetti code like that new Execute1(nextFunction); ....

is there any cool Deferred library in ActionScript? or Which script are you using?

Taryn
  • 242,637
  • 56
  • 362
  • 405
freddiefujiwara
  • 57,041
  • 28
  • 76
  • 106

4 Answers4

4

I just came across this:

https://github.com/CodeCatalyst/promise-as3

I haven't tried it yet, but it looks.. promising. It's modelled on jQuery's Deferred, follows the CommonJS Promise/A spec (I assume), and has a decent looking set of unit tests.

darscan
  • 963
  • 1
  • 12
  • 17
3

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/

Community
  • 1
  • 1
Mark Knol
  • 9,663
  • 3
  • 29
  • 44
1

I think most tweening library will do exactly what you ask for. For instance TweenLite and TimelineLite (https://www.greensock.com/timelinelite/) should do the job perfectly.

Axelle Ziegler
  • 2,505
  • 17
  • 19
1

I'm not sure this is what you're looking for, but there's quite a nice port of LINQ for AS3 here: https://bitbucket.org/briangenisio/actionlinq/wiki/Home

Cay
  • 3,804
  • 2
  • 20
  • 27