Download: FrameEvent
download FrameEvent Class (detailed instructions in Class file)
Howmany times developing an application we realized that a function should be executed in the next frame? (tipically, working with dynamic text fields, where scroll properties get correctly updated only in the next frame, or with components, etc...).
FrameEvent is a very useful class that can manage one or more frame event functions easily, just like typing:
This is the simplest usage of FrameEvent, just to call "this.myFunction()" once, in the next frame.
With FrameEvent you can create as many events as you want, each with its behaviour (number of repetitions, infinite, execute every howmany frames, send an argument object, etc...).
Example of FrameEvent usage
In this example, you can see some simple use of FrameEvent:
download source code (fla & ActionScript)
How to control FrameEvent
FrameEvent accepts only one prameter, it is a Parameter Object containing all the properties (Read this post for further information about Parameters Objects). The syntax of the frame parameter verbose is as follows:
par.functionObject = this;
par.frameFunction = "myFunction";
var myEvent = new FrameEvent(par);
Of course, the same result can be achieved with the shorter code:
(The order of parameters is not important because they are named.)
To pause the event, with the possibility to restart it later, just type:
To resume, predictably:
Parameters accepted by FrameEvent
functionObject
Reference to the object where to call the function (i.e. this, _root, _level0, etc.)
frameFunction
STRING - Function name to be called as a string (i.e. "myFunction")
paramsObject
OBJECT - Parameters object to be sent to the function (i.e. {txt:"hello"}, will result in: this.myFunction({txt:"hello"}))
repeat
NUMBER - Number of times the function should be executed (if not specified, repeats forever)
interval
NUMBER - Every howmany frames should the function execute? (if not specified, executes every frame)
idle
BOOLEAN - If true, the event is set but doesn't start untill calling: myEvent.start();
List of methods and properties of FrameEvent
INSTANCE METHODS
myEvent.pause();
Pauses the execution of the event
myEvent.resume();
Resumes the execution continuing the count
myEvent.start();
Restarts the execution of the event from the beginning, restarting the count.
Starts if event was initiated with idle = true
myEvent.stop();
Kills the execution of the event forever and frees memory
myEvent.getStatus();
Returns an object with all the properties and status of the FrameEvent
CLASS METHODS
FrameEvent.createEventClipIn(Clip);
To execute the events, FrameEvent creates a new movieclip (to avoid conflics with existing onEnterFrame) in the _root. With this command, you can move the movieclip inside the specified clip.
FrameEvent.pauseFrameEvents();
Pauses the execution of all events
FrameEvent.activateFrameEvents();
Resumes the execution of all events
FrameEvent.launchAllFrameEvents();
Executes all existing frame events, doesn't matter if paused or finished repetitions
download FrameEvent Class (detailed instructions in Class file)
So many times when coding, it happens that I need to execute some onEnterFrame events, and I save so much time by using this class. I hope you will enjoy FrameEvent as much as I do. Feel free to experiment with it, and let me know if it has been useful.
namaste,
Pippo