Download: FrameEvent

Downloads, Classes - December 21

Manage frame events easily and quickly with this Class. No more boring coding of onEnterFrame event. Make your ActionScript easier: set number of repetitions, frames interval, arguments to send to the function... or simply delay a function of one frame...

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:

var myEvent = new FrameEvent({functionObject:this, frameFunction:"myFunction", repeat:1});

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:

var par = new Object();
par.functionObject = this;
par.frameFunction = "myFunction";
var myEvent = new FrameEvent(par);

Of course, the same result can be achieved with the shorter code:

var myEvent = new FrameEvent({functionObject:this,frameFunction:"myFunction"});

(The order of parameters is not important because they are named.)

To pause the event, with the possibility to restart it later, just type:

myEvent.pause();

To resume, predictably:

myEvent.resume();

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

Flash, ActionScript, OOP, object oriented programming, freelance flash developer, actionscript developer, flash programmer, flasher, rich internet applications developer, ria, flash games, flash 3D, web applications, ActionScript 2.0, free actionscript classes, swf, free flash downloads, free flash components, flash tutorials, actionscript tutorials, flash developer beijing, programmatore flash, sviluppatore flash, sviluppatore flash italia, sviluppatore flash roma, sviluppatore flash italiano, freelance flash developer, Flash, ActionScript, actionscript, OOP, object oriented programming, freelance, actionscripter, programmer, freelance flasher, actionscript developer, rich internet applications, ria, flash games, 3D, web applications, interface developer, ActionScript 2.0, classes, swf, useability, usability, free stuff, free code, free classes, Flash Components, Flash Developer, Flash Games developer, Flash MX 2004, Flash 8, Flash Developer in Italy, Italian Flash developer, Flash Sviluppatore roma, Flash Developer Beijing, flash developer china, flash Developer Bangkok