SyntaxScrewer's Blog

September 10, 2010

RobotLegs – Dispatching events from the view, making the mediator listen.

Filed under: ActionScript 3.0,Flash — geekymaira @ 7:57 pm

Hi,

So basically I was trying to do something really basic in RobotLegs and got stuck.
Wanted to dispatch an event from a view and listen to it in the mapped mediator.
The problem was that I was dispatching the event from the view before it actually got added
to the stage ie. Before the view dispatched the ADDED_TO_STAGE event.

The mediator wouldn’t catch any event because it was dispatched before the ADDED_TO_STAGE
for the view, which I think is when the onRegister() for the mediator gets executed.

Finally got it fixed. The solution was simple – Added a listener to the mediator for the ADDED_TO_STAGE event of the mediated view
and called a public function view.init(); from the handler. Dispatched the desired event from the view.init() function.

So the things to keep in mind are :
– Add mediators to views before adding the view to the context.
– Before dispatching an event from the view, make sure the view has dispatched the ADDED_TO_STAGE event.
– Listen to the ADDED_TO_STAGE event in the mediator and call an init() function on the view.

PS: This post was written essentially so that I don’t land in the same situation again 🙂

Cheers!
SyntaxScrewer.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: