ActionScript 2 double interval

Within the delicious:suite I often have the need of calling a function at an interval. But I need a two step timer to call that function at a slower interval the first few times, and then call it at a faster interval.

I wrote a custom class to mimic the Flash ActionScript 2 built in setInterval() and clearInterval() functions, but with the addition of this two-step timer. The sample swf demoed here shows my stepper that increments a number up and down. When you press and hold either arrow button the number increments slowly for the first 10, and then increments faster until you release the button. Another example of this class in action is the nudge function in the delicious:designer — the user can nudge art objects using the arrow keys. The first nudge occurs at a long interval, and then, if the user continues holding the key down, the nudge continues at a faster interval.Here is sample ActionScript 2 code showing how simple it can be to create a double interval function call. This example will call the function myFunction 10 times every 200 milliseconds. Then it will call the function myFunction every 50 milliseconds until the user clears it.

import mx.utils.Delegate;
import delicious.doubleInterval;
intervalNumber = doubleInterval.setDoubleInterval( Delegate.create( this, myFunction ), 200, 10, 50);


For more advanced uses you can also pass parameters to the function called on the interval. The class can be downloaded here, and the documentation can be viewed here.

Leave a Reply