Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 01-20-2011, 06:04 AM   #1
Join Date: Oct 2010
Posts: 55
Default setInterval?

For some reason in the past month or so I've been noticing a lot of people posting code using the setInterval functions. Before I first saw somebody post it I never even realized there was such code.

I just want to know whether that function, for what it actually accomplishes, is more effective than using the actual Timer class or even other more basic methods?

Is it good practice to use the interval methods in code? I just wonder since I had never even heard of it before.
blank01 is offline   Reply With Quote
Old 01-20-2011, 03:07 PM   #2
Obfuscated Coder
maskedMan's Avatar
Join Date: Apr 2008
Posts: 1,635

In AS3, no it isn't good practice at all.

If you're seeing it a lot in recent months, it's probably either a large body of outdated tutorials, or perhaps it's AS3 written by JavaScript coders who don't know the language well enough to realize there's a better way.
http://www.scriptocalypse.com - It's not the end of the world. It's just Actionscript!

man.mask = mask_mc;
maskedMan is offline   Reply With Quote
Old 01-20-2011, 03:08 PM   #3
Salmon Eater
TomMalufe's Avatar
Join Date: Jun 2007
Location: Doylestown, PA, USA.
Posts: 741

Originally Posted by Adobe
Instead of using the setInterval() method, consider creating a Timer object, with the specified interval, using 0 as the repeatCount parameter (which sets the timer to repeat indefinitely)
setInterval() exists in a lot of different programing languages and there is nothing wrong with using it in Flash/AS3. But AS3 is supposed to be more of an event driven language and so Adobe recommends using the Timer class and handling the events from that instead.

I think of setInterval as a lazy alternative to the Timer class. For some experiments it just seems easier to write that one line of code rather then the 5-6 lines it would take to set up your timer. For the most part, I do not use setInterval in any official paid projects. Only when I'm messing around with small new ideas.
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." -- Chinese Proverb.
TomMalufe is offline   Reply With Quote
Old 01-20-2011, 06:13 PM   #4
Super Moderator
ASWC's Avatar
Join Date: Dec 2007
Location: Greenville, SC
Posts: 6,742

setInterval is like XMLDocument (known as XML in AS2), they are deprecated function/class that Adobe kept in AS3 to help AS2 coder make the transition. They will be removed from the language at one point so in a way it is bad practice to use them because one day they won't be supported by future version of the Flash Player and as a coder you will have to start working with other Timer and XML class anyway so better doing it now.
Super Duper!
ASWC is offline   Reply With Quote
Old 02-20-2011, 10:59 AM   #5
Ravi Bhadauria
ActionScript Instructor
Join Date: Feb 2011
Location: Rohini, New Delhi, India
Posts: 39
Send a message via Skype™ to Ravi Bhadauria
Default playing with setInterval and clearInterval

Hi all,
One more example on setInterval in action script 3.0, i found when i was playing with timing events of as3.0.

Expect, following code will be helpful:

Just create a movieclip on the stage and put its instance name my_btn and copy the following code and paste it on first frame of your flash file:

function moveBtn():void {

var myInterval:uint=setInterval(moveBtn,500);

my_btn.addEventListener(MouseEvent.MOUSE_DOWN, stopMe);
my_btn.addEventListener(MouseEvent.MOUSE_UP, playMe);

function stopMe(e:MouseEvent):void {

function playMe(e:MouseEvent):void {
myInterval =setInterval(moveBtn,500);

Ravi Bhadauria
ADMEC Multimedia Institute
Ravi Bhadauria is offline   Reply With Quote

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 On
HTML code is Off

Forum Jump

All times are GMT. The time now is 01:50 PM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2015, 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.