One mediator for a Parent listening to many children
Hi i am very new at robotlegs,
Im trying to create a single mediator for a grid where each square in the grid is a different view and has independant events ( such as click ) attached to them.
there are of the order of 150 squares and it seems unreasonable to have a mediator for each one especially since only one signal can be fired at a time, so i am trying to create a parent grid and a mediator attached to that listening to signals for the children, i am trying not to do this using some central singleton which handles the signals and also i would like to leave it independant of the main context.
Thanks
Comments are currently closed for this discussion. You can start a new one.
2 Posted by Abel de Beer on 01 Dec, 2010 03:35 PM
It sounds very logical to create one view/mediator combination for the grid that contains all your 'square views'. Especially if they all fire the same types of events. For example, if all your squares dispatch a SquareEvent.CLICKED event, your grid view could listen for this event and dispatch a framework event (or signal of course) in response.
3 Posted by antoine.amassih on 01 Dec, 2010 03:52 PM
so how would the Mediator listen for the child event since its mapped to the Parent View.
mediatorMap.mapView(ParentView, ParentViewMediator);
Again im new , is it through :
addContextListener(SquareEvent.CLICKED , handleMessage)
for example even though the child view is not mapped?
4 Posted by Abel de Beer on 01 Dec, 2010 05:37 PM
Almost! You should do
addViewListener(SquareEvent.CLICKED, square_onClicked);. The event.target property should reference the clicked square.5 Posted by antoine.amassih on 01 Dec, 2010 05:45 PM
Will try it out Thanks for the help, Cheers
6 Posted by antoine.amassih on 05 Dec, 2010 05:40 PM
Abel,
So i tried what you suggested :
HexGrid View Contains HexBitmap View
i dispatch an Event in the HexBitmap View :
dispatchEvent(new HexEvent(HexEvent.HEX_CLICKED));Which works fine then i add this to the context:
mediatorMap.mapView(HexGrid, HexGridMediator);and the mediator :
`import org.robotlegs.demos.helloflash.controller.HexEvent;
Which for some reason doesnt accept the addViewListener or addContextListener . and of course it doesnt work.
Suggestions ?
Thanks
Support Staff 7 Posted by Shaun Smith on 05 Dec, 2010 05:46 PM
Make sure your HexEvent bubbles.
8 Posted by antoine.amassih on 05 Dec, 2010 06:07 PM
Hey Shaun,
Thanks but it does isnt it just
`public function HexEvent(type:String, body:* = null)
it doesnt work, i forgot to mention that im using:
eventMap.mapListener(eventDispatcher, HexEvent.HEX_CLICKED, OnSomeHexClicked);because its not recognizing addViewListener in the mediator.
Support Staff 9 Posted by Shaun Smith on 05 Dec, 2010 06:11 PM
Howdy. You need to override the clone method in your event or it won't bubble properly.
10 Posted by antoine.amassih on 05 Dec, 2010 06:14 PM
This is the whole Event Class
` package org.robotlegs.demos.helloflash.controller
{
}
`
its overriden
Support Staff 11 Posted by Shaun Smith on 05 Dec, 2010 06:26 PM
Hi. Looks like you're listening to the shared event dispatcher for those events, which doesn't make much sense:
eventMap.mapListener(eventDispatcher, HexEvent.HEX_CLICKED, OnSomeHexClicked);Surely you want to be listening to the view?
eventMap.mapListener(view, HexEvent.HEX_CLICKED, OnSomeHexClicked);12 Posted by antoine.amassih on 05 Dec, 2010 06:28 PM
Thanks a bunch for the quick responses, Works
Support Staff 13 Posted by Shaun Smith on 05 Dec, 2010 06:31 PM
It's a pleasure. Glad you're back on track
Shaun Smith closed this discussion on 05 Dec, 2010 06:31 PM.