Avg. Rating 5.0
Tags:



Problem

Working with events in AS3 isn't as easy as it used to be in the past. While you need to monitor every event in your application there is no real easy way to do it without manually remembering all of your events and remembering to remove them on a one by one bases(ohi so much work...). With all the new features and powers of AS3 came a lot of leg work. So many classes out there tried to tackle this issue from many interesting and different directions. But most of them demand a large learning curve and a big shift in the way you would interact with your code, some through a framework that locks you into a development style, some changed the way flash handles events.

Solution

Essentially Event Controller is an easier way to keep track of events in actionscript 3. Event Controller is a simple extension to your normal workflow that allows you to easily tag, group and remove any and all events, pause events and restore them when you want them back and more. We know that there are many great solutions out there from very talented people. But we wanted to bring out another option the most simple one we could think about and we are with our ears to the community(so far in our 3rd revision) to making it even easier. The goal is to create the most simple yet feature rich event hub. Let unknown leaks be a thing of the past by taking our library out for a spin.

Detailed explanation

Event Controller was designed to stay out of your way and follow nearly the same structure as you are already using for creating and removing events with AS3. Only now with a little extra horsepower under the hood. There is even a local event controller that you can use to create local events managers and separate your events into buckets. Check out Event Controller in action. We are sure it has a little something for everyone.

Event Controller in Action

Event Controller is a very basic yet extremely powerful library. You can easily update any current project in minutes to utilize the Event Controller library. From beginners to advanced developers, everyone should find something for them. Below you will find a few examples of the simplicity of EC (Event Controller) and also how to empower yourself with it. We recommend taking the time to understand each example.

Links: basics | intro to clusters | regexp feature | event logging | local event control

Here is a small quick sample but click on the links above for an indepth overview of the classes or check out our documentation:

import _as.fla.events.LEC;
                   
var btn:MovieClip = new MovieClip();
var lec:LEC = new LEC(); //for a local event controller
//or:
var ec:LEC = LEC.getGlobal(); // the global event controller

//basic add event
lec.add(btn, Event.ENTER_FRAME, loop, "button");
lec.add(btn, MouseEvent.CLICK, onClick, "button");
lec.add(btn, MouseEvent.ROLL_OVER, onOver, "button");
lec.add(btn, MouseEvent.ROLL_OUT, onOut, "button");
                                       
function loop(e:Event):void{}
function onClick(e:MouseEvent):void{}
function onOver(e:MouseEvent):void{}
function onOut(e:MouseEvent):void{}
                   
                   
// yes you can still change your useCapture,priority,useWeakReference attributes
// using the same normal flow but pushing the cluster name to the last param:
//lec.add(btn, MouseEvent.ROLL_OUT, onOut, false, 0, true, "button"); // all the same
                   
//remove a cluster of events
lec.remove("button");
                   
//or remove it by sending the object to be removed
lec.remove(btn);
                   
//or you can regexp it(any regexp welcomed) :
lec.remove(/button/);

All new logger plugins

//plugin required for logging. Check docs for other popular built in flash loggers. 

  import _as.fla.events.log.ClassicLog; 
  EC.plug(ClassicLog); 
  //output all events in my controller
  lec.log();
                   
  //or - output all events of button
  lec.log(btn);


  //or - output all events in cluster
  lec.log("cluster ID");
                   
  //or - output all events that match the regular expression
  lec.log(/button/);

 

As of release 1.3 and up we have added support for popular Flash loggers. First was the ClassicLog which you have seen above but we have also added in support for loggers like Alcon, Arthropod and Monster Debugger. This is to help out anyone already locked into a debugger.

For more information and to download the library please visit us at:
http://fla.as/ec/

p.s we would love to hear from you. If you want to hear from us join our google group for updates or to listen in and chat about events and flash.
 


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes