tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/12905-flex-invoke-event-in-robotlegsRobotlegs: Discussion 2015-08-19T21:05:52Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/368033132015-05-12T09:53:24Z2015-05-12T09:58:14ZFlex invoke event in Robotlegs <div><p>Hi,</p>
<p>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.</p>
<p>The order of events that are dispatched during a
component’s creation life cycle in Flex/AIR:</p>
<p>FlexEvent.PREINITIALIZE</p>
<p>FlexEvent.INITIALIZE</p>
<p>FlexEvent.CREATION_COMPLETE</p>
<p>Event.ADDED_TO_STAGE</p>
<p>FlexEvent.UPDATE_COMPLETE</p>
<p>FlexEvent.APPLICATION_COMPLETE</p>
<p>flash.events.InvokeEvent</p>
<p>The InvokeEvent is the last one in the list!</p>
<p>In my experience, the best place to initialize the Context for
the application is within the handler of FlexEvent.PREINITIALIZE
.</p>
<p>From Adobe:<br>
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.</p>
<p>I suppose that the InvokeEvent would be also dispatched every
time the application is resized or minimized and then maximized
again.</p>
<p>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.</p>
<p>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.</p>
<blockquote>
<p>I currently use to determine if the application was opened by
double clicking a file image</p>
</blockquote>
<p>And what should happen after that?<br>
Is the Context already initialized?<br>
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?<br>
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]</p>
<p>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..</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/368033132015-05-12T14:15:29Z2015-08-19T21:05:52ZFlex invoke event in Robotlegs <div><p>Ondina,</p>
<p>Thanks for your detailed reply. I was not able to find
documentation that said the invoke event came last! That clears up
a lot!</p>
<p>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.</p>
<p>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.</p>
<p>Thanks</p></div>dkartentag:robotlegs.tenderapp.com,2009-10-18:Comment/368033132015-05-12T16:40:44Z2015-05-12T16:43:04ZFlex invoke event in Robotlegs <div><p>My pleasure:)</p>
<p>I was curious about InvokeEvent's behaviour, so I tried it out
in a simple AIR application.<br>
I was wrong about it being dispatched every time the application is
resized.<br>
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.</p>
<p>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.</p>
<p>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.</p>
<p>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:</p>
<p>
NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE,
onInvoke);</p>
<p>and let its mediator communicate with other parts of your
app.</p>
<p>Both scenarios are ok. It's up to you to find out which one is
working as expected.</p>
<blockquote>
<p>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)?</p>
</blockquote>
<p>Yes, that's correct. You'll be a robotlges expert in no
time:)</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/368033132015-05-13T16:19:09Z2015-08-19T21:05:52ZFlex invoke event in Robotlegs <div><p>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!</p></div>dkartentag:robotlegs.tenderapp.com,2009-10-18:Comment/368033132015-05-14T08:58:00Z2015-05-14T08:58:00ZFlex invoke event in Robotlegs <div><p>No problem:)</p>
<blockquote>
<p>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.</p>
</blockquote>
<p>Sounds good.</p>
<blockquote>
<p>Great stuff, really impressed with robotlegs so far!</p>
</blockquote>
<p>I'm glad to hear that:)</p>
<p>Looks like this issue is resolved, hence I'm closing it. You can
reopen the discussion, if need be.<br>
And, of course, you're welcome to create other threads for new
questions/issues.</p>
<p>Have fun with robotlegs!</p>
<p>Ondina</p></div>Ondina D.F.