Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 04-08-2006, 10:18 AM   #1
MichaelxxOA
Flash Sucks
 
MichaelxxOA's Avatar
 
Join Date: Mar 2005
Location: Victorville, Ca
Posts: 2,228
Send a message via AIM to MichaelxxOA Send a message via MSN to MichaelxxOA Send a message via Yahoo to MichaelxxOA Send a message via Skype™ to MichaelxxOA
Default Dev Kit, Interval Manager... here you go

Another little useful class I decided I'd give to you guys since it's going to be a bit before the kit is out.

This is used to manage intervals. It may not seem like a big deal, but it has honestly saved me so much time and grief. It gives you one location for setting and clearing intervals, and even allows you to set a timeout function.

Here is the class, IntervalManager.as

ActionScript Code:
/**  * Flash's interval management is horrible.  Here we provide a way  * of setting and clearing intervals, in one location.  *  * @author Michael Avila  * @version 1.0.0  */ class IntervalManager {    // stores the interval ID's in a dictionary, so that you can name them    private static var intervalIDs : Object = new Object();    /**     * Sets an interval, storing it's reference in this IntervalManager.  If there is already an interval associated with the     * name that you provide (meaning an interval that was created with but not cleared with the IntervalManager), the IntervalManager     * will clear the interval and set the interval you provide in it's place.     *     * @param The name you are assigning the interval, note that this is how you will be deleting it     * @param The path to the function that will be called by the setInterval     * @param The name of the function as a string     * @param The interval that this function will be called on     * @param The args that will be passed to the interval.  The arguments are passed as an array, so be sure     *        to have your function compensate for that.     */    public static function setInterval( name:String, path:Object, functionName:String, interval:Number, args:Array ) : Void    {       if ( IntervalManager.intervalIDs[name] != undefined)       {          IntervalManager.clearInterval( name );       }       IntervalManager.intervalIDs[name] = _global.setInterval(path, functionName, interval, args);    }    /**     * Sets a function to be called at "interval" seconds after the timeout is set.  If there is already a timeout associated with     * the name that you provide (meaning an interval that was created with but not cleared with the IntervalManager), the IntervalManager     * will clear the old timeout and set the new timeout you provide in it's place.     *     * @param The name you are assigning the timeout     * @param The path to the function that will be called by the setTimeout     * @param The name of the function as a string     * @param The interval that this function will be called on     * @param The args that will be passed to the timeout.  The arguments are passed as an array, so be sure     *        to have your function compensate for that.     */    public static function setTimeout( name:String, path:Object, functionName:String, interval:Number, args:Array ) : Void    {       if ( IntervalManager.intervalIDs[name] != undefined)       {          IntervalManager.clearInterval( name );       }       IntervalManager.intervalIDs[name] = _global.setTimeout(path, functionName, interval, args);    }    /**     * Clears the interval with the name you provide.     *     * @param The name of the interval you'd like to clear.     */    public static function clearInterval( name:String ) : Void    {       _global.clearInterval( IntervalManager.intervalIDs[name] );       delete IntervalManager.intervalIDs[name];    } }

The code is simple... no need to worry about it.

Here is the code in the fla:

ActionScript Code:
IntervalManager.setInterval("hello", this, "sayHello", 1000, ["Michael"]); IntervalManager.setTimeout("helloOnce", this, "sayHelloOnce", 1000); function sayHello(args:Array) : Void {     trace("Hello, " + args[0]); } function sayHelloOnce() : Void {     trace( "Hello from the TimeOut" ); } function onMouseDown() {     IntervalManager.clearInterval( "hello" ); }

This class will be found in the package,

createage.managers

in the Dev Kit.

The documentation for the dev kit can be found here...

www.createage.com/CreateageLib

Take Care.

_Michael
MichaelxxOA is offline   Reply With Quote
Old 08-03-2006, 11:22 PM   #2
ddk632
"medium-well, yet flashy"
 
ddk632's Avatar
 
Join Date: Jun 2006
Location: Tarzana, CA (LA)
Posts: 24
Send a message via AIM to ddk632
Default Thank you!

This is awesome, I have been using this.intervalID ... and then clear this.intervalID inside whatever function that was called in the interval, and I hate to say it and sound cheesy but it seemed hard to manage the intervals without leaving at least some of them not cleared - this will help me since I'm a big fan of using intervals over onEnterFrames for animation.
ddk632 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Slideshow interval problem elements ActionScript 2.0 0 01-24-2006 09:46 AM
Wait, then execute a function Kpax00 ActionScript 1.0 (and below) 3 04-06-2005 09:24 AM
Simple Counter aperez ActionScript 2.0 1 05-30-2004 02:56 PM
random interval loop Thunderhawk ActionScript 1.0 (and below) 4 07-23-2003 06:32 AM
draw polygon with line mc's sneeuwitje ActionScript 1.0 (and below) 2 07-08-2003 01:23 PM


All times are GMT. The time now is 05:13 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.