In Flash movies you can’t set different frame rates for different clips, but having different frame rates is sometimes necessary, and often very useful.
You can do this by controlling the time interval before moving on to the next frame in each movie clip. Download the flash file here: variable frame rate fla.
This works by using the following actionscript in a clip that resides within the movieclip you want to control. Here’s the actionscript:
onClipEvent (load) {
_visible = false;
_parent.stop();
setInterval(function () {
_parent.nextFrame();
}, 50);
}
To use this actionscript do the following: In the movie clip you want to control make another movieclip, the graphic can be anything as we’re going to make it invisible anyway. Make sure you’re still in the movieclip you want to control and click on the new movieclip (lets call this the controller movie clip), go to actions and paste in the actionscript above. Below is an explanation of how it works.
OnClipEvent (load){ … }
this does everything when the clip loads
_visible = false;
this makes the controller clip invisible - so you don’t have to worry about it anymore
_parent.stop();
this stops the clip you want to control, then allowing you to controll the way it advances
setInterval
this sets the interval of something (in this case a function) and the time delay in milliseconds
function () {
_parent.nextFrame();
}
this tells the parent (the clip that the contoller clip is within) to go to the next frame
Thats it, your clip will now advance to the next frame every 50 milliseconds in the above example.
The only other thing you should do is make sure that the movie frame rate is fairly high (anything over 25fps should do), otherwise you wont see smooth action. Even if you set you controller clip to have a fast interval the movie can only refresh the screen at the movie frame rate.
In the attached example movie there are 2 identical movie clips called circler and circler2. Each has a circle that moves in circle. The clip clock speed has the above actions attached, this controls the speed the circle rotates in both movie clips. You could copy and paste the clip clock speed into any movie clip you want to control and change the interval to suit.
The only other bit of script in the attached movie is below:
onClipEvent (enterFrame) {
//trace(_parent._currentframe);
}
If you uncomment the middle line (remove “//”) then you’ve get an output of the current frame when you’re in the Flash program, this can be useful to see whats going on. It will only output this every frame (this is set to the frame rate of the movie).




0 Responses to “Multiple frame rates in a Flash movie”