Flex invoke event in Robotlegs

dkarten's Avatar

dkarten

11 May, 2015 04:53 PM

Hi all,

Flex has an invoke event that I currently use to determine if the application was opened by double clicking a file image. How would one handle this in Robotlegs startup? I searched the documentation and examples, but didn't really see anything that dealt with this phase of startup and how it fit in with RL bootstrapping.

  1. Support Staff 1 Posted by Ondina D.F. on 12 May, 2015 09:53 AM

    Ondina D.F.'s Avatar

    Hi,

    Robotlegs is only interested in the ADDED_TO_STAGE ( and the CREATION_COMPLETE for Flex UIComponents ) event(s), so it can create Mediators for mapped views landing on the stage.

    The order of events that are dispatched during a component’s creation life cycle in Flex/AIR:

    FlexEvent.PREINITIALIZE

    FlexEvent.INITIALIZE

    FlexEvent.CREATION_COMPLETE

    Event.ADDED_TO_STAGE

    FlexEvent.UPDATE_COMPLETE

    FlexEvent.APPLICATION_COMPLETE

    flash.events.InvokeEvent

    The InvokeEvent is the last one in the list!

    In my experience, the best place to initialize the Context for the application is within the handler of FlexEvent.PREINITIALIZE .

    From Adobe:
    The NativeApplication object always dispatches an invoke event when an application is launched, but the event may be dispatched at other times as well. For example, a running application dispatches an additional InvokeEvent when a user activates a file associated with the application.

    I suppose that the InvokeEvent would be also dispatched every time the application is resized or minimized and then maximized again.

    Because of that I wouldn't initialize the context in the handler of an InvokeEvent. But, since I've never needed an InvokeEvent in my applications until now, I don't really know much about its behaviour.

    Anyway, where and how the context is created is the responsibility of the user. The framework, as I said, is only interested on the ADDED_TO_STAGE event.

    I currently use to determine if the application was opened by double clicking a file image

    And what should happen after that?
    Is the Context already initialized?
    Are you using this event in the hope that everything in the application has been initialized and is ready for user interactions and the framework classes are able to do their work?
    If the answer is yes, then FlexEvent.APPLICATION_COMPLETE would be the one you should use, because it is " dispatched after the application has been initialized, processed by the LayoutManager, and attached to the display list. This is the last event dispatched during an application’s startup sequence." [Adobe]

    On the other hand, there is robotlegs' context.afterInitializing() handler to run after the initialization of the context, that you can use to your advantage, for example for a service call..

    Ondina

  2. 2 Posted by dkarten on 12 May, 2015 02:15 PM

    dkarten's Avatar

    Ondina,

    Thanks for your detailed reply. I was not able to find documentation that said the invoke event came last! That clears up a lot!

    In my use case, users can save individual database files. This makes it easy for them to transfer them amongst computers and to people they are collaborating with. This also allows user to double click directly on the saved file and expect that the app open directly to that file. The way I handle this now is through the invoke event, where you can check the InvokeEvent's arguments for a filename.

    So if the invoke event handler found that a specific file was requested on startup and stored a reference to this file, I would be able to wire this information to the context and make the appropriate service call to the database file? And the best way to do this, if I understand the separation of roles correctly, would be with a mediator (on the main app)? I've only been working with Robotlegs for about a week but I love it so far.

    Thanks

  3. Support Staff 3 Posted by Ondina D.F. on 12 May, 2015 04:40 PM

    Ondina D.F.'s Avatar

    My pleasure:)

    I was curious about InvokeEvent's behaviour, so I tried it out in a simple AIR application.
    I was wrong about it being dispatched every time the application is resized.
    But, there seems to be a difference between a spark.components.WindowedApplication.invoke and an InvokeEvent.INVOKE dispatched by the NativeApplication concerning the order in which they are dispatched.

    When the application is launched for the first time, the NativeApplication's InvokeEvent.INVOKE is dispatched right after the FlexEvent.INITIALIZE (if a listener has been registered inside the preinitialized handler), whereas the WindowedApplication.invoke is the last one dispatched, as I said before.

    If you initialized the context within the preinitialize handler, as I suggested, then the mediator for the main view (windowedapplication) would be already created and ready for receiving events from the view ( preferably custom events) by the time the WindowedApplication.invoke is dispatched. Of course, you can let the mediator redispatch the event to make a service call or whatever else you need.

    Instead of the main view, you can also use a child of the main view to register a listener for the NativeApplication's invoke event:

    NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, onInvoke);

    and let its mediator communicate with other parts of your app.

    Both scenarios are ok. It's up to you to find out which one is working as expected.

    So if the invoke event handler found that a specific file was requested on startup and stored a reference to this file, I would be able to wire this information to the context and make the appropriate service call to the database file? And the best way to do this, if I understand the separation of roles correctly, would be with a mediator (on the main app)?

    Yes, that's correct. You'll be a robotlges expert in no time:)

    Ondina

  4. 4 Posted by dkarten on 13 May, 2015 04:19 PM

    dkarten's Avatar

    Awesome, thanks so much. I found I was able to just add a view listener for InvokeEvent.INVOKE to the AppMediator, and then remove it at the end of the handler. That way it is only called once since we only need to check for an invoked file on app startup. Great stuff, really impressed with robotlegs so far!

  5. Support Staff 5 Posted by Ondina D.F. on 14 May, 2015 08:58 AM

    Ondina D.F.'s Avatar

    No problem:)

    I found I was able to just add a view listener for InvokeEvent.INVOKE to the AppMediator, and then remove it at the end of the handler. That way it is only called once since we only need to check for an invoked file on app startup.

    Sounds good.

    Great stuff, really impressed with robotlegs so far!

    I'm glad to hear that:)

    Looks like this issue is resolved, hence I'm closing it. You can reopen the discussion, if need be.
    And, of course, you're welcome to create other threads for new questions/issues.

    Have fun with robotlegs!

    Ondina

  6. Ondina D.F. closed this discussion on 14 May, 2015 08:58 AM.

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

Keyboard shortcuts

Generic

? 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