Skip to content

#360Flex Notes – “AddEventListener() – Now What()” – Josh Buhler

Event: noteworthy runtime occurence

Types of events: built-in (come from Flash Player) and custom (coder defined)

Custom: Something that you feel is “noteworthy”

Basics: Something happens, creation, dispatch, handling (not all dispatched events are handled)

Objects: type (either Event or subclass), name, phase (where in event flow this is), target (what triggered event and what is handling it)

Using Events: name, type, register, handle, wait

Event Names: code hints

Event Types: documentation is the best place to see what exists

Register
addEventListener(type:String,listener:Function)
Other parameters: useCapture, priority, useWeakReference

Dispatch: Create, dispatch

Removing Event Listeners: unnecessary and just uses memory/cpu load.
removeEventListener SAME parameters
if something changes in the addEventListener then the same thing must change in the removeEventListener

Force garbage collection: Should not be used in production environments

Know what events are on an object when you delete it.

Anonymous Handlers: inline functions to “just do one thing” –> bad! no way to get rid of it.

Weak References: Connection is still there between EventDispatcher and Listener. If GC comes along, if thats the only link, then it marks it as “eligible” for trash. Problem with this? doesn’t always work. Code for forced GC: http://bit.ly/IU0Z5

Always remove event listeners when you no longer need it.

Custom Events: Name-Only (just name changes and still Event class) and Extend (carry additional properties/functionality)

Changed tempChange to a custom event which extends Event to return number and prevNumber. Nice simple example of a custom extended event.

Notes on custom:
always call clone and toString if you have added additional properties.

http://bit.ly/Fwb64

Event flow: capture phase (finding target), target phase (handling), bubble phase (which goes all the way back up to stage)
Not all events bubble by default and only events on the stage will bubble
You can register on all phases but need to specifically register for each phase.

Broadcast Events: activate, deactivate, enterFrame, exitFrame, frameConstructed, render
always happen. you can’t destroy from but you can register for them. they fire regardless of if they are on the stage.

Event Target: target (dispatched event), currentTarget (target currently handling event in Event Flow)

Priority: they will fire in the order they were registered unless you change when registering. higher priority will be triggered first. int.MAX_VALUE will put it at the top.

Killing Events: stopPropagation() prevents from continuing through event flow. Continues at current display object/same level.
stopImmeadiatePropagation() stops in its tracks. No $200.

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*