flashactionscript-3actionscriptanimationflash-cs4

Wave-like animation on objects in AS3


I have different cards, I need to reveal them in a wave like form, i.e. the cards open and close at different timings sequentially and systematically such that they form a wave.

I have the cards in an array already. How do I implement this animation in the most efficient way?


Solution

  • presuming what you are meaning is a stadium "wave" effect, try to define an array with an offset, this will depend if you are using a tweening engine etc or if you are using another function.

    The Timer class for example will do you well in this one:

    private var t:Timer = new Timer(100, 0);
        private var index:int = 0;
        t.addEventListener(TimerEvent.TIMER, ping);
        t.start();
    
        private function ping(ev:TimerEvent) {
            if(index < waveArray.length){
                waveArray[index].startAnimation(); //If animated by object
                startAnimation(waveArray[index]); //If animated by container
                index ++;
            }
            else {
                t.stop();
                endAnimation(); //All cards have animated
            }
        }