PDA

View Full Version : onEnterFrame vs setInterval



flash1810
March 13th, 2006, 04:56 PM
Hello everyone...

I dont know if this has been discussed here before...

i was having a conversation with a flash developer and he was going on about how using setInterval is much better than using onEnterFrame for actionscripted animations as the latter suffers from platform dependance (muc slower on Macs and slow processors) and also because once killed (delete onEnterFrame) can't be reinstated.

Yesterday i received some help in this forum and the person who helped me pointed that i should use onEnterFrame as opposite as setInterval as is easier to use and less buggy...

:sigh:

Anybody willing to shed some light on the subject?

Cheers in advance for your advice!!

D

Dauntless
March 13th, 2006, 05:01 PM
I dont' really have an opinion, but I do have to say this:

and also because once killed (delete onEnterFrame) can't be reinstated.
That is SO WRONG!

You can really easily reinstate an onEnterFarme:



function moveMe()
{
//move the movieclip
this._x += 10;
}
//assign onEnterFrame
myMovieClip.onEnterFrame = moveMe;
//delete onEnterFrame
delete myMovieClip.onEnterFrame;
//reinstate oEF:
myMovieClip.onEnterFrame = moveMe;

stringy
March 13th, 2006, 05:07 PM
At one time i used setInterval for all movement etc but one of the problems is that if you reload a movieclip, then the intervals do not clear on their own.So unless you keep track of all intervals to clear, can mess everthing up.
Now reverted back to onEnterFrame and only use setInterval when necessary.

Dauntless
March 13th, 2006, 05:09 PM
At one time i used setInterval for all movement etc but one of the problems is that if you reload a movieclip, then the intervals do not clear on their own.So unless you keep track of all intervals to clear, can mess everthing up.
Now reverted back to onEnterFrame and only use setInterval when necessary.Why not write a custom class that keeps track of all the intervals ?

stringy
March 13th, 2006, 05:29 PM
Why not write a custom class that keeps track of all the intervals ?
because i cannot (-:

Dauntless
March 13th, 2006, 05:58 PM
I just made this one. (It seems to be working, though I havent tested it much)

[code]class IntervalManager
{
var intervals:Array = new Array();

public function addInterval(p_id:String, p_timeLine:Object, p_functionName:String, p_interval:Number):Void
{
var myArgs:Array = arguments;
myArgs.shift();
var myInterval:Number = setInterval.apply(null, arguments);
intervals.push({interval:myInterval, id:p_id, args:myArgs});
}

public function removeInterval(p_id:String):Void
{
for(var i in intervals)
{
if(intervals[i].id == p_id)
{
clearInterval(intervals[i].interval);
intervals.splice(i, 1);
break;

}
}
}

public function pauseIntervals():Void
{
for(var i in intervals)
{
clearInterval(intervals[i].interval);
}

}
public function removeAllIntervals():Void
{
for(var i in intervals)
{
clearInterval(intervals[i].interval);
}
intervals = new Array();
}

public function unPauseIntervals():Void
{
for(var i in intervals)
{
intervals[i].interval = setInterval.apply(null, intervals[i].args);
}
}

public function unPauseSingleInterval(p_id:String)
{
for(var i in intervals)
{
if(intervals[i].id == p_id)
{
intervals[i].interval = setInterval.apply(null, intervals[i].args);
break;
}
}
}

public function pauseSingleInterval(p_id:String)
{
for(var i in intervals)
{
if(intervals[i] == p_id)
{
clearInterval(intervals[i].interval);
break;
}
}
}

}[/As]

flash1810
March 13th, 2006, 06:05 PM
this article http://www.13dots.com/forum/index.php?showtopic=2353 (http://www.13dots.com/forum/index.php?showtopic=2353)

approaches the same issues...with an eye on cpu usage

D

bombsledder
March 13th, 2006, 07:10 PM
I use onEnterFrame unless i need like a timed event of a such a sort, i rarely ever use setInterval though