views:

72

answers:

7

I am having trouble wiring up an event listener to a fl.transitions.Transition.

Is it possible to somehow view all the events an object fires? That way I could check I am using the correct event (and possible view better ones to use).

A: 

You cannot programmatically get a list of all events fired by any given object. You can however get a list of all events fired by a standard library object (that are part of it's public interface) from its documentation (cilck on the show inherited events link) and decide whether you're using the appropriate one.

Amarghosh
Unfortunately, the events for TransitionManager are undocumented (!). See: http://ducharme.cc/transitions-transition-manager/.Unfortunately, the strings this blog posts suggests don't seem to work for me so I was hoping to examine the events fired myself to see what was going on.
voidstate
-1; The documentation / ASDocs will only show events that are defined using metadata in the component. It is very commong to have events for which no metadata exists. One example is Binding Events, which are very common on many properties of the Flex Framework.
www.Flextras.com
So how does one discover events that are not in the docs? I assumed there might be some way of subscribing to all events but failing that, is there another option?
voidstate
The [TransitionManager](http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/fl/transitions/TransitionManager.html#eventSummary) doesn't fire any events.
Amarghosh
@www Undocumented events are not part of the public interface of that class and might change in the subsequent versions. A well built library will expose all events that are intended to be used by its users using asdoc tags.
Amarghosh
@voidstate actionscript doesn't have any such short cut whereby you can listen to all dispatched events. It doesn't make sense to have one: you can create and instance of the object and dispatch an event of type `myEvent` at runtime - another object of same type cannot anticipate this.
Amarghosh
@Amarghosh Agreed; but the OP's question was not on API Design techniques; it was about how to get a list of all events that may be fired by a component. Reviewing ASDocs simply won't do that.
www.Flextras.com
@www while I agree that you're technically correct, reviewing asdoc will give you a list of all events that you can rely upon. I can fire a `"blah"` event from my sprite object, but that wouldn't interest anyone but me.
Amarghosh
+1  A: 

The problem is, you have to have an event type to listen for. The only way to do this is to add listeners for all the possible events.

Now, you can add a handler with an indeterminate event type, such as:

private function myUniversalHandler(event:*) : void {
  trace(event.type);
  trace(event.constructor.toString());
}

And this will report any event passed to it. Nevertheless, it simply won't be called unless it is listening for an event of a particular type. And adding all those listeners is a lot of work to go through. Better to study the events available to you from whatever class you are dispatching the vent from.

Robusto
A: 

checkout the online reference, you should see there all events (and inherited events) of a Class.
On a side note if you are using flex you might be using mx.states.Transition

Daniel
-1. This is not not true. The on-line reference will only show events for which metadata exists in the component. Even if metadata exists, it can be removed from the ASDocs using the @private asdoc tag. Plenty of events are undocumented, most commonly the binding events (somePropertyChanged) that exist on most every property of Flex UI Components.
www.Flextras.com
10x, I guess you learn something new every day :)btw. love your podcast.d.
Daniel
+3  A: 

The easiest is to override the dispatchEvent method in classes where you want to intercept events.
You can find the classes in %CS_ROOT%\Common\First Run\Classes\mx\transitions\easing\.

You can also create a subclass of EventDispatcher with a custom dispatchEvent-implementation and use that as a subclass for all classes where you'll be wanting to intercept events.

greetz
back2dos

back2dos
+1 for having a creative solution.
www.Flextras.com
A: 

There is no way, at runtime, to find out all the events that fire from a component. You'll have to explore the component source code to get a complete list.

Reviewing the ASDocs, as others have suggested, is a good way to get a handle on the documented events of a component; and in most cases you'll be able to find one to suit your needs.

www.Flextras.com
A: 

I have scratched my head quite a bit on this issue as well. The answer is this

  1. you can get a list of all event listeners that an object is listening to only if attached though MXML
  2. if not attached through MXML you cannot see the events an object is listening to (attached by AS)

if you want to see all the events an object is listening to you can check for hasEventListener although this is a long coding way

another efficient way (if you can use it, I couldn't) is to monkey patch the framework and create a dictionary of listeners for every object. you can accomplish that by patching FlexSprite and overriding the addEventListener function. you should keep in mind, this will not work when you are loading the framework through RSL.

Avi Tzurel
+1  A: 

I would look at TransitionManager, and the events allTransitionsOutDone and allTransitionsInDone which it dispatches. I haven't used these, but my understanding of their function matches what you seem to be looking for.

ThatSteveGuy