Flex Events flow in non hierarchy e.g via framework responder - apache-flex

say an application has panel and panel has button and textField or textArea. we click on a button to hit a service say via cairngorm framework.
The Events lifecycle follows the capture-target-bubble cycle in the display hierarchy like the MouseClick event on button will call the handlers for the listeners attached to button and/or panel and/or application and/or stage since the flow moves in this direction.
How do the event on non hierarchy works e.g the result from the service fires a custom event DataRecieved. we have a listener attached to the panel/button for this dataRecieved event. How do this listener gets the information? how the event lifecycle comes into this picture?
Can anyone explain this?
Thanks!

Since it's a non-DisplayObject, the Event only has a target phase. That means that only listeners attached to the Object which is identical to the Object in the target property of the Event work. Hence, non-DisplayObject's can only dispatch Events to themselves. At least that's how I understand it.
In answer to a related question there is some discussion of writing custom EventDispatcher's that would enable a bubbling for non-DisplayObject's.

If you dispatch a custom event on a Flex UIComponent via dispatchEvent, the UIComponent takes care of bubbling the event through the display hierarchy, as long as the bubbles flag in the Event object is true.

I found out the concept of GlobalEventDispatcher to which we can attach listeners and dispatch from the same.
a ref from another question was helpful - Flex Custom Event dispatching
The important point is that - the instance of dispatcher must be same. we can keep a Custom Global singleton event dispatcher for our application or we can use stage/systemManager/FexGlobals.toplevelapplicaton for the purpose which might not be a good Practice.

Related

Messaging Centre - Subscribing Event in the ViewModel Constructor

I am trying to send data from one ViewModel to another using Messaging Centre.
I have subscribed the event in 2nd ViewModel's constructor. But the event is not subscribed as the constructor is not compiled until I open the page/view corresponding to the ViewModel.
I am using MVVM Light, until now I had an understanding that the VM's constructor are compiled when ViewModelLocator is called at the app startup.
Can someone help me understand this better and how can I subscribe the event i.e. compile the constructor without the VM being called.
Perhaps you are thinking about this in the wrong way. Without seeing code it's difficult to see what you are trying to achieve exactly, but what you could do is subscribe to the event elsewhere in your app, for example in your App.xaml.cs. When the event fires, at that point navigate to a new page of type ViewModel2 and pass any details required as a navigation parameter.

Flex - Difference between creationComplete and ApplicationComplete event?

Folks,
I didn't get the difference between those two event.
What is the difference between them ?
Explanation with e.g will always be appreciated.
Thanks.
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7ee6.html
Each component dispatches a creationComplete message during application startup - if it is meant to be created at startup. Otherwise each component will dispatch the message whenever it is actually created.
From the documentation link above:
After all components are created and
drawn, the Application object
dispatches an applicationComplete
event. This is the last event
dispatched during an application
startup.
*Edited to reflect other times when creationComplete events get dispatched, besides just the context of application startup.
See this link with the full explanation. In addition, creationComplete is dispatched by every Flex component but applicationComplete dispatched only one time by Application itself.
Both the Creationcomplete and application complete is part of the flex application life cycle. For more information and examples you can go to the following link:
http://technobytz.com/flex-preinitialize.html
Another important difference is your application doesn't have a reference to the stage until the applicationComplete is dispatched

add event into the loader in flex 4 air

I would like to know if it's possible to add some jobs on the onload of my air app, what I mean is:
I have an eventHandler which get the event "FlexEvent.APPLICATION_COMPLETE" but this event it`s dispatched after the progress bar ends, I would like to know if there is some event that I can handler and add my jobs there?!?
Or the only way to do this, it's doing a custom preloader??, like the link bellow:
Custom Preloader in Flex 4?
Thanks for all!
There are four events that an Application dispatches during its creation and initial display:
preinitialize
initialize
creationComplete
applicationComplete
More info at Adobe: About Startup Order
EDIT:
However, the Application itself is not instantiated until after all the RSL's have loaded, ie., when the Preloader fires an Event.COMPLETE (for that part of the preload). The preinitialize event on the Application should get fired while the Preloader is still displayed, but the initialization phase might just be much faster relative to the other loading phases. So, yes, if you want to do something concurrent to the Preloader loading RSL's, you have to write a custom preloader.

Mate not listening to events - Flex

I am working on a simple project involving flex 4 and Mate framework. When I am including Mate event map in fx:declarations tag in mxml file, and when I fire up an event, Mate event handlers listen to events and act upon it.
The issue is this, in action script based project, when I instantiate the eventmap class(this is in mxml file only) and keep it in top and fireup an event, instantiated eventmap is not listening to event fired up from action script class.
What do you think is going wrong?
Thanks in advance.
Antony. Just a suggestion, getting an example CafeTownSend http://mate.asfusion.com/page/examples/cafe-townsend is not a bad idea.
Build your application using that example will be much more easy. You can learn the event handling of MATE from that project too.
For some reason, the events dispatched by actionscript classes cannot be listened to by Mate event handlers.
To ensure, event handlers definitely receive events appropriately, we should make use of the class defined in mate called, com.asfusion.mate.events.Dispatcher. we just need to instantiate and dispatch an event with this class.

Do I need to unsubscribe from (manually subscribed to) events in asp.net?

Do the same best practis rules regarding subscribing/unsubscribing to events apply in asp.net?
I know it might seem like a silly question, but when I think about it, I have never really seen any code where people first subscribe to an event on a page and then unsubscribe later on in the web request.
Example 1:
On a page, in the Page_Load method, I subscribe to a updating event on a ListView. Should I unsubscribe from that event later on, for example in the OnPreRenderComplete method?
Example 2:
In the passive view patter, a view (Page control/Usercontrol) will raise an event whenever it needs the presenter to do anything. So the presenter needs to subscribe to events on the view, but do it also need to unsubscribe from the events again?
Best regards, Egil.
The page instance and all of its components will "go out of scope" when request completes, e.g. they become eligible for GC. So your ListView will go out of scope along with the Page/user controls on it. You don't need to unsubscribe (unless you subscribe to an event that belongs to some kind of singleton that survives every request and use one of the methods of the page as the event handler, for example).
The same thing is valid for the presenter (again as long as this presenter is used solely with one page and goes out of scope after that).
Generally, no. Events are supposed to be dumped automatically when the page unloads. SUPPOSED to be. I've run into a bug before (in .NET 1.1) where that wasn't the case.
I won't bother unsubscribing, unless I notice a problem with the page (like, a method being called 20 times from a phantom in the call stack: that's usually a sign of something not being unsubscribed properly).

Resources