<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flex Stuff by Gilles Guillemin &#187; Mate Framework</title>
	<atom:link href="http://www.flexstuff.co.uk/category/mateframework/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.flexstuff.co.uk</link>
	<description>Stuff about Flex. And Air. Oh and Flash. And probably about other stuff as well. Who knows?</description>
	<lastBuildDate>Thu, 24 Dec 2009 12:38:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Mate examples: #11 Mediator (or Passive View)</title>
		<link>http://www.flexstuff.co.uk/2009/10/13/mate-examples-11-mediator-or-passive-view/</link>
		<comments>http://www.flexstuff.co.uk/2009/10/13/mate-examples-11-mediator-or-passive-view/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 07:00:26 +0000</pubDate>
		<dc:creator>gillesguillemin</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Mate Framework]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[London Flash Platform User Group]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[mxml]]></category>

		<guid isPermaLink="false">http://www.flexstuff.co.uk/?p=559</guid>
		<description><![CDATA[This is the eleventh of a series of gradually more complex examples on how to use Mate. Here we see how to use the Mediator (or Passive View) pattern with Mate.


Related posts:<ol><li><a href='http://www.flexstuff.co.uk/2009/08/25/mate-examples-10-presentation-model/' rel='bookmark' title='Permanent Link: Mate examples: #10 Presentation Model'>Mate examples: #10 Presentation Model</a> <small>This is the tenth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/06/mate-examples-4-counters-created-dynamically/' rel='bookmark' title='Permanent Link: Mate examples: #4 Counters created dynamically'>Mate examples: #4 Counters created dynamically</a> <small>This is the fourth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/18/mate-examples-8-modules-example-pt-1/' rel='bookmark' title='Permanent Link: Mate examples: #8 Modules Example (pt 1)'>Mate examples: #8 Modules Example (pt 1)</a> <small>This is the eigth of a series of gradually more...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>This blog post is related to <a href="http://www.flexstuff.co.uk/2009/08/05/my-lfpug-presentation-about-mate/" target="_blank">My LFPUG Presentation about Mate</a> blog post (I know, it was 3 months ago, it&#8217;s a shame but I also must work for a living).</p>
<p>If you haven&#8217;t done it yet you should have a look first at our previous examples: <a href="http://www.flexstuff.co.uk/2009/08/05/mate-examples-1-a-very-basic-injectors-example/" target="_blank">#1,</a> <a href="http://www.flexstuff.co.uk/2009/08/05/mate-examples-2-databinding-and-eventhandlers/" target="_blank">#2</a>, <a href="http://www.flexstuff.co.uk/2009/08/06/mate-examples-3-multiple-counters/" target="_blank">#3</a>, <a href="http://www.flexstuff.co.uk/?p=521" target="_blank">#4</a>, <a href="http://www.flexstuff.co.uk/2009/08/06/mate-examples-5-localeventmap/" target="_blank">#5</a>, <a href="http://www.flexstuff.co.uk/2009/08/09/mate-examples-6-reset-countdown-pt-1/" target="_blank">#6</a>, <a href="http://www.flexstuff.co.uk/2009/08/09/mate-examples-7-reset-countdown-pt-2/" target="_blank">#7</a>, <a href="http://www.flexstuff.co.uk/2009/08/18/mate-examples-8-modules-example-pt-1/" target="_blank">#8</a>, <a href="http://www.flexstuff.co.uk/2009/08/23/mate-examples-9-modules-example-pt-2/" target="_blank">#9</a> and <a href="http://www.flexstuff.co.uk/2009/08/25/mate-examples-10-presentation-model/" target="_blank">#10</a>.</p>
<p>In our previous example we&#8217;ve studied a simple implementation of the Presentation Pattern. In this configuration, the View has a reference to its presentation model (or at least to its interface). But what if you want it to be the other way around? The view exists for itself and the model is the one who has a reference to the view. This approach definitely is a prime candidate if you want to use views generated in Flash Catalyst then synchronised with Flash Builder with <a href="http://www.flexstuff.co.uk/applications/catalystbuildersync/" target="_blank">CatalystBuilderSync</a>. You can easily modify your views without affecting the logic whatsoever. The view is dumb or passive as explained in <a href="http://blogs.adobe.com/paulw/archives/2007/11/presentation_pa_6.html#more" target="_blank">this other article by Paul Williams</a>. It&#8217;s also one of the patterns used in <a href="http://puremvc.org" target="_blank">PureMVC</a>, called Mediator and we will keep the name here. So, how is it possible with Mate?</p>
<p>Let&#8217;s have a look (source is available by right-clicking on the demo after launching it):</p>
<div class="wp-caption aligncenter" style="width: 360px"><a class="lightview" title="#11 Mediator (a la PureMVC) :: Right-click to view the source. :: width: 1024, height: 768" href="http://flexstuff.co.uk/wp-content/uploads/examples/mate_lfpug/_Demo11%20-%20Mediator/Demo.swf"><img src="http://flexstuff.co.uk/wp-content/uploads/examples/mate_lfpug/_Demo11%20-%20Mediator/Mate_example10.png" alt="Mate example" width="350" height="250" /></a><p class="wp-caption-text">#11 Mediator (a la PureMVC) (click to Launch)</p></div>
<p><span id="more-559"></span><br />
As you can see, the 2 views FirstPanel.mxml and SecondPanel.mxml are completely autonomous, without any reference to anything else nor any logic:</p>
<p><cite><br />
<h3>Demo #11: src/views/FirstPanel.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;298&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;164&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layout=<span style="color: #990000;">&quot;absolute&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title=<span style="color: #990000;">&quot;First Panel&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;button1&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;Button One&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">left</span>=<span style="color: #990000;">&quot;30&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;verticalCenter=<span style="color: #990000;">&quot;0&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;button2&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;Button Two&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">right</span>=<span style="color: #990000;">&quot;30&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;verticalCenter=<span style="color: #990000;">&quot;0&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p><cite><br />
<h3>Demo #11: src/views/SecondPanel.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;246&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;232&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layout=<span style="color: #990000;">&quot;absolute&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title=<span style="color: #990000;">&quot;Deuxieme Panel&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; borderStyle=<span style="color: #990000;">&quot;inset&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">backgroundColor</span>=<span style="color: #990000;">&quot;#A5C5ED&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;button1&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;Bouton Un&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;horizontalCenter=<span style="color: #990000;">&quot;0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">top</span>=<span style="color: #990000;">&quot;20&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;emphasized=<span style="color: #990000;">&quot;true&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cornerRadius=<span style="color: #990000;">&quot;0&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;button2&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;Bouton Deux&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;horizontalCenter=<span style="color: #990000;">&quot;0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">bottom</span>=<span style="color: #990000;">&quot;20&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cornerRadius=<span style="color: #990000;">&quot;0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fillAlphas=<span style="color: #990000;">&quot;[1.0, 1.0]&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fillColors=<span style="color: #990000;">&quot;[#FF0000, #FF0000]&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">color</span>=<span style="color: #990000;">&quot;#FFFFFF&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>Now the mediators which embed all the logic and the reference to their respective view (which is passed as an argument of the initMediator method):</p>
<p><cite><br />
<h3>Demo #11: src/views/mediators/FirstPanelMediator.as</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span> views<span style="color: #000066; font-weight: bold;">.</span>mediators<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">EventDispatcher</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>controls<span style="color: #000066; font-weight: bold;">.</span>Alert<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>FirstPanel<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> FirstPanelMediator <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">EventDispatcher</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> component <span style="color: #000066; font-weight: bold;">:</span> FirstPanel<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> initMediator<span style="color: #000000;">&#40;</span><span style="color: #004993;">target</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; component = <span style="color: #004993;">target</span> <span style="color: #0033ff; font-weight: bold;">as</span> FirstPanel<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; component<span style="color: #000066; font-weight: bold;">.</span>button1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> button1_clickHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; component<span style="color: #000066; font-weight: bold;">.</span>button2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> button2_clickHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> button1_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Alert<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">show</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Button1 Clicked&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> button2_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Alert<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">show</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Button2 Clicked&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p><cite><br />
<h3>Demo #11: src/views/mediators/SecondPanelMediator.as</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span> views<span style="color: #000066; font-weight: bold;">.</span>mediators<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">EventDispatcher</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>controls<span style="color: #000066; font-weight: bold;">.</span>Alert<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>SecondPanel<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> SecondPanelMediator <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">EventDispatcher</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> component <span style="color: #000066; font-weight: bold;">:</span> SecondPanel<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> initMediator<span style="color: #000000;">&#40;</span><span style="color: #004993;">target</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; component = <span style="color: #004993;">target</span> <span style="color: #0033ff; font-weight: bold;">as</span> SecondPanel<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; component<span style="color: #000066; font-weight: bold;">.</span>button1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> button1_clickHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; component<span style="color: #000066; font-weight: bold;">.</span>button2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> button2_clickHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> button1_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Alert<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">show</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Oh, I do not like this.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> button2_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Alert<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">show</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Please, don't do that.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>And finally the eventMap which ties together views and mediators via injection:</p>
<p><cite><br />
<h3>Demo #11: src/maps/MainEventMap.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventMap xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns<span style="color: #000066; font-weight: bold;">:</span>mate=<span style="color: #990000;">&quot;http://mate.asfusion.com/&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>SecondPanel<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>mediators<span style="color: #000066; font-weight: bold;">.</span>SecondPanelMediator<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>events<span style="color: #000066; font-weight: bold;">.</span>FlexEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>FirstPanel<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>mediators<span style="color: #000066; font-weight: bold;">.</span>FirstPanelMediator<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Debugger <span style="color: #004993;">level</span>=<span style="color: #990000;">&quot;{Debugger.ALL}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors <span style="color: #004993;">target</span>=<span style="color: #990000;">&quot;{FirstPanel}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>MethodInvoker generator=<span style="color: #990000;">&quot;{FirstPanelMediator}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;initMediator&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">arguments</span>=<span style="color: #990000;">&quot;{event.injectorTarget}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors <span style="color: #004993;">target</span>=<span style="color: #990000;">&quot;{SecondPanel}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>MethodInvoker generator=<span style="color: #990000;">&quot;{SecondPanelMediator}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;initMediator&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">arguments</span>=<span style="color: #990000;">&quot;{event.injectorTarget}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventMap<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>Whenever a view is instantiated then its related mediator is instantiated as well, its initMediator method is called and the injector&#8217;s target (the view: FirstPanel or SecondPanel) is passed as an argument. Important: note the use of Mate&#8217;s event.injectorTarget to retrieve the injector&#8217;s target reference. You cannot pass directly {FirstPanel} or {SecondPanel}. It wouldn&#8217;t work.</p>
<p>I&#8217;ll tell you what: this Mediator approach is quite simply my favourite at the moment as it leaves you with the maximum freedom to deal with the new Flex 4 paradigm (component + skin) without interfering with it at any point.</p>
<p>Next time (hopefully sooner than next month): Versioned Applications (think about Modules but more powerful)</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.flexstuff.co.uk%2F2009%2F10%2F13%2Fmate-examples-11-mediator-or-passive-view%2F';
  addthis_title  = 'Mate+examples%3A+%2311+Mediator+%28or+Passive+View%29';
  addthis_pub    = 'gillesguillemin';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>


<p>Related posts:<ol><li><a href='http://www.flexstuff.co.uk/2009/08/25/mate-examples-10-presentation-model/' rel='bookmark' title='Permanent Link: Mate examples: #10 Presentation Model'>Mate examples: #10 Presentation Model</a> <small>This is the tenth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/06/mate-examples-4-counters-created-dynamically/' rel='bookmark' title='Permanent Link: Mate examples: #4 Counters created dynamically'>Mate examples: #4 Counters created dynamically</a> <small>This is the fourth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/18/mate-examples-8-modules-example-pt-1/' rel='bookmark' title='Permanent Link: Mate examples: #8 Modules Example (pt 1)'>Mate examples: #8 Modules Example (pt 1)</a> <small>This is the eigth of a series of gradually more...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.flexstuff.co.uk/2009/10/13/mate-examples-11-mediator-or-passive-view/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Mate examples: #10 Presentation Model</title>
		<link>http://www.flexstuff.co.uk/2009/08/25/mate-examples-10-presentation-model/</link>
		<comments>http://www.flexstuff.co.uk/2009/08/25/mate-examples-10-presentation-model/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 07:37:04 +0000</pubDate>
		<dc:creator>gillesguillemin</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Mate Framework]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[London Flash Platform User Group]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[mxml]]></category>

		<guid isPermaLink="false">http://www.flexstuff.co.uk/?p=556</guid>
		<description><![CDATA[This is the tenth of a series of gradually more complex examples on how to use Mate. Here we see how to use the Presentation Model pattern with Mate.


Related posts:<ol><li><a href='http://www.flexstuff.co.uk/2009/10/13/mate-examples-11-mediator-or-passive-view/' rel='bookmark' title='Permanent Link: Mate examples: #11 Mediator (or Passive View)'>Mate examples: #11 Mediator (or Passive View)</a> <small>This is the eleventh of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/23/mate-examples-9-modules-example-pt-2/' rel='bookmark' title='Permanent Link: Mate examples: #9 Modules Example (pt 2)'>Mate examples: #9 Modules Example (pt 2)</a> <small>This is the ninth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/05/mate-examples-2-databinding-and-eventhandlers/' rel='bookmark' title='Permanent Link: Mate examples: #2 Databinding and EventHandlers'>Mate examples: #2 Databinding and EventHandlers</a> <small>This is the second of a series of gradually more...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>This blog post is related to <a href="http://www.flexstuff.co.uk/2009/08/05/my-lfpug-presentation-about-mate/" target="_blank">My LFPUG Presentation about Mate</a> blog post.</p>
<p>If you haven&#8217;t done it yet you should have a look first at our previous examples: <a href="http://www.flexstuff.co.uk/2009/08/05/mate-examples-1-a-very-basic-injectors-example/" target="_blank">#1,</a> <a href="http://www.flexstuff.co.uk/2009/08/05/mate-examples-2-databinding-and-eventhandlers/" target="_blank">#2</a>, <a href="http://www.flexstuff.co.uk/2009/08/06/mate-examples-3-multiple-counters/" target="_blank">#3</a>, <a href="http://www.flexstuff.co.uk/?p=521" target="_blank">#4</a>, <a href="http://www.flexstuff.co.uk/2009/08/06/mate-examples-5-localeventmap/" target="_blank">#5</a>, <a href="http://www.flexstuff.co.uk/2009/08/09/mate-examples-6-reset-countdown-pt-1/" target="_blank">#6</a>, <a href="http://www.flexstuff.co.uk/2009/08/09/mate-examples-7-reset-countdown-pt-2/" target="_blank">#7</a>, <a href="http://www.flexstuff.co.uk/2009/08/18/mate-examples-8-modules-example-pt-1/" target="_blank">#8</a>, and <a href="http://www.flexstuff.co.uk/2009/08/23/mate-examples-9-modules-example-pt-2/" target="_blank">#9</a>.</p>
<p>Today we&#8217;re going to put aside our (I know: boooring) <em>counters</em>. We will come back to them in a couple of posts for <em>the great finale: Mate and versioned applications</em>.<br />
But for now I wanted to illustrate a really good practice with <em>Mate</em> (and in general): the <em>Presentation Model pattern</em>. For those who want to know more about the <em>Presentation Model</em>, have a look at <a href="http://blogs.adobe.com/paulw/archives/2007/10/presentation_pa_3.html">Paul Williams great article</a>. Basically, the idea is to keep the view <em>as simple as possible</em>, separating all the <em>logic</em> in a <em>dedicated class</em>. That way, <em>Mate</em> communicates with the <em>presentation model class</em> and not directly with the <em>view</em>, the latter being updated via <em>data binding</em>. In this configuration, the <em>view&#8217;s</em> only concern is its own elements and its only dependency is its <em>model</em>.</p>
<p>Let&#8217;s have a look at our very simple demo (source is available by right-clicking on the demo after launching it):</p>
<div class="wp-caption aligncenter" style="width: 360px"><a class="lightview" title="#10 Presentation Model :: Right-click to view the source. :: width: 1200, height: 768" href="http://flexstuff.co.uk/wp-content/uploads/examples/mate_lfpug/_Demo10%20-%20Presentation%20Model/Demo.swf"><img src="http://flexstuff.co.uk/wp-content/uploads/examples/mate_lfpug/_Demo10%20-%20Presentation%20Model/Mate_example10.png" alt="Mate example" width="350" height="250" /></a><p class="wp-caption-text">#10 Presentation Model (click to Launch)</p></div>
<p><span id="more-556"></span>So what do we have here (apart from the opportunity to learn a bit of French)? Two visually different <em>panels</em>, each with two <em>buttons</em>, each <em>button</em> triggering an <em>alert</em> with a different <em>message</em>. The structure is dead simple: the two different panels are instantiated in the now usual <strong>MainView</strong>:</p>
<p><cite><br />
<h3>Demo #10: src/views/MainView.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Canvas xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;656&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;314&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns<span style="color: #000066; font-weight: bold;">:</span>views=<span style="color: #990000;">&quot;views.*&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>views<span style="color: #000066; font-weight: bold;">:</span>FirstPanel verticalCenter=<span style="color: #990000;">&quot;0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">left</span>=<span style="color: #990000;">&quot;25&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;298&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>views<span style="color: #000066; font-weight: bold;">:</span>SecondPanel verticalCenter=<span style="color: #990000;">&quot;0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">right</span>=<span style="color: #990000;">&quot;25&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Canvas<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p><strong>FirstPanel</strong> and <strong>SecondPanel</strong> are pretty similar, the main differences being various &#8220;cosmetic&#8221; <em>properties</em>:</p>
<p><cite><br />
<h3>Demo #10: src/views/FirstPanel.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;298&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;164&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layout=<span style="color: #990000;">&quot;absolute&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title=<span style="color: #990000;">&quot;First Panel&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>presentationmodel<span style="color: #000066; font-weight: bold;">.</span>IPresentationModel<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> pm <span style="color: #000066; font-weight: bold;">:</span> IPresentationModel<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;button1&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;Button One&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">left</span>=<span style="color: #990000;">&quot;30&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;verticalCenter=<span style="color: #990000;">&quot;0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;pm.button1_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;button2&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;Button Two&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">right</span>=<span style="color: #990000;">&quot;30&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;verticalCenter=<span style="color: #990000;">&quot;0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;pm.button2_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p><cite><br />
<h3>Demo #10: src/views/SecondPanel.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;246&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;232&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layout=<span style="color: #990000;">&quot;absolute&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title=<span style="color: #990000;">&quot;Deuxieme Panel&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; borderStyle=<span style="color: #990000;">&quot;inset&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">backgroundColor</span>=<span style="color: #990000;">&quot;#A5C5ED&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>presentationmodel<span style="color: #000066; font-weight: bold;">.</span>IPresentationModel<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> pm <span style="color: #000066; font-weight: bold;">:</span> IPresentationModel<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;button1&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;Bouton Un&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;horizontalCenter=<span style="color: #990000;">&quot;0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">top</span>=<span style="color: #990000;">&quot;20&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;emphasized=<span style="color: #990000;">&quot;true&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cornerRadius=<span style="color: #990000;">&quot;0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;pm.button1_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;button2&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;Bouton Deux&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;horizontalCenter=<span style="color: #990000;">&quot;0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">bottom</span>=<span style="color: #990000;">&quot;20&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cornerRadius=<span style="color: #990000;">&quot;0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fillAlphas=<span style="color: #990000;">&quot;[1.0, 1.0]&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fillColors=<span style="color: #990000;">&quot;[#FF0000, #FF0000]&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">color</span>=<span style="color: #990000;">&quot;#FFFFFF&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;pm.button2_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>One important thing to notice though: they both share a same <strong>pm</strong> variable referring to an <em>Interface</em>, <strong>IPresentationModel</strong>. Also, the 2 <em>buttons</em> call 2 <em>methods</em> within this <em>interface</em>: <strong>button1_clickHandler</strong> and <strong>button2_clickHandler</strong>.</p>
<p><cite><br />
<h3>Demo #10: src/views/presentationmodel/IPresentationModel.as</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span> views<span style="color: #000066; font-weight: bold;">.</span>presentationmodel<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> interface IPresentationModel<br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339966; font-weight: bold;">function</span> button1_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339966; font-weight: bold;">function</span> button2_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now, there are two <em>classes</em> in the <strong>views/presentationmodel</strong> package: <strong>PresentationModel1</strong> and <strong>PresentationModel2</strong>. Once again, those two are pretty similar, the only differences being the different messages thrown by the <strong>Alerts</strong>:</p>
<p><cite><br />
<h3>Demo #10: src/views/presentationmodel/PresentationModel1.as</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span> views<span style="color: #000066; font-weight: bold;">.</span>presentationmodel<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">EventDispatcher</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>controls<span style="color: #000066; font-weight: bold;">.</span>Alert<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> PresentationModel1 <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">EventDispatcher</span> implements IPresentationModel<br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> button1_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Alert<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">show</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Button1 Clicked&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> button2_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Alert<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">show</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Button2 Clicked&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p><cite><br />
<h3>Demo #10: src/views/presentationmodel/PresentationModel2.as</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span> views<span style="color: #000066; font-weight: bold;">.</span>presentationmodel<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">EventDispatcher</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>controls<span style="color: #000066; font-weight: bold;">.</span>Alert<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> PresentationModel2 <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">EventDispatcher</span> implements IPresentationModel<br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> button1_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Alert<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">show</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Oh! I do not like this.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> button2_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Alert<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">show</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Please don't do that.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>And now, the glue, as usual:</p>
<p><cite><br />
<h3>Demo #10: src/maps/MainEventMap.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventMap xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns<span style="color: #000066; font-weight: bold;">:</span>mate=<span style="color: #990000;">&quot;http://mate.asfusion.com/&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>SecondPanel<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>presentationmodel<span style="color: #000066; font-weight: bold;">.</span>PresentationModel2<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>presentationmodel<span style="color: #000066; font-weight: bold;">.</span>PresentationModel1<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>FirstPanel<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Debugger <span style="color: #004993;">level</span>=<span style="color: #990000;">&quot;{Debugger.ALL}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors <span style="color: #004993;">target</span>=<span style="color: #990000;">&quot;{FirstPanel}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>ObjectBuilder generator=<span style="color: #990000;">&quot;{PresentationModel1}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>PropertyInjector <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;{lastReturn}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;targetKey=<span style="color: #990000;">&quot;pm&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors <span style="color: #004993;">target</span>=<span style="color: #990000;">&quot;{SecondPanel}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>ObjectBuilder generator=<span style="color: #990000;">&quot;{PresentationModel2}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>PropertyInjector <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;{lastReturn}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;targetKey=<span style="color: #990000;">&quot;pm&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventMap<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>The <strong>MainEventMap</strong> maps each <em>PresentationModel</em> to its related <em>view</em> and the job is done! The beauty of it is that you can swap <em>presentation models</em> and <em>views</em> as easily as this:</p>
<p><cite><br />
<h3>Demo #10: src/maps/MainEventMap.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventMap xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns<span style="color: #000066; font-weight: bold;">:</span>mate=<span style="color: #990000;">&quot;http://mate.asfusion.com/&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>SecondPanel<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>presentationmodel<span style="color: #000066; font-weight: bold;">.</span>PresentationModel2<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>presentationmodel<span style="color: #000066; font-weight: bold;">.</span>PresentationModel1<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>FirstPanel<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Debugger <span style="color: #004993;">level</span>=<span style="color: #990000;">&quot;{Debugger.ALL}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors <span style="color: #004993;">target</span>=<span style="color: #990000;">&quot;{FirstPanel}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>ObjectBuilder generator=<span style="color: #990000;">&quot;{PresentationModel2}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>PropertyInjector <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;{lastReturn}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;targetKey=<span style="color: #990000;">&quot;pm&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors <span style="color: #004993;">target</span>=<span style="color: #990000;">&quot;{SecondPanel}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>ObjectBuilder generator=<span style="color: #990000;">&quot;{PresentationModel1}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>PropertyInjector <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;{lastReturn}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;targetKey=<span style="color: #990000;">&quot;pm&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventMap<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>Neat, isn&#8217;t it? You can as easily imagine using <em>data binding</em> to dynamically change <em>view&#8217;s properties</em> (<em>visible, enabled, label</em>, whatnot) with some <em>bindable</em> variables in the presentation model.</p>
<p>Here we go. Next, my new favourite one: a port of <em>PureMVC&#8217;s mediator pattern</em> which is one of the best ways to use <em>Mate</em> with the new <em>Flex 4 component architecture</em>.</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.flexstuff.co.uk%2F2009%2F08%2F25%2Fmate-examples-10-presentation-model%2F';
  addthis_title  = 'Mate+examples%3A+%2310+Presentation+Model';
  addthis_pub    = 'gillesguillemin';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>


<p>Related posts:<ol><li><a href='http://www.flexstuff.co.uk/2009/10/13/mate-examples-11-mediator-or-passive-view/' rel='bookmark' title='Permanent Link: Mate examples: #11 Mediator (or Passive View)'>Mate examples: #11 Mediator (or Passive View)</a> <small>This is the eleventh of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/23/mate-examples-9-modules-example-pt-2/' rel='bookmark' title='Permanent Link: Mate examples: #9 Modules Example (pt 2)'>Mate examples: #9 Modules Example (pt 2)</a> <small>This is the ninth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/05/mate-examples-2-databinding-and-eventhandlers/' rel='bookmark' title='Permanent Link: Mate examples: #2 Databinding and EventHandlers'>Mate examples: #2 Databinding and EventHandlers</a> <small>This is the second of a series of gradually more...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.flexstuff.co.uk/2009/08/25/mate-examples-10-presentation-model/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mate examples: #9 Modules Example (pt 2)</title>
		<link>http://www.flexstuff.co.uk/2009/08/23/mate-examples-9-modules-example-pt-2/</link>
		<comments>http://www.flexstuff.co.uk/2009/08/23/mate-examples-9-modules-example-pt-2/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 18:05:46 +0000</pubDate>
		<dc:creator>gillesguillemin</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Mate Framework]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[London Flash Platform User Group]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[mxml]]></category>

		<guid isPermaLink="false">http://www.flexstuff.co.uk/?p=554</guid>
		<description><![CDATA[This is the ninth of a series of gradually more complex examples on how to use Mate. Here we see how to use Mate with Flex Modules.


Related posts:<ol><li><a href='http://www.flexstuff.co.uk/2009/08/18/mate-examples-8-modules-example-pt-1/' rel='bookmark' title='Permanent Link: Mate examples: #8 Modules Example (pt 1)'>Mate examples: #8 Modules Example (pt 1)</a> <small>This is the eigth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/06/mate-examples-5-localeventmap/' rel='bookmark' title='Permanent Link: Mate examples: #5 LocalEventMap'>Mate examples: #5 LocalEventMap</a> <small>This is the fifth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/06/mate-examples-3-multiple-counters/' rel='bookmark' title='Permanent Link: Mate examples: #3 Multiple Counters'>Mate examples: #3 Multiple Counters</a> <small>This is the third of a series of gradually more...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>This blog post is related to <a href="http://www.flexstuff.co.uk/2009/08/05/my-lfpug-presentation-about-mate/" target="_blank">My LFPUG Presentation about Mate</a> blog post.</p>
<p>This is the ninth of a series of gradually more complex examples on how to use <em>Mate</em>. If you haven&#8217;t done it yet you should have a look first at our previous examples: <a href="http://www.flexstuff.co.uk/2009/08/05/mate-examples-1-a-very-basic-injectors-example/" target="_blank">#1,</a> <a href="http://www.flexstuff.co.uk/2009/08/05/mate-examples-2-databinding-and-eventhandlers/" target="_blank">#2</a>, <a href="http://www.flexstuff.co.uk/2009/08/06/mate-examples-3-multiple-counters/" target="_blank">#3</a>, <a href="http://www.flexstuff.co.uk/?p=521" target="_blank">#4</a>, <a href="http://www.flexstuff.co.uk/2009/08/06/mate-examples-5-localeventmap/" target="_blank">#5</a>, <a href="http://www.flexstuff.co.uk/2009/08/09/mate-examples-6-reset-countdown-pt-1/" target="_blank">#6</a>, <a href="http://www.flexstuff.co.uk/2009/08/09/mate-examples-7-reset-countdown-pt-2/" target="_blank">#7</a>, and <a href="http://www.flexstuff.co.uk/2009/08/18/mate-examples-8-modules-example-pt-1/" target="_blank">#8</a>.</p>
<p>By now, you should reasonably be up to speed so I&#8217;m going to speed up as well and throw examples more regularly but with less explanations (it takes some time that I don&#8217;t exactly have those days). If you really don&#8217;t get it though don&#8217;t hesitate to ask for further explanations in the comments.</p>
<p>In <a href="http://www.flexstuff.co.uk/2009/08/06/mate-examples-8-modules-example-pt-1/#more-552">the previous example</a>, we started to see how to use Mate with Modules but the main application was still keeping references to the module&#8217;s classes. </p>
<p>This example push decoupling a bit further (source is available by right-clicking on the demo after launching it):</p>
<div class="wp-caption aligncenter" style="width: 360px"><a class="lightview" title="#9 Modules Example (pt 2) :: Right-click to view the source. :: width: 1024, height: 768" href="http://flexstuff.co.uk/wp-content/uploads/examples/mate_lfpug/_Demo09%20-%20Modules%20example%20(2)/Demo.swf"><img src="http://flexstuff.co.uk/wp-content/uploads/examples/mate_lfpug/_Demo09%20-%20Modules%20example%20(2)/Mate_example7.png" alt="Mate example" width="350" height="250" /></a><p class="wp-caption-text">#9 Modules Example (pt 2) (click to Launch)</p></div>
<p><span id="more-554"></span>As you can see, MainEventMap doesn&#8217;t hold anymore any reference to the module&#8217;s classes:</p>
<p><cite><br />
<h3>Demo #9: src/maps/MainEventMap.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventMap xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns<span style="color: #000066; font-weight: bold;">:</span>mate=<span style="color: #990000;">&quot;http://mate.asfusion.com/&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CountdownEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> managers<span style="color: #000066; font-weight: bold;">.</span>CountdownManager<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>events<span style="color: #000066; font-weight: bold;">.</span>FlexEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>MainView<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> managers<span style="color: #000066; font-weight: bold;">.</span>CounterManager<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CounterEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Debugger <span style="color: #004993;">level</span>=<span style="color: #990000;">&quot;{Debugger.ALL}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;{FlexEvent.APPLICATION_COMPLETE}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>ObjectBuilder generator=<span style="color: #990000;">&quot;{CountdownManager}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;{CounterEvent.INCREASE_GLOBAL}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>MethodInvoker generator=<span style="color: #990000;">&quot;{CounterManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;increaseGlobal&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;{CounterEvent.DECREASE_GLOBAL}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>MethodInvoker generator=<span style="color: #990000;">&quot;{CounterManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;decreaseGlobal&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;{CounterEvent.RESET}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>MethodInvoker generator=<span style="color: #990000;">&quot;{CounterManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;reset&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;{CountdownEvent.START_COUNTDOWN}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>MethodInvoker generator=<span style="color: #990000;">&quot;{CountdownManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;startCountdown&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;{CountdownEvent.STOP_COUNTDOWN}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>MethodInvoker generator=<span style="color: #990000;">&quot;{CountdownManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;stopCountdown&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors <span style="color: #004993;">target</span>=<span style="color: #990000;">&quot;{MainView}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>PropertyInjector <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;{CounterManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sourceKey=<span style="color: #990000;">&quot;globalAmount&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;targetKey=<span style="color: #990000;">&quot;globalAmount&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors <span style="color: #004993;">target</span>=<span style="color: #990000;">&quot;{MainView}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; debug=<span style="color: #990000;">&quot;true&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>PropertyInjector <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;{CountdownManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sourceKey=<span style="color: #990000;">&quot;isCountdownRunning&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;targetKey=<span style="color: #990000;">&quot;isCountdownRunning&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>ListenerInjector eventType=<span style="color: #990000;">&quot;{CountdownEvent.COUNTDOWN}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;updateTitle&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventMap<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>Instead, the module Counter.mxml now instanciates 2 different EventMaps: ModuleEventMap and SubEventMap (we saw in <a href="http://www.flexstuff.co.uk/2009/08/06/mate-examples-5-localeventmap/">Example #5 LocalEventMap</a> how to use LocalEventMap):</p>
<p><cite><br />
<h3>Demo #9: src/modules/Counter.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Module xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;layout=<span style="color: #990000;">&quot;absolute&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;264&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;380&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns<span style="color: #000066; font-weight: bold;">:</span>modules=<span style="color: #990000;">&quot;modules.*&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns<span style="color: #000066; font-weight: bold;">:</span>views=<span style="color: #990000;">&quot;modules.views.*&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns<span style="color: #000066; font-weight: bold;">:</span>maps=<span style="color: #990000;">&quot;modules.maps.*&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CounterEvent<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> globalAmount <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> subTotal <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> amount <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _counterTitle <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;Counter Title&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> counterTitle<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> _counterTitle<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> counterTitle<span style="color: #000000;">&#40;</span> v <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _counterTitle = v<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> increaseSubTotal<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> CounterEvent <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">++</span>subTotal<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> decreaseSubTotal<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> CounterEvent <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">--</span>subTotal<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">reset</span><span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> CounterEvent <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; subTotal = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>maps<span style="color: #000066; font-weight: bold;">:</span>ModuleEventMap <span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>maps<span style="color: #000066; font-weight: bold;">:</span>SubEventMap dispatcher=<span style="color: #990000;">&quot;{this}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;264&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;380&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title=<span style="color: #990000;">&quot;{counterTitle}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layout=<span style="color: #990000;">&quot;absolute&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;27&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;10&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Global Amount:&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;121&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;10&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{globalAmount}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>views<span style="color: #000066; font-weight: bold;">:</span>SubCounter <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;64&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; horizontalCenter=<span style="color: #990000;">&quot;0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; borderStyle=<span style="color: #990000;">&quot;inset&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>views<span style="color: #000066; font-weight: bold;">:</span>SubCounter<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>views<span style="color: #000066; font-weight: bold;">:</span>SubCounter <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;208&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; horizontalCenter=<span style="color: #990000;">&quot;0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; borderStyle=<span style="color: #990000;">&quot;inset&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>views<span style="color: #000066; font-weight: bold;">:</span>SubCounter<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;63&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;35&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Subtotal:&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;124&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;35&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{subTotal}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Module<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>And here is ModuleEventMap which deals with global events thrown by the main application:</p>
<p><cite><br />
<h3>Demo #9: src/modules/maps/ModuleEventMap.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventMap xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns<span style="color: #000066; font-weight: bold;">:</span>mate=<span style="color: #990000;">&quot;http://mate.asfusion.com/&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CounterEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> modules<span style="color: #000066; font-weight: bold;">.</span>views<span style="color: #000066; font-weight: bold;">.</span>SubCounter<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> managers<span style="color: #000066; font-weight: bold;">.</span>CounterManager<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> modules<span style="color: #000066; font-weight: bold;">.</span>Counter<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Debugger <span style="color: #004993;">level</span>=<span style="color: #990000;">&quot;{Debugger.ALL}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors <span style="color: #004993;">target</span>=<span style="color: #990000;">&quot;{Counter}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>PropertyInjector <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;{CounterManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sourceKey=<span style="color: #990000;">&quot;globalAmount&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;targetKey=<span style="color: #990000;">&quot;globalAmount&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors targets=<span style="color: #990000;">&quot;{[Counter, SubCounter]}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>ListenerInjector eventType=<span style="color: #990000;">&quot;{CounterEvent.RESET}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;reset&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventMap<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>And SubEventMap which deals with local ones:</p>
<p><cite><br />
<h3>Demo #9: src/modules/maps/SubEventMap.mxml </h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>LocalEventMap xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns<span style="color: #000066; font-weight: bold;">:</span>mate=<span style="color: #990000;">&quot;http://mate.asfusion.com/&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> modules<span style="color: #000066; font-weight: bold;">.</span>Counter<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CounterEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> modules<span style="color: #000066; font-weight: bold;">.</span>views<span style="color: #000066; font-weight: bold;">.</span>SubCounter<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Debugger <span style="color: #004993;">level</span>=<span style="color: #990000;">&quot;{Debugger.ALL}&quot;</span> <span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors targets=<span style="color: #990000;">&quot;{[Counter, SubCounter]}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>ListenerInjector eventType=<span style="color: #990000;">&quot;{CounterEvent.INCREASE_SUB_TOTAL}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;increaseSubTotal&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>ListenerInjector eventType=<span style="color: #990000;">&quot;{CounterEvent.DECREASE_SUB_TOTAL}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;decreaseSubTotal&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>LocalEventMap<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>In the example #12 we will see how to use Mate with versioned applications but first we will have a look at two different approaches of the Presentation model design pattern.</p>
<p>Next: <a href="http://www.flexstuff.co.uk/2009/08/06/mate-examples-10-presentation-model/">#10 Presentation Model</a>.</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.flexstuff.co.uk%2F2009%2F08%2F23%2Fmate-examples-9-modules-example-pt-2%2F';
  addthis_title  = 'Mate+examples%3A+%239+Modules+Example+%28pt+2%29';
  addthis_pub    = 'gillesguillemin';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>


<p>Related posts:<ol><li><a href='http://www.flexstuff.co.uk/2009/08/18/mate-examples-8-modules-example-pt-1/' rel='bookmark' title='Permanent Link: Mate examples: #8 Modules Example (pt 1)'>Mate examples: #8 Modules Example (pt 1)</a> <small>This is the eigth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/06/mate-examples-5-localeventmap/' rel='bookmark' title='Permanent Link: Mate examples: #5 LocalEventMap'>Mate examples: #5 LocalEventMap</a> <small>This is the fifth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/06/mate-examples-3-multiple-counters/' rel='bookmark' title='Permanent Link: Mate examples: #3 Multiple Counters'>Mate examples: #3 Multiple Counters</a> <small>This is the third of a series of gradually more...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.flexstuff.co.uk/2009/08/23/mate-examples-9-modules-example-pt-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mate examples: #8 Modules Example (pt 1)</title>
		<link>http://www.flexstuff.co.uk/2009/08/18/mate-examples-8-modules-example-pt-1/</link>
		<comments>http://www.flexstuff.co.uk/2009/08/18/mate-examples-8-modules-example-pt-1/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 18:04:13 +0000</pubDate>
		<dc:creator>gillesguillemin</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Mate Framework]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[London Flash Platform User Group]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[mxml]]></category>

		<guid isPermaLink="false">http://www.flexstuff.co.uk/?p=552</guid>
		<description><![CDATA[This is the eigth of a series of gradually more complex examples on how to use Mate. Here we see how to use Mate with Flex Modules.


Related posts:<ol><li><a href='http://www.flexstuff.co.uk/2009/08/23/mate-examples-9-modules-example-pt-2/' rel='bookmark' title='Permanent Link: Mate examples: #9 Modules Example (pt 2)'>Mate examples: #9 Modules Example (pt 2)</a> <small>This is the ninth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/09/mate-examples-6-reset-countdown-pt-1/' rel='bookmark' title='Permanent Link: Mate examples: #6 Reset Countdown (pt 1)'>Mate examples: #6 Reset Countdown (pt 1)</a> <small>This blog post is related to My LFPUG Presentation about...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/06/mate-examples-5-localeventmap/' rel='bookmark' title='Permanent Link: Mate examples: #5 LocalEventMap'>Mate examples: #5 LocalEventMap</a> <small>This is the fifth of a series of gradually more...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>This blog post is related to <a href="http://www.flexstuff.co.uk/2009/08/05/my-lfpug-presentation-about-mate/" target="_blank">My LFPUG Presentation about Mate</a> blog post.</p>
<p>This is the eigth of a series of gradually more complex examples on how to use <em>Mate</em>. If you haven&#8217;t done it yet you should have a look first at our previous examples: <a href="http://www.flexstuff.co.uk/2009/08/05/mate-examples-1-a-very-basic-injectors-example/" target="_blank">#1,</a> <a href="http://www.flexstuff.co.uk/2009/08/05/mate-examples-2-databinding-and-eventhandlers/" target="_blank">#2</a>, <a href="http://www.flexstuff.co.uk/2009/08/06/mate-examples-3-multiple-counters/" target="_blank">#3</a>, <a href="http://www.flexstuff.co.uk/?p=521" target="_blank">#4</a>, <a href="http://www.flexstuff.co.uk/2009/08/06/mate-examples-5-localeventmap/" target="_blank">#5</a>, <a href="http://www.flexstuff.co.uk/2009/08/09/mate-examples-6-reset-countdown-pt-1/" target="_blank">#6</a>, and <a href="http://www.flexstuff.co.uk/2009/08/09/mate-examples-7-reset-countdown-pt-2/" target="_blank">#7</a>.</p>
<p>In our two previous examples, we saw how easy it was to handle communication between the <em>application</em> and its <em>subcomponents</em>, without mix-up between <em>events</em> intended to be listened by the whole <em>application</em> and <em>events</em> required only at the <em>subcomponent</em> level. But how would <em>Mate</em> hold up with with even looser <em>subcomponents</em>, of the kind that are loaded <em>on demand</em> and are not a concrete part of our main <em>application</em>, namely <em>Modules</em>?</p>
<p>I&#8217;m sure you know already it holds up pretty well, but let&#8217;s see how it does that:</p>
<div class="wp-caption aligncenter" style="width: 360px"><a class="lightview" title="#8 Modules Example (pt 1) :: Right-click to view the source. :: width: 1024, height: 768" href="http://flexstuff.co.uk/wp-content/uploads/examples/mate_lfpug/_Demo08%20-%20Modules%20example%20(1)/Demo.swf"><img src="http://flexstuff.co.uk/wp-content/uploads/examples/mate_lfpug/_Demo08%20-%20Modules%20example%20(1)/Mate_example7.png" alt="Mate example" width="350" height="250" /></a><p class="wp-caption-text">#8 Modules Example (pt 1) (click to Launch)</p></div>
<p><span id="more-552"></span>The great thing here is that we didn&#8217;t change much between this example and our previous <a href="http://www.flexstuff.co.uk/2009/08/06/mate-examples-7-reset-countdown-pt-2/">Reset Countdown</a>. Basically, aside moving <strong>Counter.mxml</strong> and <strong>SubCounter.mxml</strong> into a new <strong>modules</strong> <em>package</em> and changing <strong>Counter.mxml</strong> from a <em>Panel</em> into a <em>Module</em>, that&#8217;s about it:</p>
<p><cite><br />
<h3>Demo #8: src/modules/Counter.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Module xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;layout=<span style="color: #990000;">&quot;absolute&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;264&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;380&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns<span style="color: #000066; font-weight: bold;">:</span>maps=<span style="color: #990000;">&quot;maps.*&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns<span style="color: #000066; font-weight: bold;">:</span>modules=<span style="color: #990000;">&quot;modules.*&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CounterEvent<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> globalAmount <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> subTotal <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> amount <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _counterTitle <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;Counter Title&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> counterTitle<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> _counterTitle<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> counterTitle<span style="color: #000000;">&#40;</span> v <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _counterTitle = v<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> increaseSubTotal<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> CounterEvent <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">++</span>subTotal<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> decreaseSubTotal<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> CounterEvent <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">--</span>subTotal<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">reset</span><span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> CounterEvent <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; subTotal = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>maps<span style="color: #000066; font-weight: bold;">:</span>SubEventMap dispatcher=<span style="color: #990000;">&quot;{this}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;264&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;380&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title=<span style="color: #990000;">&quot;{counterTitle}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layout=<span style="color: #990000;">&quot;absolute&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;27&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;10&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Global Amount:&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;121&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;10&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{globalAmount}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>modules<span style="color: #000066; font-weight: bold;">:</span>SubCounter <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;64&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; horizontalCenter=<span style="color: #990000;">&quot;0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; borderStyle=<span style="color: #990000;">&quot;inset&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>modules<span style="color: #000066; font-weight: bold;">:</span>SubCounter<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>modules<span style="color: #000066; font-weight: bold;">:</span>SubCounter <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;208&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; horizontalCenter=<span style="color: #990000;">&quot;0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; borderStyle=<span style="color: #990000;">&quot;inset&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>modules<span style="color: #000066; font-weight: bold;">:</span>SubCounter<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;63&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;35&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Subtotal:&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;124&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;35&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{subTotal}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Module<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>Don&#8217;t forget to declare <strong>Counter.mxml</strong> as a <em>Flex Module</em> in your project&#8217;s properties and of course update all your references to <strong>Counter</strong> and <strong>SubCounter</strong> from <strong>views</strong> to <strong>modules</strong> (i.e. <strong>import view.Counter</strong> => <strong>import modules.Counter</strong>).<br />
And then, all you need to do is to change your <strong>addCounterButton_clickHandler</strong> method in <strong>MainView.mxml</strong> from a simple <em>Class</em> instantiation into a <em>ModuleLoader</em> loader: </p>
<p><cite><br />
<h3>Demo #8: src/views/MainView.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;860&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;600&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title=<span style="color: #990000;">&quot;{mainTitle}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layout=<span style="color: #990000;">&quot;absolute&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns<span style="color: #000066; font-weight: bold;">:</span>views=<span style="color: #990000;">&quot;views.*&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>modules<span style="color: #000066; font-weight: bold;">.</span>ModuleLoader<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CountdownEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CounterEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> globalAmount <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> isCountdownRunning <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Boolean</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> numCounters <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> mainTitle <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;MainView&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> buttonIncrease_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> CounterEvent<span style="color: #000000;">&#40;</span> CounterEvent<span style="color: #000066; font-weight: bold;">.</span>INCREASE_GLOBAL <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> buttonDecrease_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> CounterEvent<span style="color: #000000;">&#40;</span> CounterEvent<span style="color: #000066; font-weight: bold;">.</span>DECREASE_GLOBAL <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> addCounterButton_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> moduleLoader <span style="color: #000066; font-weight: bold;">:</span> ModuleLoader = <span style="color: #0033ff; font-weight: bold;">new</span> ModuleLoader<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; moduleLoader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">url</span> = <span style="color: #990000;">&quot;modules/Counter.swf&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mainTile<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span> moduleLoader <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">++</span>numCounters<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> deleteCounterButton_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> displayObject <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">DisplayObject</span> = mainTile<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildAt</span><span style="color: #000000;">&#40;</span>mainTile<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">numChildren</span> <span style="color: #000066; font-weight: bold;">-</span> 1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ModuleLoader<span style="color: #000000;">&#40;</span> displayObject <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>unloadModule<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mainTile<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span> displayObject <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">--</span>numCounters<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> updateTitle<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> CountdownEvent <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mainTitle = <span style="color: #990000;">&quot;MainView (&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> event<span style="color: #000066; font-weight: bold;">.</span>countdown <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;)&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> countdownButton_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> isCountdownRunning <span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; countdownButton<span style="color: #000066; font-weight: bold;">.</span>label = <span style="color: #990000;">&quot;START COUNTDOWN&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> CountdownEvent<span style="color: #000000;">&#40;</span> CountdownEvent<span style="color: #000066; font-weight: bold;">.</span>STOP_COUNTDOWN <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; countdownButton<span style="color: #000066; font-weight: bold;">.</span>label = <span style="color: #990000;">&quot;STOP COUNTDOWN&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> CountdownEvent<span style="color: #000000;">&#40;</span> CountdownEvent<span style="color: #000066; font-weight: bold;">.</span>START_COUNTDOWN <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Global Amount:&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;28&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;16&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{globalAmount}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;124&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;16&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Tile id=<span style="color: #990000;">&quot;mainTile&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">left</span>=<span style="color: #990000;">&quot;10&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">right</span>=<span style="color: #990000;">&quot;10&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">top</span>=<span style="color: #990000;">&quot;82&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">bottom</span>=<span style="color: #990000;">&quot;10&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Tile<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;buttonIncrease&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;68&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;34&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;+&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;buttonIncrease_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;buttonDecrease&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;140&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;34&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;-&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;buttonDecrease_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;addCounterButton&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;614&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;31&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;Add Counter&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;addCounterButton_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;countdownButton&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;366&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;31&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;STOP COUNTDOWN&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;countdownButton_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;deleteCounterButton&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;716&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;31&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;Delete Counter&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">enabled</span>=<span style="color: #990000;">&quot;{numCounters &gt; 0}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;deleteCounterButton_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>And yet our application keeps behaving as it always did. Isn&#8217;t that great? It is, it is, but the example is still not perfect: the <em>views</em> are now separated from the <em>main application</em>, but the <em>logic</em> is still part of it and there are <em>references</em> to the <em>modules&#8217; classes</em> all around in the main application. We can clearly <em>decouple</em> a bit further and we&#8217;ll see how in our next part: <a href="http://www.flexstuff.co.uk/2009/08/06/mate-examples-9-modules-example-pt-2/">#9 Modules Example (pt 2)</a></p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.flexstuff.co.uk%2F2009%2F08%2F18%2Fmate-examples-8-modules-example-pt-1%2F';
  addthis_title  = 'Mate+examples%3A+%238+Modules+Example+%28pt+1%29';
  addthis_pub    = 'gillesguillemin';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>


<p>Related posts:<ol><li><a href='http://www.flexstuff.co.uk/2009/08/23/mate-examples-9-modules-example-pt-2/' rel='bookmark' title='Permanent Link: Mate examples: #9 Modules Example (pt 2)'>Mate examples: #9 Modules Example (pt 2)</a> <small>This is the ninth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/09/mate-examples-6-reset-countdown-pt-1/' rel='bookmark' title='Permanent Link: Mate examples: #6 Reset Countdown (pt 1)'>Mate examples: #6 Reset Countdown (pt 1)</a> <small>This blog post is related to My LFPUG Presentation about...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/06/mate-examples-5-localeventmap/' rel='bookmark' title='Permanent Link: Mate examples: #5 LocalEventMap'>Mate examples: #5 LocalEventMap</a> <small>This is the fifth of a series of gradually more...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.flexstuff.co.uk/2009/08/18/mate-examples-8-modules-example-pt-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Mate examples: #7 Reset Countdown (pt 2)</title>
		<link>http://www.flexstuff.co.uk/2009/08/09/mate-examples-7-reset-countdown-pt-2/</link>
		<comments>http://www.flexstuff.co.uk/2009/08/09/mate-examples-7-reset-countdown-pt-2/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 18:02:37 +0000</pubDate>
		<dc:creator>gillesguillemin</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Mate Framework]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[London Flash Platform User Group]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[mxml]]></category>

		<guid isPermaLink="false">http://www.flexstuff.co.uk/?p=550</guid>
		<description><![CDATA[This is the seventh of a series of gradually more complex examples on how to use Mate. Here we illustrate interaction between non visual components and the rest of the application.


Related posts:<ol><li><a href='http://www.flexstuff.co.uk/2009/08/09/mate-examples-6-reset-countdown-pt-1/' rel='bookmark' title='Permanent Link: Mate examples: #6 Reset Countdown (pt 1)'>Mate examples: #6 Reset Countdown (pt 1)</a> <small>This blog post is related to My LFPUG Presentation about...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/18/mate-examples-8-modules-example-pt-1/' rel='bookmark' title='Permanent Link: Mate examples: #8 Modules Example (pt 1)'>Mate examples: #8 Modules Example (pt 1)</a> <small>This is the eigth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/23/mate-examples-9-modules-example-pt-2/' rel='bookmark' title='Permanent Link: Mate examples: #9 Modules Example (pt 2)'>Mate examples: #9 Modules Example (pt 2)</a> <small>This is the ninth of a series of gradually more...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>This blog post is related to <a href="http://www.flexstuff.co.uk/2009/08/05/my-lfpug-presentation-about-mate/" target="_blank">My LFPUG Presentation about Mate</a> blog post.</p>
<p>This is the seventh of a series of gradually more complex examples on how to use <em>Mate</em>. If you haven&#8217;t done it yet you should have a look first at our previous examples: <a href="http://www.flexstuff.co.uk/2009/08/05/mate-examples-1-a-very-basic-injectors-example/" target="_blank">#1,</a> <a href="http://www.flexstuff.co.uk/2009/08/05/mate-examples-2-databinding-and-eventhandlers/" target="_blank">#2</a>, <a href="http://www.flexstuff.co.uk/2009/08/06/mate-examples-3-multiple-counters/" target="_blank">#3</a>, <a href="http://www.flexstuff.co.uk/?p=521" target="_blank">#4</a>, <a href="http://www.flexstuff.co.uk/2009/08/06/mate-examples-5-localeventmap/" target="_blank">#5</a>, and <a href="http://flexstuff.co.uk/548">#6</a>.</p>
<p>In the previous example, we added a <em>reset countdown</em> which sets all the <em>counters</em> to 0 when the <em>countdown</em> is off. But it&#8217;s a bit of a pain this <em>unstoppable countdown</em>. It would be cool to add a <em>start/stop button</em>, wouldn&#8217;t it?</p>
<p>OK, let&#8217;s do it (source is available by right-clicking on the demo after launching it):</p>
<div class="wp-caption aligncenter" style="width: 360px"><a class="lightview" title="#7 Reset Countdown (pt 2) :: Right-click to view the source. :: width: 1024, height: 768" href="http://flexstuff.co.uk/wp-content/uploads/examples/mate_lfpug/_Demo07%20-%20Reset%20countdown%20(2)/Demo.swf"><img src="http://flexstuff.co.uk/wp-content/uploads/examples/mate_lfpug/_Demo07%20-%20Reset%20countdown%20(2)/Mate_example7.png" alt="Mate example" width="350" height="250" /></a><p class="wp-caption-text">#7 Reset Countdown (pt 2) (click to Launch)</p></div>
<p><span id="more-550"></span>So we&#8217;ve first added this <em>start/stop button</em> (yeah, let&#8217;s have a <em>toggle button</em> this time):</p>
<p><cite><br />
<h3>Demo #7: src/views/MainView.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;860&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;600&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title=<span style="color: #990000;">&quot;{mainTitle}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layout=<span style="color: #990000;">&quot;absolute&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns<span style="color: #000066; font-weight: bold;">:</span>views=<span style="color: #990000;">&quot;views.*&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CountdownEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CounterEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> globalAmount <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> isCountdownRunning <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Boolean</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> numCounters <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> mainTitle <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;MainView&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> buttonIncrease_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> CounterEvent<span style="color: #000000;">&#40;</span> CounterEvent<span style="color: #000066; font-weight: bold;">.</span>INCREASE_GLOBAL <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> buttonDecrease_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> CounterEvent<span style="color: #000000;">&#40;</span> CounterEvent<span style="color: #000066; font-weight: bold;">.</span>DECREASE_GLOBAL <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> addCounterButton_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> counter <span style="color: #000066; font-weight: bold;">:</span> Counter = <span style="color: #0033ff; font-weight: bold;">new</span> Counter<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counter<span style="color: #000066; font-weight: bold;">.</span>counterTitle = <span style="color: #990000;">&quot;Counter &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000066; font-weight: bold;">++</span>numCounters<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mainTile<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span> counter <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> deleteCounterButton_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mainTile<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeChildAt</span><span style="color: #000000;">&#40;</span> mainTile<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">numChildren</span> <span style="color: #000066; font-weight: bold;">-</span> 1 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">--</span>numCounters<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> updateTitle<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> CountdownEvent <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mainTitle = <span style="color: #990000;">&quot;MainView (&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> event<span style="color: #000066; font-weight: bold;">.</span>countdown <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;)&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> countdownButton_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> isCountdownRunning <span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; countdownButton<span style="color: #000066; font-weight: bold;">.</span>label = <span style="color: #990000;">&quot;START COUNTDOWN&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> CountdownEvent<span style="color: #000000;">&#40;</span> CountdownEvent<span style="color: #000066; font-weight: bold;">.</span>STOP_COUNTDOWN <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; countdownButton<span style="color: #000066; font-weight: bold;">.</span>label = <span style="color: #990000;">&quot;STOP COUNTDOWN&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> CountdownEvent<span style="color: #000000;">&#40;</span> CountdownEvent<span style="color: #000066; font-weight: bold;">.</span>START_COUNTDOWN <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Global Amount:&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;28&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;16&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{globalAmount}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;124&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;16&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Tile id=<span style="color: #990000;">&quot;mainTile&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">left</span>=<span style="color: #990000;">&quot;10&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">right</span>=<span style="color: #990000;">&quot;10&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">top</span>=<span style="color: #990000;">&quot;82&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">bottom</span>=<span style="color: #990000;">&quot;10&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Tile<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;buttonIncrease&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;68&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;34&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;+&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;buttonIncrease_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;buttonDecrease&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;140&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;34&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;-&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;buttonDecrease_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;addCounterButton&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;614&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;31&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;Add Counter&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;addCounterButton_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;countdownButton&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;366&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;31&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;STOP COUNTDOWN&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;countdownButton_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;deleteCounterButton&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;716&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;31&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;Delete Counter&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">enabled</span>=<span style="color: #990000;">&quot;{numCounters &gt; 0}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;deleteCounterButton_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>Depending on <strong>isCountdownRunning</strong> (note that it is <em>bindable</em>&#8230;), the <em>button&#8217;s label</em> will change, and a <em>click</em> on the <em>button</em> will <em>dispatch</em> the new <strong>CountdownEvent.START_COUNTDOWN</strong> or <strong>CountdownEvent.STOP_COUNTDOWN</strong>.</p>
<p><cite><br />
<h3>Demo #7: src/Events/CountdownEvent.as</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span> Events<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> CountdownEvent <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Event</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static const COUNTDOWN <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;countDown&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static const START_COUNTDOWN <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;startCountDown&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static const STOP_COUNTDOWN <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;stopCountDown&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> countdown <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> CountdownEvent<span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">bubbles</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">cancelable</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">bubbles</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">cancelable</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>We can see those two new <em>types</em> here. What about <strong>CountdownManager</strong>?</p>
<p><cite><br />
<h3>Demo #7: src/managers/CountdownManager.as</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span> managers<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CountdownEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CounterEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>asfusion<span style="color: #000066; font-weight: bold;">.</span>mate<span style="color: #000066; font-weight: bold;">.</span>events<span style="color: #000066; font-weight: bold;">.</span>Dispatcher<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">EventDispatcher</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">IEventDispatcher</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TimerEvent</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.utils</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Timer</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> CountdownManager <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">EventDispatcher</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">timer</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Timer</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> duration <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> countdown <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> dispatcher <span style="color: #000066; font-weight: bold;">:</span> Dispatcher = <span style="color: #0033ff; font-weight: bold;">new</span> Dispatcher<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> isCountdownRunning <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> CountdownManager<span style="color: #000000;">&#40;</span> <span style="color: #004993;">target</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">IEventDispatcher</span> = <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">target</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; countdown = duration<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">timer</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Timer</span><span style="color: #000000;">&#40;</span> 1000<span style="color: #000066; font-weight: bold;">,</span> 1 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">timer</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">TimerEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TIMER_COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> onTimerComplete <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">timer</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onTimerComplete<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">TimerEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">timer</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">reset</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">timer</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">--</span>countdown<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> counterEvent <span style="color: #000066; font-weight: bold;">:</span> CountdownEvent = <span style="color: #0033ff; font-weight: bold;">new</span> CountdownEvent<span style="color: #000000;">&#40;</span> CountdownEvent<span style="color: #000066; font-weight: bold;">.</span>COUNTDOWN <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counterEvent<span style="color: #000066; font-weight: bold;">.</span>countdown = <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>countdown<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatcher<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> counterEvent <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> countdown <span style="color: #000066; font-weight: bold;">&lt;</span> 1 <span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatcher<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> CounterEvent<span style="color: #000000;">&#40;</span> CounterEvent<span style="color: #000066; font-weight: bold;">.</span>RESET <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; countdown = duration<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> startCountdown<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">timer</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; isCountdownRunning = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> stopCountdown<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">timer</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; isCountdownRunning = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>The same <em>bindable</em> <strong>isCountdownRunning</strong> here. And two dead simple methods: <strong>startCountdown()</strong> and <strong>stopCountdown().</strong></p>
<p>Last, but not least: the now famous <strong>MainEventMap</strong>:</p>
<p><cite><br />
<h3>Demo #7: src/maps/MainEventMap.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventMap xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns<span style="color: #000066; font-weight: bold;">:</span>mate=<span style="color: #990000;">&quot;http://mate.asfusion.com/&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CountdownEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>SubCounter<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> managers<span style="color: #000066; font-weight: bold;">.</span>CountdownManager<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>events<span style="color: #000066; font-weight: bold;">.</span>FlexEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>Counter<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>MainView<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> managers<span style="color: #000066; font-weight: bold;">.</span>CounterManager<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CounterEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Debugger <span style="color: #004993;">level</span>=<span style="color: #990000;">&quot;{Debugger.ALL}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;{FlexEvent.APPLICATION_COMPLETE}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>ObjectBuilder generator=<span style="color: #990000;">&quot;{CountdownManager}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;{CounterEvent.INCREASE_GLOBAL}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>MethodInvoker generator=<span style="color: #990000;">&quot;{CounterManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;increaseGlobal&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;{CounterEvent.DECREASE_GLOBAL}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>MethodInvoker generator=<span style="color: #990000;">&quot;{CounterManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;decreaseGlobal&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;{CounterEvent.RESET}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>MethodInvoker generator=<span style="color: #990000;">&quot;{CounterManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;reset&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;{CountdownEvent.START_COUNTDOWN}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>MethodInvoker generator=<span style="color: #990000;">&quot;{CountdownManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;startCountdown&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;{CountdownEvent.STOP_COUNTDOWN}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>MethodInvoker generator=<span style="color: #990000;">&quot;{CountdownManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;stopCountdown&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors targets=<span style="color: #990000;">&quot;{[Counter, MainView]}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>PropertyInjector <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;{CounterManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sourceKey=<span style="color: #990000;">&quot;globalAmount&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;targetKey=<span style="color: #990000;">&quot;globalAmount&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors targets=<span style="color: #990000;">&quot;{[Counter, SubCounter]}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>ListenerInjector eventType=<span style="color: #990000;">&quot;{CounterEvent.RESET}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;reset&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors <span style="color: #004993;">target</span>=<span style="color: #990000;">&quot;{MainView}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; debug=<span style="color: #990000;">&quot;true&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>PropertyInjector <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;{CountdownManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sourceKey=<span style="color: #990000;">&quot;isCountdownRunning&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;targetKey=<span style="color: #990000;">&quot;isCountdownRunning&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>ListenerInjector eventType=<span style="color: #990000;">&quot;{CountdownEvent.COUNTDOWN}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;updateTitle&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventMap<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p><strong>EventHandlers</strong> and <strong>ListenerInjectors</strong> catch events, then <em>invoke methods</em>, or <em>inject properties</em>, <em>blah, blah, blah</em>.</p>
<p>I bet you start to get it by now <img src='http://www.flexstuff.co.uk/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Next: #8 Modules Example (pt 1)</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.flexstuff.co.uk%2F2009%2F08%2F09%2Fmate-examples-7-reset-countdown-pt-2%2F';
  addthis_title  = 'Mate+examples%3A+%237+Reset+Countdown+%28pt+2%29';
  addthis_pub    = 'gillesguillemin';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>


<p>Related posts:<ol><li><a href='http://www.flexstuff.co.uk/2009/08/09/mate-examples-6-reset-countdown-pt-1/' rel='bookmark' title='Permanent Link: Mate examples: #6 Reset Countdown (pt 1)'>Mate examples: #6 Reset Countdown (pt 1)</a> <small>This blog post is related to My LFPUG Presentation about...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/18/mate-examples-8-modules-example-pt-1/' rel='bookmark' title='Permanent Link: Mate examples: #8 Modules Example (pt 1)'>Mate examples: #8 Modules Example (pt 1)</a> <small>This is the eigth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/23/mate-examples-9-modules-example-pt-2/' rel='bookmark' title='Permanent Link: Mate examples: #9 Modules Example (pt 2)'>Mate examples: #9 Modules Example (pt 2)</a> <small>This is the ninth of a series of gradually more...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.flexstuff.co.uk/2009/08/09/mate-examples-7-reset-countdown-pt-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mate examples: #6 Reset Countdown (pt 1)</title>
		<link>http://www.flexstuff.co.uk/2009/08/09/mate-examples-6-reset-countdown-pt-1/</link>
		<comments>http://www.flexstuff.co.uk/2009/08/09/mate-examples-6-reset-countdown-pt-1/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 18:00:04 +0000</pubDate>
		<dc:creator>gillesguillemin</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Mate Framework]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[London Flash Platform User Group]]></category>
		<category><![CDATA[mate]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[mxml]]></category>

		<guid isPermaLink="false">http://www.flexstuff.co.uk/?p=548</guid>
		<description><![CDATA[This blog post is related to My LFPUG Presentation about Mate blog post.
This is the sixth of a series of gradually more complex examples on how to use Mate. If you haven&#8217;t done it yet you should have a look first at our previous examples: #1, #2, #3, #4 and #5.
Today we&#8217;re going to add [...]


Related posts:<ol><li><a href='http://www.flexstuff.co.uk/2009/08/09/mate-examples-7-reset-countdown-pt-2/' rel='bookmark' title='Permanent Link: Mate examples: #7 Reset Countdown (pt 2)'>Mate examples: #7 Reset Countdown (pt 2)</a> <small>This is the seventh of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/18/mate-examples-8-modules-example-pt-1/' rel='bookmark' title='Permanent Link: Mate examples: #8 Modules Example (pt 1)'>Mate examples: #8 Modules Example (pt 1)</a> <small>This is the eigth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/23/mate-examples-9-modules-example-pt-2/' rel='bookmark' title='Permanent Link: Mate examples: #9 Modules Example (pt 2)'>Mate examples: #9 Modules Example (pt 2)</a> <small>This is the ninth of a series of gradually more...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>This blog post is related to <a href="http://www.flexstuff.co.uk/2009/08/05/my-lfpug-presentation-about-mate/" target="_blank">My LFPUG Presentation about Mate</a> blog post.</p>
<p>This is the sixth of a series of gradually more complex examples on how to use <em>Mate</em>. If you haven&#8217;t done it yet you should have a look first at our previous examples: <a href="http://www.flexstuff.co.uk/2009/08/05/mate-examples-1-a-very-basic-injectors-example/" target="_blank">#1,</a> <a href="http://www.flexstuff.co.uk/2009/08/05/mate-examples-2-databinding-and-eventhandlers/" target="_blank">#2</a>, <a href="http://www.flexstuff.co.uk/2009/08/06/mate-examples-3-multiple-counters/" target="_blank">#3</a>, <a href="http://www.flexstuff.co.uk/?p=521" target="_blank">#4</a> and <a href="http://www.flexstuff.co.uk/2009/08/06/mate-examples-5-localeventmap/" target="_blank">#5</a>.</p>
<p>Today we&#8217;re going to add another useless functionality to our already useless application: <em>a reset countdown</em>. It&#8217;s a <em>timer</em> that resets all the <em>counters</em> when it reaches 0. The point here is to illustrate the communication (other than using <em>data binding</em>) between a <em>manager</em> and the rest of the application.</p>
<p>Here is the demo (source is available by right-clicking on the demo after launching it):</p>
<div class="wp-caption aligncenter" style="width: 360px"><a class="lightview" title="#6 Reset Countdown (part 1) :: Right-click to view the source. :: width: 1024, height: 768" href="http://flexstuff.co.uk/wp-content/uploads/examples/mate_lfpug/_Demo06%20-%20Reset%20countdown%20(1)/Demo.swf"><img src="http://flexstuff.co.uk/wp-content/uploads/examples/mate_lfpug/_Demo06%20-%20Reset%20countdown%20(1)/Mate_Example6.png" alt="Mate example" width="350" height="250" /></a><p class="wp-caption-text">#6 Reset Countdown (part 1) (click to Launch)</p></div>
<p>As you can see, it&#8217;s pretty much the same application as before (visually speaking) except that there&#8217;s now a <em>countdown</em> showing up next to the <strong>MainView</strong> title. When it reaches 0 all your <strong>amounts</strong>, <strong>subAmounts</strong> and <strong>globalAmounts</strong> are reset to 0.</p>
<p><span id="more-548"></span>Now let&#8217;s have a look at <strong>MainView.mxml</strong> first:</p>
<p><cite><br />
<h3>Demo #6: src/views/MainView.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;860&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;600&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title=<span style="color: #990000;">&quot;{mainTitle}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layout=<span style="color: #990000;">&quot;absolute&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns<span style="color: #000066; font-weight: bold;">:</span>views=<span style="color: #990000;">&quot;views.*&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CountdownEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CounterEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> globalAmount <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> numCounters <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> mainTitle <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;MainView&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> buttonIncrease_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> CounterEvent<span style="color: #000000;">&#40;</span> CounterEvent<span style="color: #000066; font-weight: bold;">.</span>INCREASE_GLOBAL <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> buttonDecrease_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> CounterEvent<span style="color: #000000;">&#40;</span> CounterEvent<span style="color: #000066; font-weight: bold;">.</span>DECREASE_GLOBAL <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> addCounterButton_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> counter <span style="color: #000066; font-weight: bold;">:</span> Counter = <span style="color: #0033ff; font-weight: bold;">new</span> Counter<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counter<span style="color: #000066; font-weight: bold;">.</span>counterTitle = <span style="color: #990000;">&quot;Counter &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000066; font-weight: bold;">++</span>numCounters<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mainTile<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>counter<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> deleteCounterButton_clickHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mainTile<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeChildAt</span><span style="color: #000000;">&#40;</span>mainTile<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">numChildren</span> <span style="color: #000066; font-weight: bold;">-</span> 1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">--</span>numCounters<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> updateTitle <span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> CountdownEvent <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mainTitle = <span style="color: #990000;">&quot;MainView (&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> event<span style="color: #000066; font-weight: bold;">.</span>countdown <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;)&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Global Amount:&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;28&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;16&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{globalAmount}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;124&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;16&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Tile id=<span style="color: #990000;">&quot;mainTile&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">left</span>=<span style="color: #990000;">&quot;10&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">right</span>=<span style="color: #990000;">&quot;10&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">top</span>=<span style="color: #990000;">&quot;82&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">bottom</span>=<span style="color: #990000;">&quot;10&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Tile<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;buttonIncrease&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;68&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;34&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;+&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;buttonIncrease_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;buttonDecrease&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;140&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;34&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;-&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;buttonDecrease_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;addCounterButton&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;614&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;31&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;Add Counter&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;addCounterButton_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;deleteCounterButton&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;716&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;31&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;Delete Counter&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">enabled</span>=<span style="color: #990000;">&quot;{numCounters &gt; 0}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;deleteCounterButton_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>A new method <strong>updateTitle</strong> has appeared, updating the <strong>MainView</strong> panel title with the <strong>event.countdown</strong> property of a new <strong>CountdownEvent</strong>:</p>
<p><cite><br />
<h3>Demo #6: src/Events/CountdownEvent.as</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span> Events<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> CountdownEvent <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Event</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static const COUNTDOWN <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;countDown&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> countdown <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> CountdownEvent<span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">bubbles</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">cancelable</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">bubbles</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">cancelable</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>It&#8217;s a rather common (<em>bubbles = true</em>) <strong>Event</strong>, with one type (<strong>COUNTDOWN</strong>) and a <strong>public var countdown</strong> (an <em>integer</em>). Now let&#8217;s have a look at <strong>CounterEvent.as</strong>, see if there&#8217;s any change:</p>
<p><cite><br />
<h3>Demo #6: src/Events/CounterEvent.as</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span> Events<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> CounterEvent <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Event</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static const INCREASE_GLOBAL <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;increaseGlobal&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static const DECREASE_GLOBAL <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;decreaseGlobal&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static const INCREASE_SUB_TOTAL <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;increaseSubTotal&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static const DECREASE_SUB_TOTAL <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;decreaseSubTotal&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static const RESET <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;resetCounters&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> CounterEvent<span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">bubbles</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">cancelable</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">bubbles</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">cancelable</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>There&#8217;s only a new type: <strong>RESET</strong>. Ok, what about <strong>CounterManager.as</strong> then?</p>
<p><cite><br />
<h3>Demo #6: src/managers/CounterManager.as</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span> managers<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">EventDispatcher</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">IEventDispatcher</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> CounterManager <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">EventDispatcher</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> globalAmount <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> increaseGlobal<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">++</span>globalAmount<span style="color: #000066; font-weight: bold;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> decreaseGlobal<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">--</span>globalAmount<span style="color: #000066; font-weight: bold;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">reset</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; globalAmount = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Oh, there&#8217;s a new method <strong>reset()</strong> that set <strong>globalAmount</strong> value to 0. Looks like there&#8217;s a relationship of some sort between the method and the new <strong>RESET</strong> type of <strong>CounterEvent</strong>&#8230;</p>
<p>And <strong>Counter.mxml</strong> and <strong>SubCounter.mxml</strong>?</p>
<p><cite><br />
<h3>Demo #6: src/views/Counter.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;264&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;380&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title=<span style="color: #990000;">&quot;{counterTitle}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layout=<span style="color: #990000;">&quot;absolute&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns<span style="color: #000066; font-weight: bold;">:</span>views=<span style="color: #990000;">&quot;views.*&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns<span style="color: #000066; font-weight: bold;">:</span>maps=<span style="color: #990000;">&quot;maps.*&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CounterEvent<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> globalAmount <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> subTotal <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> amount <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _counterTitle <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;Counter Title&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> counterTitle<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> _counterTitle<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> counterTitle<span style="color: #000000;">&#40;</span> v <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _counterTitle = v<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> increaseSubTotal<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> CounterEvent <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">++</span>subTotal<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> decreaseSubTotal<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> CounterEvent <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">--</span>subTotal<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">reset</span><span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> CounterEvent <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; subTotal = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>maps<span style="color: #000066; font-weight: bold;">:</span>SubEventMap dispatcher=<span style="color: #990000;">&quot;{this}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;27&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;10&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Global Amount:&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;121&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;10&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{globalAmount}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>views<span style="color: #000066; font-weight: bold;">:</span>SubCounter <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;64&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; horizontalCenter=<span style="color: #990000;">&quot;0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; borderStyle=<span style="color: #990000;">&quot;inset&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>views<span style="color: #000066; font-weight: bold;">:</span>SubCounter<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>views<span style="color: #000066; font-weight: bold;">:</span>SubCounter <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;208&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; horizontalCenter=<span style="color: #990000;">&quot;0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; borderStyle=<span style="color: #990000;">&quot;inset&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>views<span style="color: #000066; font-weight: bold;">:</span>SubCounter<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;63&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;35&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Subtotal:&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;124&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;35&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{subTotal}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p><cite><br />
<h3>Demo #6: src/views/SubCounter.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Canvas xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;220&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;120&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CounterEvent<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> subTotal <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> amount <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> increaseSubTotal<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> CounterEvent <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">++</span>subTotal<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> decreaseSubTotal<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> CounterEvent <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">--</span>subTotal<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">reset</span><span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> CounterEvent = <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; amount = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; subTotal = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> buttonIncrease_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">++</span>amount<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> CounterEvent<span style="color: #000000;">&#40;</span> CounterEvent<span style="color: #000066; font-weight: bold;">.</span>INCREASE_GLOBAL <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> CounterEvent<span style="color: #000000;">&#40;</span> CounterEvent<span style="color: #000066; font-weight: bold;">.</span>INCREASE_SUB_TOTAL <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> buttonDecrease_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">--</span>amount<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> CounterEvent<span style="color: #000000;">&#40;</span> CounterEvent<span style="color: #000066; font-weight: bold;">.</span>DECREASE_GLOBAL <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> CounterEvent<span style="color: #000000;">&#40;</span> CounterEvent<span style="color: #000066; font-weight: bold;">.</span>DECREASE_SUB_TOTAL <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;50&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;15&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Subtotal:&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;111&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;15&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{subTotal}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;57&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;50&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Amount:&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;111&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;50&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{amount}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;buttonIncrease&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;58&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;77&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;+&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;buttonIncrease_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;buttonDecrease&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;130&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;77&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;-&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;buttonDecrease_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Canvas<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>Pretty much the same <strong>reset() methods</strong> in both of them as well.</p>
<p>Ok, it&#8217;s time to have a look at the newcomer then: <strong>CountdownManager.as</strong>:</p>
<p><cite><br />
<h3>Demo #6: src/managers/CountdownManager.as</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span> managers<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CountdownEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CounterEvent<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>asfusion<span style="color: #000066; font-weight: bold;">.</span>mate<span style="color: #000066; font-weight: bold;">.</span>events<span style="color: #000066; font-weight: bold;">.</span>Dispatcher<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">EventDispatcher</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">IEventDispatcher</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TimerEvent</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.utils</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Timer</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> CountdownManager <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">EventDispatcher</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">timer</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Timer</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> duration <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> countdown <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> dispatcher <span style="color: #000066; font-weight: bold;">:</span> Dispatcher = <span style="color: #0033ff; font-weight: bold;">new</span> Dispatcher<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> CountdownManager<span style="color: #000000;">&#40;</span> <span style="color: #004993;">target</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">IEventDispatcher</span> = <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">target</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; countdown = duration<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">timer</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Timer</span><span style="color: #000000;">&#40;</span> 1000<span style="color: #000066; font-weight: bold;">,</span> 1 <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">timer</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">TimerEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TIMER_COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> onTimerComplete <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">timer</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onTimerComplete<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">TimerEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">timer</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">reset</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">timer</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">--</span>countdown<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> counterEvent <span style="color: #000066; font-weight: bold;">:</span> CountdownEvent = <span style="color: #0033ff; font-weight: bold;">new</span> CountdownEvent<span style="color: #000000;">&#40;</span> CountdownEvent<span style="color: #000066; font-weight: bold;">.</span>COUNTDOWN <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counterEvent<span style="color: #000066; font-weight: bold;">.</span>countdown = <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>countdown<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatcher<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> counterEvent <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span> countdown <span style="color: #000066; font-weight: bold;">&lt;</span> 1 <span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatcher<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> CounterEvent<span style="color: #000000;">&#40;</span> CounterEvent<span style="color: #000066; font-weight: bold;">.</span>RESET <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; countdown = duration<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>CountdownManager</strong> extends <strong>EventDispatcher</strong> and is once again rather simple: it&#8217;s basically a <strong>Timer</strong> that dispatches every second a <strong>CountdownEvent</strong> with the type <strong>CountdownEvent.COUNTDOWN</strong>, passing its <strong>countdown</strong> variable value to the <strong>event countdown property</strong> (property that will be caught later on by <strong>MainView</strong> to update its title).<br />
<strong>Countdown</strong> also dispatchs a <strong>CounterEvent</strong> with the type <strong>CounterEvent.RESET</strong> whenever its countdown value reaches 0.</p>
<p>Once again, there&#8217;s absolutely no direct connection between the different parts of the application (<strong>CountdownManager, MainView, Counter</strong>, etc). <strong>MainEventMap.mxml</strong> is here to make this connection:</p>
<p><cite><br />
<h3>Demo #6: src/maps/MainEventMap.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventMap xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns<span style="color: #000066; font-weight: bold;">:</span>mate=<span style="color: #990000;">&quot;http://mate.asfusion.com/&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CountdownEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>SubCounter<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> managers<span style="color: #000066; font-weight: bold;">.</span>CountdownManager<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>events<span style="color: #000066; font-weight: bold;">.</span>FlexEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>Counter<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>MainView<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> managers<span style="color: #000066; font-weight: bold;">.</span>CounterManager<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CounterEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Debugger <span style="color: #004993;">level</span>=<span style="color: #990000;">&quot;{Debugger.ALL}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;{FlexEvent.APPLICATION_COMPLETE}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>ObjectBuilder generator=<span style="color: #990000;">&quot;{CountdownManager}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;{CounterEvent.INCREASE_GLOBAL}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>MethodInvoker generator=<span style="color: #990000;">&quot;{CounterManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;increaseGlobal&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;{CounterEvent.DECREASE_GLOBAL}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>MethodInvoker generator=<span style="color: #990000;">&quot;{CounterManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;decreaseGlobal&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;{CounterEvent.RESET}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>MethodInvoker generator=<span style="color: #990000;">&quot;{CounterManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;reset&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors targets=<span style="color: #990000;">&quot;{[Counter, MainView]}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">start</span>=<span style="color: #990000;">&quot;trace('MAIN INJECTORS')&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>PropertyInjector <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;{CounterManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sourceKey=<span style="color: #990000;">&quot;globalAmount&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;targetKey=<span style="color: #990000;">&quot;globalAmount&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors targets=<span style="color: #990000;">&quot;{[Counter, SubCounter]}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>ListenerInjector eventType=<span style="color: #990000;">&quot;{CounterEvent.RESET}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;reset&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors <span style="color: #004993;">target</span>=<span style="color: #990000;">&quot;{MainView}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>ListenerInjector eventType=<span style="color: #990000;">&quot;{CountdownEvent.COUNTDOWN}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;updateTitle&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventMap<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>First thing to notice: <em>Mate</em> can catch <strong>FlexEvent events</strong>. Not being a <em>visual component</em>, <strong>CountdownManager</strong> still needs to be <em>declared</em> and <em>instanciated</em> somewhere in order to function properly. That&#8217;s the role of <strong>ObjectBuilder tag</strong>. When <strong>FlexEvent. APPLICATION_COMPLETE</strong> is caught, <strong>CountdownManager</strong> is <em>instanciated</em> (and the <strong>init()</strong> method, starting the <em>timer</em>, is called by the class <em>constructor</em>).</p>
<p>You should be used now to the other parts: whenever <strong>CounterEvent.RESET</strong> is caught (by <strong>EventHandlers</strong> or a <strong>ListenerInjector</strong>) it invokes the <strong>reset</strong> methods of <strong>CounterManager</strong>, <strong>Counter</strong> and <strong>SubCounter</strong>. And it&#8217;s just the same with <strong>CountdownEvent.COUNTDOWN</strong> which calls <strong>MainView</strong>&#8217;s <strong>updateTitle</strong> method.</p>
<p>One <strong>VERY important thing</strong> to notice though: <strong>CountdownManager</strong> not being part of the <strong>displaylist</strong> it can not <em>dispatch</em> events on its own if you want them to be caught by the <strong>MainEventMap</strong>. That&#8217;s the <strong>Dispatcher</strong>&#8217;s role:</p>
<p><cite><br />
<h3>Demo #6: src/managers/CountdownManager.as (detail)</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">...</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> dispatcher <span style="color: #000066; font-weight: bold;">:</span> Dispatcher = <span style="color: #0033ff; font-weight: bold;">new</span> Dispatcher<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000066; font-weight: bold;">...</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatcher<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> counterEvent <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">...</span></div></td></tr></tbody></table></div>
<p>Forget to do this and you can wait for long before something reacts at all&#8230;</p>
<p>Once again, <em>Mate</em> makes things really easy as long as you follow <em>some simple rules</em>.</p>
<p>Next: some refinements of our reset countdown with <a href="http://www.flexstuff.co.uk/550">#7 Reset Countdown (pt 2)</a>.</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.flexstuff.co.uk%2F2009%2F08%2F09%2Fmate-examples-6-reset-countdown-pt-1%2F';
  addthis_title  = 'Mate+examples%3A+%236+Reset+Countdown+%28pt+1%29';
  addthis_pub    = 'gillesguillemin';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>


<p>Related posts:<ol><li><a href='http://www.flexstuff.co.uk/2009/08/09/mate-examples-7-reset-countdown-pt-2/' rel='bookmark' title='Permanent Link: Mate examples: #7 Reset Countdown (pt 2)'>Mate examples: #7 Reset Countdown (pt 2)</a> <small>This is the seventh of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/18/mate-examples-8-modules-example-pt-1/' rel='bookmark' title='Permanent Link: Mate examples: #8 Modules Example (pt 1)'>Mate examples: #8 Modules Example (pt 1)</a> <small>This is the eigth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/23/mate-examples-9-modules-example-pt-2/' rel='bookmark' title='Permanent Link: Mate examples: #9 Modules Example (pt 2)'>Mate examples: #9 Modules Example (pt 2)</a> <small>This is the ninth of a series of gradually more...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.flexstuff.co.uk/2009/08/09/mate-examples-6-reset-countdown-pt-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mate examples: #5 LocalEventMap</title>
		<link>http://www.flexstuff.co.uk/2009/08/06/mate-examples-5-localeventmap/</link>
		<comments>http://www.flexstuff.co.uk/2009/08/06/mate-examples-5-localeventmap/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 17:32:28 +0000</pubDate>
		<dc:creator>gillesguillemin</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Mate Framework]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[London Flash Platform User Group]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[mxml]]></category>

		<guid isPermaLink="false">http://www.flexstuff.co.uk/?p=530</guid>
		<description><![CDATA[This is the fifth of a series of gradually more complex examples on how to use Mate. We're going here to study how to use Mate's LocalEventMap.


Related posts:<ol><li><a href='http://www.flexstuff.co.uk/2009/08/23/mate-examples-9-modules-example-pt-2/' rel='bookmark' title='Permanent Link: Mate examples: #9 Modules Example (pt 2)'>Mate examples: #9 Modules Example (pt 2)</a> <small>This is the ninth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/18/mate-examples-8-modules-example-pt-1/' rel='bookmark' title='Permanent Link: Mate examples: #8 Modules Example (pt 1)'>Mate examples: #8 Modules Example (pt 1)</a> <small>This is the eigth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/09/mate-examples-6-reset-countdown-pt-1/' rel='bookmark' title='Permanent Link: Mate examples: #6 Reset Countdown (pt 1)'>Mate examples: #6 Reset Countdown (pt 1)</a> <small>This blog post is related to My LFPUG Presentation about...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>This blog post is related to <a href="http://www.flexstuff.co.uk/2009/08/05/my-lfpug-presentation-about-mate/" target="_blank">My LFPUG Presentation about Mate</a> blog post.</p>
<p>This is the fifth of a series of gradually more complex examples on how to use <em>Mate</em>. If you haven&#8217;t done it yet you should have a look first at our previous examples: <a href="http://www.flexstuff.co.uk/2009/08/05/mate-examples-1-a-very-basic-injectors-example/" target="_blank">#1,</a> <a href="http://www.flexstuff.co.uk/2009/08/05/mate-examples-2-databinding-and-eventhandlers/" target="_blank">#2</a>, <a href="http://www.flexstuff.co.uk/2009/08/06/mate-examples-3-multiple-counters/" target="_blank">#3</a> and <a href="http://www.flexstuff.co.uk/?p=521" target="_blank">#4</a>.</p>
<p>In <a href="../?p=521" target="_blank">the previous example</a>, we added the capability to <em>add/remove counters</em> to the <em>Tile</em> component dynamically. Now let&#8217;s imagine that each <em>counter</em> is now embedding two <em>subcounters</em>, each one being capable of interacting with the other, but without affecting the <em>subcounters</em> in other <em>counters</em>.</p>
<p>The demo should probably be clearer (source is available by right-clicking on the demo after launching it):</p>
<div class="wp-caption aligncenter" style="width: 360px"><a class="lightview" title="#5 LocalEventMap :: Right-click to view the source. :: width: 1024, height: 768" href="http://flexstuff.co.uk/wp-content/uploads/examples/mate_lfpug/_Demo05%20-%20LocalEventMap/Demo.swf"><img src="http://flexstuff.co.uk/wp-content/uploads/examples/mate_lfpug/_Demo05%20-%20LocalEventMap/Mate_Example5.png" alt="Mate example" width="350" height="250" /></a><p class="wp-caption-text">#5 LocalEventMap (click to Launch)</p></div>
<p><span id="more-530"></span></p>
<p>When you click on the [+]/[-] <em>buttons</em> of one a the <em>subcounters</em>, it <em>increases/decreases</em> its own amount, the <em>globalAmount</em> (at every level of the application) and its <em>subtotal</em> along with the <em>subtotal</em> of its counterpart (the <em>other</em> <em>subcounter</em> of its <em>parent counter</em>), without affecting the <em>subtotal</em> values of the other <em>subcounters</em>.</p>
<p><cite><br />
<h3>Demo #5: src/views/Counter.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;264&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;380&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title=<span style="color: #990000;">&quot;{counterTitle}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layout=<span style="color: #990000;">&quot;absolute&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns<span style="color: #000066; font-weight: bold;">:</span>views=<span style="color: #990000;">&quot;views.*&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns<span style="color: #000066; font-weight: bold;">:</span>maps=<span style="color: #990000;">&quot;maps.*&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CounterEvent<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> globalAmount <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> subTotal <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> amount <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _counterTitle <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;Counter Title&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> counterTitle<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> _counterTitle<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> counterTitle<span style="color: #000000;">&#40;</span> v <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _counterTitle = v<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> increaseSubTotal<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> CounterEvent <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">++</span>subTotal<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> decreaseSubTotal<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> CounterEvent <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">--</span>subTotal<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>maps<span style="color: #000066; font-weight: bold;">:</span>SubEventMap dispatcher=<span style="color: #990000;">&quot;{this}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;27&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;10&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Global Amount:&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;121&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;10&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{globalAmount}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>views<span style="color: #000066; font-weight: bold;">:</span>SubCounter <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;64&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; horizontalCenter=<span style="color: #990000;">&quot;0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; borderStyle=<span style="color: #990000;">&quot;inset&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>views<span style="color: #000066; font-weight: bold;">:</span>SubCounter<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>views<span style="color: #000066; font-weight: bold;">:</span>SubCounter <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;208&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; horizontalCenter=<span style="color: #990000;">&quot;0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; borderStyle=<span style="color: #990000;">&quot;inset&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>views<span style="color: #000066; font-weight: bold;">:</span>SubCounter<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;63&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;35&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Subtotal:&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;124&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;35&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{subTotal}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>Plenty of novelties in <em><strong>Counter.mxml</strong></em>: 2 new <em><strong>SubCounter</strong></em> components, a new <em><strong>subTotal private variable</strong></em> incremented/decremented by 2 new <em><strong>public methods</strong></em>: <em><strong>increaseSubTotal</strong></em> and <em><strong>decreaseSubTotal</strong></em>.</p>
<p>A <em>very important</em> new thing as well: the appearing of a new <em><strong>SubEventMap</strong></em>. We&#8217;ll come back to that one a bit later. Let&#8217;s have a look at <em><strong>SubCounter.mxml</strong></em> first:</p>
<p><cite><br />
<h3>Demo #5: src/views/SubCounter.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Canvas xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;220&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;120&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CounterEvent<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> subTotal <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> amount <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> increaseSubTotal <span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> CounterEvent <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">++</span>subTotal<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> decreaseSubTotal <span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> CounterEvent <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">--</span>subTotal<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> buttonIncrease_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">++</span>amount<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> CounterEvent<span style="color: #000000;">&#40;</span> CounterEvent<span style="color: #000066; font-weight: bold;">.</span>INCREASE_GLOBAL <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> CounterEvent<span style="color: #000000;">&#40;</span> CounterEvent<span style="color: #000066; font-weight: bold;">.</span>INCREASE_SUB_TOTAL <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> buttonDecrease_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">--</span>amount<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> CounterEvent<span style="color: #000000;">&#40;</span> CounterEvent<span style="color: #000066; font-weight: bold;">.</span>DECREASE_GLOBAL <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> CounterEvent<span style="color: #000000;">&#40;</span> CounterEvent<span style="color: #000066; font-weight: bold;">.</span>DECREASE_SUB_TOTAL <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;50&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;15&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Subtotal:&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;111&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;15&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{subTotal}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;57&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;50&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Amount:&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;111&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;50&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{amount}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;buttonIncrease&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;58&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;77&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;+&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;buttonIncrease_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;buttonDecrease&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;130&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;77&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;-&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;buttonDecrease_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Canvas<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>As you can see, it looks a lot like <em><strong>Counter</strong></em> used to in our previous examples. But there are differences: almost any references to <em><strong>globalAmount</strong></em> were replaced by references to <em><strong>SubTotal. </strong></em>It also refers to 2 new event types:</p>
<p><cite><br />
<h3>Demo #5: src/Events/CounterEvent.as</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span> Events<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> CounterEvent <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Event</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static const INCREASE_GLOBAL <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;increaseGlobal&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static const DECREASE_GLOBAL <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;decreaseGlobal&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static const INCREASE_SUB_TOTAL <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;increaseSubTotal&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static const DECREASE_SUB_TOTAL <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;decreaseSubTotal&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> CounterEvent<span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">bubbles</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">cancelable</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>=<span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">type</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">bubbles</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">cancelable</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p><em><strong>CounterEvent.INCREASE_SUB_TOTAL</strong></em> and <em><strong>CounterEvent.DECREASE_SUB_TOTAL</strong></em> were added to the previous ones. Now let&#8217;s see the <em>EventMaps</em>. First the <em><strong>MainEventMap.mxml</strong></em>:</p>
<p><cite><br />
<h3>Demo #5: src/maps/MainEventMap.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventMap xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns<span style="color: #000066; font-weight: bold;">:</span>mate=<span style="color: #990000;">&quot;http://mate.asfusion.com/&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>Counter<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>MainView<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> managers<span style="color: #000066; font-weight: bold;">.</span>CounterManager<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CounterEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Debugger <span style="color: #004993;">level</span>=<span style="color: #990000;">&quot;{Debugger.ALL}&quot;</span> <span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;{CounterEvent.INCREASE_GLOBAL}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>MethodInvoker generator=<span style="color: #990000;">&quot;{CounterManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;increaseGlobal&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;{CounterEvent.DECREASE_GLOBAL}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>MethodInvoker generator=<span style="color: #990000;">&quot;{CounterManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;decreaseGlobal&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors targets=<span style="color: #990000;">&quot;{[Counter, MainView]}&quot;</span> <span style="color: #004993;">start</span>=<span style="color: #990000;">&quot;trace('MAIN INJECTORS')&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>PropertyInjector <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;{CounterManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sourceKey=<span style="color: #990000;">&quot;globalAmount&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;targetKey=<span style="color: #990000;">&quot;globalAmount&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventMap<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>Well, except for the <em><strong>Debugger</strong></em> tag and the <em><strong>trace</strong></em> inside the <em><strong>start property</strong></em> (an <em>eventListener</em> actually) it hasn&#8217;t changed at all! So, what&#8217;s in the new <em><strong>SubEventMap.mxml</strong></em>?</p>
<p><cite><br />
<h3>Demo #5: src/maps/SubEventMap.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>LocalEventMap xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns<span style="color: #000066; font-weight: bold;">:</span>mate=<span style="color: #990000;">&quot;http://mate.asfusion.com/&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>Counter<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CounterEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>SubCounter<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Debugger <span style="color: #004993;">level</span>=<span style="color: #990000;">&quot;{Debugger.ALL}&quot;</span> <span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors targets=<span style="color: #990000;">&quot;{[Counter, SubCounter]}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>ListenerInjector eventType=<span style="color: #990000;">&quot;{CounterEvent.INCREASE_SUB_TOTAL}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;increaseSubTotal&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>ListenerInjector eventType=<span style="color: #990000;">&quot;{CounterEvent.DECREASE_SUB_TOTAL}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;decreaseSubTotal&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>LocalEventMap<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>Here again, it&#8217;s pretty simple and still all the power lies here. The only true novelty here is the fact that the component now extends <em><strong>LocalEventMap</strong></em> (instead of <em><strong>EventMap</strong></em>). The main difference between <em><strong>LocalEventMap</strong></em> and the regular <em><strong>EventMap</strong></em> is that the <em><strong>LocalEventMap</strong></em> listens only for events coming from the view it was declared in and its children. Nothing from the outside (unless explicitly told so). Exactly what we were looking for!</p>
<p>One last important bit here: when you instantiate your <em><strong>SubEventMap</strong></em> in <em><strong>Counter.mxml</strong></em>, you must declare a <em><strong>dispatcher</strong></em>:</p>
<p><cite><br />
<h3>Demo #5: src/views/Counter.mxml (detail)</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>48<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>maps<span style="color: #000066; font-weight: bold;">:</span>SubEventMap dispatcher=<span style="color: #990000;">&quot;{this}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span></div></td></tr></tbody></table></div>
<p>If you don&#8217;t declare <em><strong>{this}</strong></em> as a <em><strong>dispatcher</strong></em> it will simple won&#8217;t work at all and won&#8217;t catch any event.</p>
<p>That&#8217;s it for now. Next to come: <a href="http://www.flexstuff.co.uk/548">#6 Reset Countdown (part 1)</a></p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.flexstuff.co.uk%2F2009%2F08%2F06%2Fmate-examples-5-localeventmap%2F';
  addthis_title  = 'Mate+examples%3A+%235+LocalEventMap';
  addthis_pub    = 'gillesguillemin';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>


<p>Related posts:<ol><li><a href='http://www.flexstuff.co.uk/2009/08/23/mate-examples-9-modules-example-pt-2/' rel='bookmark' title='Permanent Link: Mate examples: #9 Modules Example (pt 2)'>Mate examples: #9 Modules Example (pt 2)</a> <small>This is the ninth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/18/mate-examples-8-modules-example-pt-1/' rel='bookmark' title='Permanent Link: Mate examples: #8 Modules Example (pt 1)'>Mate examples: #8 Modules Example (pt 1)</a> <small>This is the eigth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/09/mate-examples-6-reset-countdown-pt-1/' rel='bookmark' title='Permanent Link: Mate examples: #6 Reset Countdown (pt 1)'>Mate examples: #6 Reset Countdown (pt 1)</a> <small>This blog post is related to My LFPUG Presentation about...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.flexstuff.co.uk/2009/08/06/mate-examples-5-localeventmap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mate examples: #4 Counters created dynamically</title>
		<link>http://www.flexstuff.co.uk/2009/08/06/mate-examples-4-counters-created-dynamically/</link>
		<comments>http://www.flexstuff.co.uk/2009/08/06/mate-examples-4-counters-created-dynamically/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 14:15:25 +0000</pubDate>
		<dc:creator>gillesguillemin</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Mate Framework]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[London Flash Platform User Group]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[mxml]]></category>

		<guid isPermaLink="false">http://www.flexstuff.co.uk/?p=521</guid>
		<description><![CDATA[This is the fourth of a series of gradually more complex examples on how to use Mate.


Related posts:<ol><li><a href='http://www.flexstuff.co.uk/2009/08/06/mate-examples-3-multiple-counters/' rel='bookmark' title='Permanent Link: Mate examples: #3 Multiple Counters'>Mate examples: #3 Multiple Counters</a> <small>This is the third of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/18/mate-examples-8-modules-example-pt-1/' rel='bookmark' title='Permanent Link: Mate examples: #8 Modules Example (pt 1)'>Mate examples: #8 Modules Example (pt 1)</a> <small>This is the eigth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/09/mate-examples-7-reset-countdown-pt-2/' rel='bookmark' title='Permanent Link: Mate examples: #7 Reset Countdown (pt 2)'>Mate examples: #7 Reset Countdown (pt 2)</a> <small>This is the seventh of a series of gradually more...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>This blog post is related to <a href="http://www.flexstuff.co.uk/2009/08/05/my-lfpug-presentation-about-mate/" target="_blank">My LFPUG Presentation about Mate</a> blog post.</p>
<p>This is the fourth of a series of gradually more complex examples on how to use <em>Mate</em>. If you haven&#8217;t done it yet you should have a look first at our previous examples: <a href="http://www.flexstuff.co.uk/2009/08/05/mate-examples-1-a-very-basic-injectors-example/" target="_blank">#1,</a> <a href="http://www.flexstuff.co.uk/2009/08/05/mate-examples-2-databinding-and-eventhandlers/" target="_blank">#2</a> and <a href="http://www.flexstuff.co.uk/2009/08/06/mate-examples-3-multiple-counters/" target="_blank">#3</a>.</p>
<p>In <a href="http://www.flexstuff.co.uk/2009/08/06/mate-examples-3-multiple-counters/" target="_blank">the previous example</a>, we manually added four counters to a Tile component. Let&#8217;s now add/remove those counters dynamically.</p>
<p>But let&#8217;s have a look at the demo first (source is available by right-clicking on the demo after launching it):</p>
<div class="wp-caption aligncenter" style="width: 360px"><a class="lightview" title="#4 Counters created dynamically :: Right-click to view the source. :: width: 1024, height: 768" href="http://flexstuff.co.uk/wp-content/uploads/examples/mate_lfpug/_Demo04%20-%20Counters%20created%20dynamically/Demo.swf"><img src="http://flexstuff.co.uk/wp-content/uploads/examples/mate_lfpug/_Demo04%20-%20Counters%20created%20dynamically/Mate_Example4.png" alt="Mate example" width="350" height="250" /></a><p class="wp-caption-text">#4 Counters created dynamically (click to Launch)</p></div>
<p><span id="more-521"></span>Let&#8217;s say it straight ahead: there is absolutely no change in the <em>Mate</em> related classes/components in the current example. Still, we set here the ground for further examples so let&#8217;s have a quick look at the changes since <em>Example #3</em>:</p>
<p><cite><br />
<h3>Demo #4: src/views/MainView.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;860&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;600&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title=<span style="color: #990000;">&quot;MainView&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layout=<span style="color: #990000;">&quot;absolute&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns<span style="color: #000066; font-weight: bold;">:</span>views=<span style="color: #990000;">&quot;views.*&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CounterEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> globalAmount <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> numCounters <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> buttonIncrease_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> CounterEvent<span style="color: #000000;">&#40;</span> CounterEvent<span style="color: #000066; font-weight: bold;">.</span>INCREASE_GLOBAL <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> buttonDecrease_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> CounterEvent<span style="color: #000000;">&#40;</span> CounterEvent<span style="color: #000066; font-weight: bold;">.</span>DECREASE_GLOBAL <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> addCounterButton_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> counter <span style="color: #000066; font-weight: bold;">:</span> Counter = <span style="color: #0033ff; font-weight: bold;">new</span> Counter<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counter<span style="color: #000066; font-weight: bold;">.</span>counterTitle = <span style="color: #990000;">&quot;Counter &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000066; font-weight: bold;">++</span>numCounters<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mainTile<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>counter<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> deleteCounterButton_clickHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mainTile<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeChildAt</span><span style="color: #000000;">&#40;</span>mainTile<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">numChildren</span> <span style="color: #000066; font-weight: bold;">-</span> 1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">--</span>numCounters<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Global Amount:&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;28&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;16&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{globalAmount}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;124&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;16&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Tile id=<span style="color: #990000;">&quot;mainTile&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">left</span>=<span style="color: #990000;">&quot;10&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">right</span>=<span style="color: #990000;">&quot;10&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">top</span>=<span style="color: #990000;">&quot;82&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">bottom</span>=<span style="color: #990000;">&quot;10&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Tile<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;buttonIncrease&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;68&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;34&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;+&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;buttonIncrease_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;buttonDecrease&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;140&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;34&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;-&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;buttonDecrease_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;addCounterButton&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;614&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;31&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;Add Counter&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;addCounterButton_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;deleteCounterButton&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;716&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;31&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;Delete Counter&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">enabled</span>=<span style="color: #990000;">&quot;{numCounters &gt; 0}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;deleteCounterButton_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p><em><strong>MainView.mxml</strong></em> is the only file that sees some changes. Here we&#8217;ve added the logic to handle adding/removing new counters (<em><strong>addCounterButton_clickhandler</strong></em> method) and two new buttons <em><strong>Add Counter</strong></em> and <em><strong>Delete Counter</strong></em>, the latter being dynamically enabled/disabled, depending whether there are counters or not in the <em><strong>Tile</strong></em> (increments/decrements the <em><strong>numCounter</strong></em> variable).</p>
<p>Ok, <em>VERY</em> simple this time, but don&#8217;t worry, we&#8217;ll do better in the <a href="http://www.flexstuff.co.uk/2009/08/06/mate-examples-5-localeventmap/">next example: #5 LocalEventMap</a> so don&#8217;t give up on me!</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.flexstuff.co.uk%2F2009%2F08%2F06%2Fmate-examples-4-counters-created-dynamically%2F';
  addthis_title  = 'Mate+examples%3A+%234+Counters+created+dynamically';
  addthis_pub    = 'gillesguillemin';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>


<p>Related posts:<ol><li><a href='http://www.flexstuff.co.uk/2009/08/06/mate-examples-3-multiple-counters/' rel='bookmark' title='Permanent Link: Mate examples: #3 Multiple Counters'>Mate examples: #3 Multiple Counters</a> <small>This is the third of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/18/mate-examples-8-modules-example-pt-1/' rel='bookmark' title='Permanent Link: Mate examples: #8 Modules Example (pt 1)'>Mate examples: #8 Modules Example (pt 1)</a> <small>This is the eigth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/09/mate-examples-7-reset-countdown-pt-2/' rel='bookmark' title='Permanent Link: Mate examples: #7 Reset Countdown (pt 2)'>Mate examples: #7 Reset Countdown (pt 2)</a> <small>This is the seventh of a series of gradually more...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.flexstuff.co.uk/2009/08/06/mate-examples-4-counters-created-dynamically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mate examples: #3 Multiple Counters</title>
		<link>http://www.flexstuff.co.uk/2009/08/06/mate-examples-3-multiple-counters/</link>
		<comments>http://www.flexstuff.co.uk/2009/08/06/mate-examples-3-multiple-counters/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 11:02:45 +0000</pubDate>
		<dc:creator>gillesguillemin</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Mate Framework]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[London Flash Platform User Group]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[mxml]]></category>

		<guid isPermaLink="false">http://www.flexstuff.co.uk/?p=503</guid>
		<description><![CDATA[This is the third of a series of gradually more complex examples on how to use Mate.


Related posts:<ol><li><a href='http://www.flexstuff.co.uk/2009/08/06/mate-examples-4-counters-created-dynamically/' rel='bookmark' title='Permanent Link: Mate examples: #4 Counters created dynamically'>Mate examples: #4 Counters created dynamically</a> <small>This is the fourth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/18/mate-examples-8-modules-example-pt-1/' rel='bookmark' title='Permanent Link: Mate examples: #8 Modules Example (pt 1)'>Mate examples: #8 Modules Example (pt 1)</a> <small>This is the eigth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/06/mate-examples-5-localeventmap/' rel='bookmark' title='Permanent Link: Mate examples: #5 LocalEventMap'>Mate examples: #5 LocalEventMap</a> <small>This is the fifth of a series of gradually more...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>This blog post is related to <a href="http://www.flexstuff.co.uk/2009/08/05/my-lfpug-presentation-about-mate/" target="_blank">My LFPUG Presentation about Mate</a> blog post.</p>
<p>This is the third of a series of gradually more complex examples on how to use <em>Mate</em>. If you haven&#8217;t done it yet you should have a look first at <a href="http://www.flexstuff.co.uk/2009/08/05/mate-examples-1-a-very-basic-injectors-example/" target="_blank">our first example</a> and at <a href="http://www.flexstuff.co.uk/2009/08/05/mate-examples-2-databinding-and-eventhandlers/" target="_blank">our second one</a>.</p>
<p>And now let&#8217;s have a look on the demo (source is available by right-clicking on the demo after launching it):</p>
<div class="wp-caption aligncenter" style="width: 360px"><a class="lightview" title="#3 Multiple Counters :: Right-click to view the source. :: width: 1024, height: 768" href="http://flexstuff.co.uk/wp-content/uploads/examples/mate_lfpug/_Demo03%20-%20Multiple%20counters/Demo.swf"><img src="http://flexstuff.co.uk/wp-content/uploads/examples/mate_lfpug/_Demo03%20-%20Multiple%20counters/Mate_Example3.png" alt="Mate example" width="350" height="250" /></a><p class="wp-caption-text">#3 Multiple Counters (click to Launch)</p></div>
<p><span id="more-503"></span><br />
Now, instead of duplicating <em><strong>FirstCounter.mxml</strong></em> code into a useless <em><strong>SecondCounter.mxml</strong></em>, we are using only one generic class: <em><strong>Counter.mxml</strong></em>.</p>
<p><cite><br />
<h3>Demo #3: src/views/Counter.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;264&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;146&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title=<span style="color: #990000;">&quot;{counterTitle}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layout=<span style="color: #990000;">&quot;absolute&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CounterEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> globalAmount <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> amount <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _counterTitle <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;Counter Title&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> counterTitle<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> _counterTitle<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">set</span> counterTitle<span style="color: #000000;">&#40;</span>v<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _counterTitle = v<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> buttonIncrease_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">++</span>amount<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> CounterEvent<span style="color: #000000;">&#40;</span>CounterEvent<span style="color: #000066; font-weight: bold;">.</span>INCREASE_GLOBAL<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> buttonDecrease_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">--</span>amount<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> CounterEvent<span style="color: #000000;">&#40;</span>CounterEvent<span style="color: #000066; font-weight: bold;">.</span>DECREASE_GLOBAL<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;27&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;10&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Global Amount:&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;121&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;10&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{globalAmount}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;67&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;45&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Amount:&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;121&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;45&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{amount}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;buttonIncrease&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;68&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;72&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;+&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;buttonIncrease_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;buttonDecrease&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;140&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;72&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;-&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;buttonDecrease_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>We&#8217;ve also created a getter/setter counterTitle in order to dynamically change the component&#8217;s title (it extends the Panel component). Aside from that, it&#8217;s exactly the same code as the one you could find in the <em><strong>FirstCounter.mxml</strong></em> component of our <a href="http://www.flexstuff.co.uk/2009/08/05/mate-examples-2-databinding-and-eventhandlers/" target="_blank">second example</a>.</p>
<p>Let&#8217;s see check out now <em><strong>Demo.mxml</strong></em>:</p>
<p><cite><br />
<h3>Demo #3: src/Demo.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Application xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layout=<span style="color: #990000;">&quot;absolute&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; minWidth=<span style="color: #990000;">&quot;1024&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; minHeight=<span style="color: #990000;">&quot;768&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns<span style="color: #000066; font-weight: bold;">:</span>local=<span style="color: #990000;">&quot;*&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns<span style="color: #000066; font-weight: bold;">:</span>maps=<span style="color: #990000;">&quot;maps.*&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns<span style="color: #000066; font-weight: bold;">:</span>views=<span style="color: #990000;">&quot;views.*&quot;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>maps<span style="color: #000066; font-weight: bold;">:</span>MainEventMap<span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>views<span style="color: #000066; font-weight: bold;">:</span>MainView horizontalCenter=<span style="color: #990000;">&quot;0&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; verticalCenter=<span style="color: #990000;">&quot;0&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Application<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>It is now simplified, everything being now grouped inside a new <em><strong>MainView.mxml</strong></em> component:</p>
<p><cite><br />
<h3>Demo #3: src/views/MainView.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;860&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;600&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title=<span style="color: #990000;">&quot;MainView&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layout=<span style="color: #990000;">&quot;absolute&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlns<span style="color: #000066; font-weight: bold;">:</span>views=<span style="color: #990000;">&quot;views.*&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> globalAmount <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Global Amount:&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;300&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;21&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{globalAmount}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;396&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;21&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Tile <span style="color: #004993;">left</span>=<span style="color: #990000;">&quot;10&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">right</span>=<span style="color: #990000;">&quot;10&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">top</span>=<span style="color: #990000;">&quot;68&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">bottom</span>=<span style="color: #990000;">&quot;10&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>views<span style="color: #000066; font-weight: bold;">:</span>Counter counterTitle=<span style="color: #990000;">&quot;Counter 1&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>views<span style="color: #000066; font-weight: bold;">:</span>Counter counterTitle=<span style="color: #990000;">&quot;Counter 2&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>views<span style="color: #000066; font-weight: bold;">:</span>Counter counterTitle=<span style="color: #990000;">&quot;Counter 3&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>views<span style="color: #000066; font-weight: bold;">:</span>Counter counterTitle=<span style="color: #990000;">&quot;Counter 4&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Tile<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>We&#8217;ve added here a <em><strong>globalAmount</strong></em> variable along with the now well-known related labels. This way we can see that the global amount can be updated simultaneously at various level of the application.</p>
<p>We have also created a <em><strong>Tile</strong></em> and added four <em><strong>Counter</strong></em> components (manually for now, we&#8217;ll see later how to add them dynamically).</p>
<p>And where is the glue? As always, everything relies on the <em><strong>MainEventMap.mxml</strong></em>:</p>
<p><cite><br />
<h3>Demo #3: src/maps/MainEventMap.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventMap xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns<span style="color: #000066; font-weight: bold;">:</span>mate=<span style="color: #990000;">&quot;http://mate.asfusion.com/&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>Counter<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> views<span style="color: #000066; font-weight: bold;">.</span>MainView<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> managers<span style="color: #000066; font-weight: bold;">.</span>CounterManager<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CounterEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;{CounterEvent.INCREASE_GLOBAL}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>MethodInvoker generator=<span style="color: #990000;">&quot;{CounterManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;increaseGlobal&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;{CounterEvent.DECREASE_GLOBAL}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>MethodInvoker generator=<span style="color: #990000;">&quot;{CounterManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;decreaseGlobal&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors targets=<span style="color: #990000;">&quot;{[Counter, MainView]}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>PropertyInjector <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;{CounterManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sourceKey=<span style="color: #990000;">&quot;globalAmount&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;targetKey=<span style="color: #990000;">&quot;globalAmount&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventMap<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>As you can see, not much has changed since the last time. We have just replaced the <em><strong>target</strong></em> property of our <em><strong>Injectors</strong></em> by the <em><strong>target<span style="text-decoration: underline;">s</span></strong></em> property which accepts an array of views: <em><strong>MainView</strong></em> and <em><strong>Counter</strong></em>. And as <em><strong>Counter</strong></em> is repeated four times, the <em>four instances</em> will receive their update.</p>
<p>How easy is that?</p>
<p><a href="http://www.flexstuff.co.uk/?p=521" target="_self">Next example: #4 Counters created dynamically</a></p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.flexstuff.co.uk%2F2009%2F08%2F06%2Fmate-examples-3-multiple-counters%2F';
  addthis_title  = 'Mate+examples%3A+%233+Multiple+Counters';
  addthis_pub    = 'gillesguillemin';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>


<p>Related posts:<ol><li><a href='http://www.flexstuff.co.uk/2009/08/06/mate-examples-4-counters-created-dynamically/' rel='bookmark' title='Permanent Link: Mate examples: #4 Counters created dynamically'>Mate examples: #4 Counters created dynamically</a> <small>This is the fourth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/18/mate-examples-8-modules-example-pt-1/' rel='bookmark' title='Permanent Link: Mate examples: #8 Modules Example (pt 1)'>Mate examples: #8 Modules Example (pt 1)</a> <small>This is the eigth of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/06/mate-examples-5-localeventmap/' rel='bookmark' title='Permanent Link: Mate examples: #5 LocalEventMap'>Mate examples: #5 LocalEventMap</a> <small>This is the fifth of a series of gradually more...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.flexstuff.co.uk/2009/08/06/mate-examples-3-multiple-counters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mate examples: #2 Databinding and EventHandlers</title>
		<link>http://www.flexstuff.co.uk/2009/08/05/mate-examples-2-databinding-and-eventhandlers/</link>
		<comments>http://www.flexstuff.co.uk/2009/08/05/mate-examples-2-databinding-and-eventhandlers/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 12:06:04 +0000</pubDate>
		<dc:creator>gillesguillemin</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Mate Framework]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[London Flash Platform User Group]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[mxml]]></category>

		<guid isPermaLink="false">http://www.flexstuff.co.uk/?p=490</guid>
		<description><![CDATA[This is the second of a series of gradually more complex examples on how to use Mate. It's a fairly basic one.


Related posts:<ol><li><a href='http://www.flexstuff.co.uk/2009/08/06/mate-examples-3-multiple-counters/' rel='bookmark' title='Permanent Link: Mate examples: #3 Multiple Counters'>Mate examples: #3 Multiple Counters</a> <small>This is the third of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/05/mate-examples-1-a-very-basic-injectors-example/' rel='bookmark' title='Permanent Link: Mate examples: #1 A very basic injectors example'>Mate examples: #1 A very basic injectors example</a> <small>This is the first of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/06/mate-examples-5-localeventmap/' rel='bookmark' title='Permanent Link: Mate examples: #5 LocalEventMap'>Mate examples: #5 LocalEventMap</a> <small>This is the fifth of a series of gradually more...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>This blog post is related to <a href="http://www.flexstuff.co.uk/2009/08/05/my-lfpug-presentation-about-mate/" target="_blank">My LFPUG Presentation about Mate</a> blog post.</p>
<p>This is the second of a series of gradually more complex examples on how to use <em>Mate</em>. It&#8217;s still a fairly basic one and visually it looks just the same as <a href="http://www.flexstuff.co.uk/2009/08/05/mate-examples-1-a-very-basic-injectors-example/" target="_blank">our previous example</a>.</p>
<p>But let&#8217;s first have a look on the demo (source is available by right-clicking on the demo after launching it):</p>
<div class="wp-caption aligncenter" style="width: 360px"><a class="lightview" title="#2 Databinding and EventHandlers :: Right-click to view the source. :: width: 1024, height: 768" href="http://flexstuff.co.uk/wp-content/uploads/examples/mate_lfpug/_Demo02%20-%20Databinding%20and%20EventHandlers/Demo.swf"><img src="http://flexstuff.co.uk/wp-content/uploads/examples/mate_lfpug/_Demo02%20-%20Databinding%20and%20EventHandlers/Mate_example1.png" alt="Mate example" width="350" height="250" /></a><p class="wp-caption-text">#2 Databinding and EventHandlers (click to Launch)</p></div>
<p><span id="more-490"></span>Let&#8217;s have a look at <em><strong>FirstCounter.mxml</strong></em> (<em><strong>SecondCounter.mxml</strong></em> has the same content):</p>
<p><cite><br />
<h3>Demo #2: src/FirstCounter.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;264&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;146&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title=<span style="color: #990000;">&quot;First Counter&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layout=<span style="color: #990000;">&quot;absolute&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CounterEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> globalAmount <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> amount <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> buttonIncrease_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">++</span>amount<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> CounterEvent<span style="color: #000000;">&#40;</span>CounterEvent<span style="color: #000066; font-weight: bold;">.</span>INCREASE_GLOBAL<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> buttonDecrease_clickHandler<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">MouseEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">--</span>amount<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> CounterEvent<span style="color: #000000;">&#40;</span>CounterEvent<span style="color: #000066; font-weight: bold;">.</span>DECREASE_GLOBAL<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;27&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;10&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Global Amount:&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;121&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;10&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{globalAmount}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;67&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;45&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Amount:&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;121&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;45&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{amount}&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;buttonIncrease&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;68&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;72&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;+&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;buttonIncrease_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;buttonDecrease&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;140&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;72&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label=<span style="color: #990000;">&quot;-&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;buttonDecrease_clickHandler(event)&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Panel<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>Here the <em><strong>increaseGlobal</strong></em> and <em><strong>decreaseGlobal</strong></em> methods have disappeared and <em><strong>globalAmount</strong></em> is now <span style="text-decoration: underline;"><em><strong>public</strong></em></span> (which is important).</p>
<p>Actually, they haven&#8217;t completely disappeared: we&#8217;ve created a new class: <em><strong>CounterManager.as</strong></em></p>
<p><cite><br />
<h3>Demo #2: src/managers/CounterManager.as</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span> managers<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">EventDispatcher</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">IEventDispatcher</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> CounterManager <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">EventDispatcher</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> globalAmount <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> increaseGlobal<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">++</span>globalAmount<span style="color: #000066; font-weight: bold;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> decreaseGlobal<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">--</span>globalAmount<span style="color: #000066; font-weight: bold;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Here are our methods! Along with a <em><strong>bindable public globalAmount variable</strong></em> again&#8230;</p>
<p>Let&#8217;s check what has changed in our <em><strong>MainEventMap.mxml</strong></em>:</p>
<p><cite><br />
<h3>Demo #2: src/maps/MainEventMap.mxml</h3>
<p></cite></p>
<div class="codecolorer-container actionscript3 dawn" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span><br />
<span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventMap xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xmlns<span style="color: #000066; font-weight: bold;">:</span>mate=<span style="color: #990000;">&quot;http://mate.asfusion.com/&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> managers<span style="color: #000066; font-weight: bold;">.</span>CounterManager<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> Events<span style="color: #000066; font-weight: bold;">.</span>CounterEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;{CounterEvent.INCREASE_GLOBAL}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>MethodInvoker generator=<span style="color: #990000;">&quot;{CounterManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;increaseGlobal&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers <span style="color: #004993;">type</span>=<span style="color: #990000;">&quot;{CounterEvent.DECREASE_GLOBAL}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>MethodInvoker generator=<span style="color: #990000;">&quot;{CounterManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">method</span>=<span style="color: #990000;">&quot;decreaseGlobal&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventHandlers<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors <span style="color: #004993;">target</span>=<span style="color: #990000;">&quot;{FirstCounter}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>PropertyInjector <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;{CounterManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sourceKey=<span style="color: #990000;">&quot;globalAmount&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;targetKey=<span style="color: #990000;">&quot;globalAmount&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors <span style="color: #004993;">target</span>=<span style="color: #990000;">&quot;{SecondCounter}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;</span>mate<span style="color: #000066; font-weight: bold;">:</span>PropertyInjector <span style="color: #004993;">source</span>=<span style="color: #990000;">&quot;{CounterManager}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sourceKey=<span style="color: #990000;">&quot;globalAmount&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;targetKey=<span style="color: #990000;">&quot;globalAmount&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>Injectors<span style="color: #000066; font-weight: bold;">&gt;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">&lt;/</span>mate<span style="color: #000066; font-weight: bold;">:</span>EventMap<span style="color: #000066; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>There are new tags: first <em><strong>EventHandlers</strong></em>: as previously our <em><strong>ListenerInjectors</strong></em>, they are listening to one specific event type then invoke a specific method inside our new <em><strong>CounterManager.as</strong></em> class using the tag <em><strong>MethodInvoker</strong></em>.<br />
Another tag has appeared inside our Injectors tags: <em><strong>PropertyInjector</strong></em> which tie together the public variable <em><strong>globalAmount</strong></em> of <em><strong>CounterManager</strong></em> and both <em>counters</em>. Here <em><strong>CounterManager</strong></em> acts as a <em>model</em> shared by the <em>counters</em>. When the <em>model</em> is updated, the <em>counters</em> are automatically updated as well.</p>
<p><a href="http://www.flexstuff.co.uk/2009/08/06/mate-examples-3-multiple-counters/">Next example: #3 Multiple Counters</a></p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.flexstuff.co.uk%2F2009%2F08%2F05%2Fmate-examples-2-databinding-and-eventhandlers%2F';
  addthis_title  = 'Mate+examples%3A+%232+Databinding+and+EventHandlers';
  addthis_pub    = 'gillesguillemin';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>


<p>Related posts:<ol><li><a href='http://www.flexstuff.co.uk/2009/08/06/mate-examples-3-multiple-counters/' rel='bookmark' title='Permanent Link: Mate examples: #3 Multiple Counters'>Mate examples: #3 Multiple Counters</a> <small>This is the third of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/05/mate-examples-1-a-very-basic-injectors-example/' rel='bookmark' title='Permanent Link: Mate examples: #1 A very basic injectors example'>Mate examples: #1 A very basic injectors example</a> <small>This is the first of a series of gradually more...</small></li>
<li><a href='http://www.flexstuff.co.uk/2009/08/06/mate-examples-5-localeventmap/' rel='bookmark' title='Permanent Link: Mate examples: #5 LocalEventMap'>Mate examples: #5 LocalEventMap</a> <small>This is the fifth of a series of gradually more...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.flexstuff.co.uk/2009/08/05/mate-examples-2-databinding-and-eventhandlers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
