Mediator dispatches an event, but command doesn't pick it up
Robotlegs v1.1.1
FlashBuilder 4
Firefox 3.6.3 on Windows XP
Flash Player 10.1.53.64 (debug)
Firebug 1.5.3
Flashbug 1.6.3
I'm hitting a wall here. I've read the demos and got confused with the older implementations there. Read through the best practices guide. Googled and still can't find out what's up. I'm a little new to RobotLegs so please forgive my ignorance.
Basically, I have a simple app with a login form (see attached zip). I have a context that maps ContextEvent.STARTUP to StartupCommand and dispatches the ContextEvent.STARTUP event. StartupCommand.execute() is called successfully. Yay! However, I try the same way of doing things on my login button. It fires the LoginFormEvent.LOGIN_SUBMITTED event when the button is clicked. The LoginMediator picks it up ok then re-dispatches (little confused as to why but that was the pattern) the event to the framework. The problem is LoginCommand.execute() is never ran. It looks like in the MyAppContext.as file that I've done the commandMap.mapEvent() call correctly for it. I've checked it a few times. I've even tried just a quick test and dispatch the LoginFormEvent directly from the context just like I do with ContextEvent.STARTUP. It works then. So it's something down in the LoginMediator that doesn't place the event on the right bus in the context or something... shrug
Any ideas would be awesome!
- MyApp.zip 2.29 MB
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 Stray on 23 Jun, 2010 08:22 PM
Hi Justin,
I just wanted to confirm that there's nothing obviously wrong with your code - at least not the AS part - I'm not familiar with mxmlc.
I wasn't able to compile it (I have a kind of weird set up because I use sprouts) but hopefully someone else will do shortly.
Hopefully someone more Flex centric will be around shortly to actually compile it and confirm the result you're having.
If you trace out the eventDispatcher - literally trace(eventDispatcher) - just before you do the dispatch(e) in your mediator, and also somewhere else - for example in the command that is working ok - that might give you a clue. They should be the same object.
Which version of swift suspenders are you using? You need the latest one to work with RL 1.1.1 and FP 10.1
Stray
2 Posted by Justin on 23 Jun, 2010 08:37 PM
Howdy Stray,
Thanks for the response! I'm using what ever version of Swift Suspenders (SS) came with the distro. It looks like it's classes are included in the robotlegs swc file under the org.swiftsupsenders package. Would I need a separate swc for SS? I saw this done in some examples but thought I could get away with just the robotlegs swc. I'll grab the latest one and give it a go.
Tracing the eventDispatcher yields the same object. I actually had to go into debug mode with FB4 and find the object id (I think) which was @21766809 in my case.
Support Staff 3 Posted by Shaun Smith on 23 Jun, 2010 08:45 PM
Hi Justin,
You need to override your custom event's clone() method - the Flash Player will not let you re-dispatch events without doing that. Something like this:
The same is true for bubbling events: without the clone method they will not bubble. This is a Flash Player rule and nothing to do with Robotlegs.
Hope that helps!
4 Posted by Justin on 23 Jun, 2010 08:52 PM
Brilliant! Yes. That did the trick. Thank you Shaun for saving me days of research! I wouldn't have found that at all. This one is resolved.
Support Staff 5 Posted by Shaun Smith on 23 Jun, 2010 09:02 PM
My pleasure! This one has tripped up quite a number of folk.. we should add it the knowledgebase somewhere prominent.
Shaun Smith closed this discussion on 23 Jun, 2010 09:05 PM.