2) Use setInterval() (Flash MX and up only) coupled with nextFrame(); (or prevFrame() to create a faux frame rate
the functions i use are these:
stop();
function playfps(){
//params = (funcion name,delay,target movieclip);
setInterval(playAndLoop,1000,this);
}
function playAndLoop(mc){
mc.nextFrame();
if(mc._currentframe == mc._totalframes){
mc.gotoAndStop(1);
}
}
playfps();
- stop();
- function playfps(){
- //params = (funcion name,delay,target movieclip);
- setInterval(playAndLoop,1000,this);
- }
- function playAndLoop(mc){
- mc.nextFrame();
- if(mc._currentframe == mc._totalframes){
- mc.gotoAndStop(1);
- }
- }
- playfps();
Hi, setInterval is great but can also cause problems if you dont use clearInterval to manage its presence. I always use the following when using setInterval.
stop();
function playfps(){
//params = (funcion name,delay,target movieclip);
clearInterval(_root.mysetinterval )
_root.mysetinterval = setInterval(playAndLoop,1000,this);
}
- stop();
- function playfps(){
- //params = (funcion name,delay,target movieclip);
- clearInterval(_root.mysetinterval )
- _root.mysetinterval = setInterval(playAndLoop,1000,this);
- }
You may want to read up on setInterval, if you dont store a reference to it (in my example _root.mysetInterval) you could end up with a permant loop you cant get rid off. You will notice that i call clearInterval with the _root.mysetinterval, this is to avoid a memory leak where by calling setInterval again leaves any previous setIntervals running.
I had a screensaver using 78mb of system memory after running through the night because of not tidying up the setInterval.
you might also want to add the clearInterval as below
if(mc._currentframe == mc._totalframes){
clearInterval(_root.mysetinterval )
mc.gotoAndStop(1);
}
- if(mc._currentframe == mc._totalframes){
- clearInterval(_root.mysetinterval )
- mc.gotoAndStop(1);
- }
Another problem with setInterval is when setting them within a movieClip that is removed from the score. If you set an interval and store a reference to it within a movieclip and then kill/remove that movieclip you also remove any chance of clearing the interval from running. Always clear any intervals you have running before removing a movieclip from the score. Its very difficult to debug cos you dont realise its a setinterval is causing problems.