Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Reaction to FlexEvent?  (Read 14578 times)
deltajam
Courseware Beta
Full Member
***
Posts: 25


View Profile Email
« on: March 29, 2009, 12:44:37 »

Can anyone confirm that they have this working?  I'm trying to listen to a creationComplete from my application with my Mediator, however it does not seem to get called.  However, I have a handler that listens for resize that works just fine.

so to cap off:

reactToApplicationResize( e:Event ) - works just fine;
reactToApplicationCreationComplete( e:FlexEvent ) - does not work


any ideas?
Logged
Ondina
Sr. Member
****
Posts: 86


View Profile Email
« Reply #1 on: March 29, 2009, 02:42:13 »

Maybe because of this:

puremvc Best Practice:
"Since we are initializing the variable with a call to the static ApplicationFacade.getInstance method, this means that by the time the Application’s creationComplete event fires, the Façade will have been created and along with it, the Model, View and Controller, though no Mediators or Proxies will have been created yet. "
Logged

~ Ondina ~
Jason MacDonald
Sr. Member
****
Posts: 243


View Profile Email
« Reply #2 on: March 29, 2009, 09:11:10 »

I use Fabrication with Flash, not Flex, but I believe Fabrication may not be finished initializing yet. If I'm not mistaken, by the time your very first mediator (appMediator) gets it's onRegister() method called Flex should already be created.
Logged
deltajam
Courseware Beta
Full Member
***
Posts: 25


View Profile Email
« Reply #3 on: March 29, 2009, 12:16:48 »

Hmmm, I'm not entirely sure that this is correct, because in my Application file, I listen for creationComplete and trace it out, and in my ApplicationMediator I trace the mediator out when it registers ... and low and behold, ApplicationMediator gets registered first, and then the creationComplete event is traced.

Is it possible that you can't listen for FlexEvent calls with reactions?  I solved my small problem by just listening for the Event.ADDED_TO_STAGE in my Mediator, which I used as a reaction (reactToApplicationAddedToStage).

I understand what you guys are saying, but it still doesn't make sense to me.
Logged
Jason MacDonald
Sr. Member
****
Posts: 243


View Profile Email
« Reply #4 on: March 29, 2009, 02:39:51 »

I very well could be wrong. I don't use Flex. However, I'm 100% sure that the reactTo is meant to work with Flex events, or any events for that matter.
Logged
deltajam
Courseware Beta
Full Member
***
Posts: 25


View Profile Email
« Reply #5 on: March 29, 2009, 06:13:54 »

I'm 100% sure that the reactTo is meant to work with Flex events, or any events for that matter.

I really wish so! :(  The only logical answer I can come up with to support my conclusion, is found in the org.puremvc.as3.multicore.utilities.fabrication.vo.Reaction class on line 94, with this function here:

:
public function fulfil(event:Event):void {
handler(event);
}

I understand that FlexEvent is a sub class of Event, but MouseEvent also extends Event ... and works just fine.  So, I'm not sure if that function above has anything to do with it (probably not).
Logged
Ondina
Sr. Member
****
Posts: 86


View Profile Email
« Reply #6 on: March 30, 2009, 12:21:26 »

I solved my small problem by just listening for the Event.ADDED_TO_STAGE in my Mediator

This would be the same as using the onRegister method, meaning that you only can do something/anything in your mediator after it has been created.

Isn't that so?
Logged

~ Ondina ~
deltajam
Courseware Beta
Full Member
***
Posts: 25


View Profile Email
« Reply #7 on: March 30, 2009, 11:19:19 »

sure.  The creationComplete event is not fired by the time the mediator is registered, so I should be able to listen to it.  That is the point of this post.  For whatever reason, I can't listen to that event being fired ... even though I add an eventlistener before the event is fired.
Logged
Ondina
Sr. Member
****
Posts: 86


View Profile Email
« Reply #8 on: March 30, 2009, 11:36:33 »

How can you react to an event, if you aren't there by the time the event  is occurring?

In a classic puremvc application you could, if you wanted/needed to, initialize the Facade on creationComplete and then in your mediator listen for applicationComplete, which is the last event dispatched during an application startup.
Look at this:
http://www.wietseveenstra.nl/blog/2007/02/understanding-the-flex-application-startup-event-order/

On creationComplete or on applicationComplete you first initialize the PureMVC apparatus:
First the Facade, then the Commands, Proxies, Mediators.


In Fabrication ( as I understand it ) FlexApplicationFabricator is the first one that handles the FlexEvent.CREATION_COMPLETE, so if you'd trace it you'd see that the creationComplete that you're handling in your main app is called after the initializeEnvironment() in Fabricator, which does:
facade.registerCommand(FabricationNotification.STARTUP, ApplicationStartupCommand);
which does :
facade.registerMediator(new ApplicationMediator(app));

So your Mediator can't listen to anything happening before its own creation. It just isn't there, and it surely isn't God :)

Please correct me if I'm wrong.

Is it possible that you can't listen for FlexEvent calls with reactions? 

You can. Try BUTTON_DOWN.
Logged

~ Ondina ~
deltajam
Courseware Beta
Full Member
***
Posts: 25


View Profile Email
« Reply #9 on: March 30, 2009, 05:26:41 »

Nope, you're right!  Thanks for straightening me out :)
Logged
Darshan Sawardekar
Sr. Member
****
Posts: 85


View Profile Email
« Reply #10 on: April 01, 2009, 08:18:33 »

Yup, like Ondina said, Fabrication initializes with creationComplete event in FlexApplication. Thats the reason your creationComplete handler isn't firing. The code in your creationComplete handler would be better placed in your startup command.

peace,
darshan
Logged
Pages: [1]
Print