views:

38

answers:

2

I want trace every event on every object, there is way to do it?

A: 

You have to create your own registry and access it that way. So yes, there is a way to do it, but no, not easily.

Joel Hooks
+1  A: 

Yes and no.

The one way is to simply override its dispatchEvent function:

override public function dispatchEvent(event:Event):Boolean
{
    // Do something with event.
    return super.dispatchEvent( event );
}

The problem, however, is that this does not always work -- sometimes dispatchEvent is not called if a child object does something. It also will not work if you are unwilling to create a special class for each instance.

Another alternative is to iterate through an array of different event types:

var evtTypes:Array = [ MouseEvent.CLICK, MouseEvent.ROLL_OVER, 
                       MouseEvent.MOUSE_DOWN...
                       Event.ADDED, Event.ADDED_TO_STAGE... etc.];

for( var i:int = 0; i < evtTypes.length; i++ )
{
    target.addEventListener( evtTypes[ i ], trace );
}

The problem with this method is that you'll not be able to capture custom events, only the events you have in your list. I would definitely recommend the second method for most learning and debugging problems.

I suppose a more important question, however, is "What do you want to do with these events?" Most of the documentation lists all of the events an object will dispatch: if you scroll down in the MovieClip documentation, you'll see an example.

Christopher W. Allen-Poole