Mate not listening to events - Flex - apache-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.

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 Events flow in non hierarchy e.g via framework responder

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.

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.

Help understanding Cairngorm Event in Flex

I was going through this article by David Tucker (http://www.davidtucker.net/2007/10/29/cairngorm-part-3/) in which he talks about Cairngorm Events.
There are two things that I want to ask in this-
What is the significance of calling the constructor of the parent class with the event arg? super(LOGIN) in the example
Why do you need to overrride the clone method?
Understanding these things will give me a better insight into the way things are done with Cairngorm.
Thanks
Both questions are not specific to Cairngorm events. This is standard mechanism for AS3 events.
Cairngorm events inherit from Event and Event class requires a "type" string. That's why you need to specify it in the constuctor.
When creating a custom event class, you need to override the clone method. This method is automatically called by the Flash Player when you want to re-dispatch an instance of a custom event.

Resources