LifeCycle events

creynders's Avatar


04 Feb, 2013 09:27 AM

I'm trying to listen to the lifecycle events, but they don't seem to be dispatched.
I've got the following:

private function creationCompleteHandler( event : FlexEvent ):void{
    _context = new Context()
        .install( MVCSBundle )
        .configure(SomeConfig )
        .configure( new ContextView( this ) );

public var commandMap : IEventCommandMap
public function configure():void{
        .map( LifecycleEvent.POST_INITIALIZE, LifecycleEvent )
        .toCommand( DoSomethingIncredibleCommand );

public function execute() : void{
    trace( 'This is incredible !' );

In the console everything appears to run in the correct sequence and it does output 753 INFO Context-0-32 Context-0-32 Initialize complete
but the command still won't run. What am I missing here?

  1. Support Staff 1 Posted by Ondina D.F. on 05 Feb, 2013 03:55 PM

    Ondina D.F.'s Avatar

    Hi Camille,

    I’m not very familiar with rl2’s Lifecycle yet, but I think, a command can’t be executed when it’s mapped to a LifecycleEvent, because in Lifecycle the dispatcher is set to the context and not to the shared eventDispatcher.

    _dispatcher = target as IEventDispatcher || new EventDispatcher(this);

    Just to verify that, I added these listeners to the context:

    context.addEventListener( LifecycleEvent.POST_INITIALIZE, handler_1);

    eventDispatcher.addEventListener( LifecycleEvent.POST_INITIALIZE, handler_2);

    Only handler_1 gets called.

    Then, I added the following to Lifecycle. beforeInitializing()

        _dispatcher = target.injector.getInstance(IEventDispatcher)

    After that, the command has been executed.

    [Sorry Shaun for maltreating your framework like this ;) I undid the changes!!]

    Of course we can use a handler to run after initialization like this:

    and dispatch events to trigger commands, and so on, from within that handler.

    It works fine in a main Context, but I’ve noticed that it doesn’t work in a child Context. Maybe it’s a bug, maybe I’m doing something wrong, I don’t know. I should try different context-configurations and see what happens…


  2. Support Staff 2 Posted by Shaun Smith on 05 Feb, 2013 11:12 PM

    Shaun Smith's Avatar

    Yup, the EventDispatcherExtension is responsible for creating a shared event dispatcher, so it can't be relied on to exist. The LifeCycleEvents are dispatched by the Context (or lifecycle target) itself. Also note that Configs are executed toward the end of the Initialize phase, so there are a bunch of phases that you can't catch if you only start listening then.

    I wonder if the EventDispatcherExtension should re-dispatch the PostInitialize event along the dispatcher for this very use-case? Some other phases might make sense too (suspend, resume), I suppose, but others might cause issues as interacting with an unitialized or destructing context would be unpredictable.

  3. Support Staff 3 Posted by creynders on 06 Feb, 2013 08:11 AM

    creynders's Avatar

    Ok, that makes sense. But probably it should be made (more) clear in the docs.

    @Shaun However then, I think it would be better if the life cycle events aren't dispatched at all and you need to rely on the callbacks solely. I suppose the reason why the eventdispatcher was put into a separate extension was to provide the possibility that you can skip the eventdispatcher altogether and just use the signalextension for instance, right? Then it doesn't make sense to me that even when you use the signalextension, the context is dispatching events. And having the EventDispatcherExtension (re-)dispatch the PostInitialize event sounds like a good idea to me.

    @Ondina thanks, you're becoming a real authority on RL :)

  4. Support Staff 4 Posted by Ondina D.F. on 07 Feb, 2013 04:21 PM

    Ondina D.F.'s Avatar

    @creynders Haha, right! Thanks, but the emphasis is to be put on ‘becoming’;)
    There is a saying: “Even the smallest spark shines brightly in darkness.”
    So, if you’d participate more often in discussions, there would be at least 3 active authorities on rl :) Of course, the more participants, the better. The room would be much brighter... and colorful.

  5. Support Staff 5 Posted by creynders on 08 Feb, 2013 06:42 AM

    creynders's Avatar

    @ondina I definitely will try!

  6. Support Staff 6 Posted by Shaun Smith on 27 Feb, 2013 10:26 PM

    Shaun Smith's Avatar

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac