Feb 12

ActionScript OnEnterFrameManager

Filed under: Development | Taged as: , | Comments Off

The onEnterFrame event is one of the most important methods used in Flash for scripted animation. What makes it a littel inflexible is that it is bound solely to the MovieClip object what makes is somehow combersome when needed for one\’s own classes. Extending the MovieClip class is not a good solution and should be avoided in general as the inheritance structure limits the architectural options.

Another aspect of the event may be, that on each frame, more than one clip should be affected. Creating several onEnterFrame handlers wastes memory and (often) has a negative impact on the movie. The management of the single event, maybe disptributed over several classes, is also an aspect that affords a solid design.

Like the OnEnterFrameBeacon ,provided as a standard class with Flash, the ASToolBox offers a central manager for handling with the topic. The usage is quite easy and requires only a registration of the objects with the manager. The objects themself must implement the OnEnterFrameListener interface for revcieving the event.

import de.flamelab.event.*;
import de.flamelab.manager.*;

// create listener objects
var a:OnEnterFrameListener = new OnEnterFrameListener();
a.onEnterFrame = function(){
trace("call object a");
}
var b:OnEnterFrameListener = new OnEnterFrameListener();
b.onEnterFrame = function(){
trace("call object b");
}

// register with manager
OnEnterFrameManager.addListener(a);
OnEnterFrameManager.addListener(b);

What the Flash own beacon does, is attaching the necessary methods as static methods to the MovieClip object, creating a strange look when registering listeners for the event. The register process with a sperate class makes your code more readable and creates a more independent handing.

Visit the ASToolBox Project or download the ASToolBox

Comments are closed.