tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/2206-how-do-i-map-an-event-to-a-views-buttonRobotlegs: Discussion 2013-04-08T08:21:50Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/261948112013-04-03T07:51:20Z2013-04-03T07:51:20ZHow do I map an event to a views button<div><p>Hi Joshua,</p>
<p>Hehe, Mitigator! Thanks for putting a smile on my face :)</p>
<p>The better way:</p>
<p>LoginView:</p>
<pre>
<code>private function employeeLoginButtonClickHandler(event:MouseEvent):void
{
loginVO.user_name = user_name.text;
dispatchEvent(new LoginEvent(LoginEvent.LOGIN_REQUESTED, loginVO));
}</code>
</pre>
<p>LoginMediator</p>
<pre>
<code>override public function onRegister():void
{
addViewListener(LoginEvent.LOGIN_REQUESTED, dispatch, LoginEvent);
}</code>
</pre>
<p>LoginEvent</p>
<pre>
<code>private var _loginVO:LoginVO;
public function LoginEvent (type:String, loginVO:LoginVO, bubbles:Boolean=false, cancelable:Boolean=false)
{
_loginVO = loginVO;
super(type, bubbles, cancelable);
}
public function get loginVO():LoginVO
{
return _loginVO;
}
override public function clone():Event
{
return new LoginEvent (type, loginVO);
}</code>
</pre>
<p>LoginEvent overrides clone(), so your mitigator can redispatch
it, either like this:<br></p>
<pre>
<code>addViewListener(LoginEvent.LOGIN_REQUESTED, dispatch, LoginEvent);</code>
</pre>
<p>or like this:</p>
<pre>
<code>addViewListener(LoginEvent.LOGIN_REQUESTED, onLoginRequested, LoginEvent);
private function onLoginRequested (event:LoginEvent):void
{
dispatch(event);
}</code>
</pre>
<p>Does this help?<br>
Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/261948112013-04-06T10:43:42Z2013-04-06T10:43:44ZHow do I map an event to a views button<div><p>This worked perfectly.. Thanks for your reply.. and yes the
mediator made me laugh too because im pretty sure I called it a
mitigator in front of my supervisor who is guiding/grooming me for
a junior role. <em>headsmack</em> he probably knew i meant
mediatior...</p></div>Joshua Cavetag:robotlegs.tenderapp.com,2009-10-18:Comment/261948112013-04-08T08:21:46Z2013-04-08T08:21:46ZHow do I map an event to a views button<div><p>Hey Joshua,</p>
<p>You’re welcome.<br>
I’m sure your supervisor liked it. Mitigator sounds cool and
original ;) It also adds a new perspective to the roles of
Mediators. It <em>alleviates</em> Views’ situation: Views
become well encapsulated, flexible, framework-agnostic, portable
and reusable.<br>
If I were you, I’d name my mediators SomeMitigator,
AnotherMitigator, LoginMitigator, just for the fun of it.</p>
<p>Closing this discussion for now.</p>
<p>Ondina</p></div>Ondina D.F.