Mediator's onRegister() not running (but only at the first time)
Why would the mediator's onRegister() not run at the first time ?
/////////// 1st
var robotView :RobotView = new RobotView( 5, 0xFF0000, 4, 30,
30, 20 );
var robotModel :RobotModel = new RobotModel( robotView,
GameObjectType.ROBOT, RobotBodyType.CUBE3, RobotSoundSet.ROBOT1,
taskVector );
injector.injectInto( robotModel );
dispatch( new RobotEvent( RobotEvent.CREATE_ROBOT, robotModel )
);
/////////// 2nd
var robotView2 :RobotView = new RobotView( 5, 0xFF0000, 4, 30,
30, 20 );
var robotModel2 :RobotModel = new RobotModel( robotView2,
GameObjectType.ROBOT, RobotBodyType.CUBE3, RobotSoundSet.ROBOT1,
taskVector2 );
injector.injectInto( robotModel2 );
dispatch( new RobotEvent( RobotEvent.CREATE_ROBOT, robotModel2 )
);
I've tried adding more of those, and all work nicely, apart of the first one. Any ideas ?
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
Support Staff 1 Posted by Stray on 11 Jul, 2011 07:42 AM
Hi Patryk,
this one is always race conditions - check out the relevant section in the common-problems documentation - it has a list of things to check.
The nut-shell answer is that your view must be hitting the stage before the mediator is registered. There are 2 strategies for tackling this: 1) delay adding views until all your mediators are registered. 2) map all your mediators so that you map the most deeply nested views first and the context view itself last (if you're mapping it).
hth,
Stray
2 Posted by patryk on 11 Jul, 2011 08:14 AM
I am mapping the mediator in main context
public class MainContext extends Context
The RobotViews are being added far after the startUpCommand.
Is there a chance that the RobotViewMediator still has not been mapped even after the startUpCommand?
3 Posted by patryk on 11 Jul, 2011 09:44 AM
Ok , sorted, I am sorry for being a pain :)
I know I should read the documentation first rather then experiment and guess ... I don't know what's wrong with me...
Ondina D.F. closed this discussion on 01 Nov, 2011 04:14 PM.