New York Design & Development Forums  

Go Back   New York Design & Development Forums > Knowledge Bank > Tutorials
Connect with Facebook

Notices

Reply
 
LinkBack Thread Tools
Old 04-08-2006, 06:32 AM   #1 (permalink)
Senior Member
Fanatic
 
Michael's Avatar
 
Join Date: Mar 2006
Age: 23
Posts: 253
Michael is a glorious beacon of lightMichael is a glorious beacon of light
Send a message via AIM to Michael Send a message via MSN to Michael Send a message via Yahoo to Michael Send a message via Skype™ to Michael
Default Interval Manager

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

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];
   }
}

[/php] 
The code is simple... no need to worry about it.

Here is the code in the fla:

[php]
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
__________________
Actionscript Developer :P ...Dope...


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
<--- yeah I'm a nooob, so what
Michael is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Google Bookmark this Post!Blink this Post!
Reply With Quote
Old 04-10-2006, 04:28 AM   #2 (permalink)
Who among you?
Enthusiast
 
General's Avatar
 
Join Date: Mar 2003
Age: 28
Posts: 98
General is on a distinguished road
Default

It worked!
General is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Google Bookmark this Post!Blink this Post!
Reply With Quote
Old 04-10-2006, 05:11 AM   #3 (permalink)
Senior Member
Fanatic
 
Michael's Avatar
 
Join Date: Mar 2006
Age: 23
Posts: 253
Michael is a glorious beacon of lightMichael is a glorious beacon of light
Send a message via AIM to Michael Send a message via MSN to Michael Send a message via Yahoo to Michael Send a message via Skype™ to Michael
Default

Thanks, General_Mayhem :P

If you have any questions feel free to ask.

Take Care.
_Michael
__________________
Actionscript Developer :P ...Dope...


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
<--- yeah I'm a nooob, so what
Michael is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Google Bookmark this Post!Blink this Post!
Reply With Quote
Old 04-10-2006, 05:59 AM   #4 (permalink)
Who among you?
Enthusiast
 
General's Avatar
 
Join Date: Mar 2003
Age: 28
Posts: 98
General is on a distinguished road
Default

Thank you.
General is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Google Bookmark this Post!Blink this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -4. The time now is 01:26 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13