Dispatching event from AppConfig to start database configuration
Following some examples in RL 1.0, i used the following line of code to start the application from the configuration of database
dispatchEvent(new DatabaseEvent(
DatabaseEvent.CONFIGURE));
I used above line but it's giving error in RL2.0 .
So, I referred some of the examples listed at (
http://knowledge.robotlegs.org/discussions/examples/20-links-to-rob...).
What i followed is either now i need to inject eventdispatcher ( in
AppConfig.as ? ) , or i should mediate the main-view, that would
dispatch the required event.
Or should i use context to dispatch event as follows ( However I couldnot make it work ):
context.dispatchEvent(new DatabaseEvent(
DatabaseEvent.CONFIGURE));
PS: I also found something as follows, seems like what i am looking for :
`context.lifecycle.afterInitializing( init );`
Or is their some other better way ? I need some guidance on
this.
Thnx
V.
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
1 Posted by zuzu on 23 Feb, 2013 10:52 PM
I am still new to RL2 (currently converting an old half-finished RL1 project) so I am no expert, but the most common way to dispatch Events in RL2 seems to be by injecting the eventDispatcher into the class:
and use it like this:
You can dispatch events (almost?) wherever you want but if you want to do it right after the mapping is done it could look somewhat like this:
Hope that helps
~Christina
2 Posted by vishwas.gagrani on 24 Feb, 2013 05:31 AM
thnx Christina.
Btw.. I am getting this error in the above :
Injector is missing a mapping to handle injection into target "[class AppConfig]" of type "swc::AppConfig".
V.
3 Posted by zuzu on 24 Feb, 2013 11:26 AM
The above code is compiling for me. The error message makes me believe context and dispatcher could not be injected into the class, hinting a problem with how you set up your context.
A minimal setup may look like this:
The MVCS Bundle is not needed to get my code above to run, but as soon as you want to map mediators/commands and so on you need either the bundle or install all needed extensions yourself.
4 Posted by vishwas.gagrani on 24 Feb, 2013 12:10 PM
Got rid of that error, but I am still not able to dispatch any event. Here are my 3 blocks of code Main.as ( Document Class), AppConfig.as, controller/ConfigureDatabaseCommand
Main.as
AppConfig.as :
controller/ConfigureDatabaseCommand.as
5 Posted by zuzu on 24 Feb, 2013 12:44 PM
I haven't tried to run your code but it seems you forgot to inject your commandMap:IEventCommandMap in AppConfig. Could well be the cause.
6 Posted by vishwas.gagrani on 24 Feb, 2013 01:51 PM
I think here is the reason, why i am not getting my event dispatched. Got the code from : https://github.com/darscan/robotlegs-demos-HelloFlex/blob/master/sr...
7 Posted by vishwas.gagrani on 24 Feb, 2013 04:25 PM
got eventdispatching working finally...
deleted the project, and used this example directly
https://github.com/darscan/robotlegs-demos-HelloFlash/tree/master/s...
Closing the thread . :)
Thnx
V.
vishwas.gagrani closed this discussion on 24 Feb, 2013 04:25 PM.
Shaun Smith re-opened this discussion on 24 Feb, 2013 05:10 PM
Support Staff 8 Posted by Shaun Smith on 24 Feb, 2013 05:10 PM
Hi Vishwas,
The root of your problem was related to how you were configuring things in your example code.
Configs are only processed towards the end of the context initialization phase, whereas Extensions are supposed to be installed before the context is initialized. You were trying to install the extensions inside of a config, which meant the extensions were being installed too late.
That is why all the official examples look something like this:
This ensures that the Bundle (and all Extensions in the Bundle) are installed before the Configs are processed.
In your code you were installing the MVCSBundle inside of the configure() method for a config, which leads to unpredictable results.
I'm going to take a look and see if I can introduce some code to throw an error if someone does this.
Hope that helps!
9 Posted by vishwas.gagrani on 26 Feb, 2013 07:11 PM
Ok. thanks for pointing that out. For now, I have just saved a basic template for RL2.0 to keep myself away from these mistakes. :)
V.
vishwas.gagrani closed this discussion on 26 Feb, 2013 07:11 PM.