<?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>blog</title>
	<atom:link href="http://www.newtonflash.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.newtonflash.com/blog</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Tue, 27 Sep 2011 12:59:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>Misconceptions about flash</title>
		<link>http://www.newtonflash.com/blog/flash/misconceptions-about-flash/</link>
		<comments>http://www.newtonflash.com/blog/flash/misconceptions-about-flash/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 12:59:55 +0000</pubDate>
		<dc:creator>newton</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.newtonflash.com/blog/?p=359</guid>
		<description><![CDATA[Looking at blogs, who have transformed from flash lover to html5 lovers have raised a lot of concerns that has proved flash to be annoying for future use. When it&#8217;s good to have new options for doing same thing that &#8230; <a href="http://www.newtonflash.com/blog/flash/misconceptions-about-flash/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Looking at blogs, who have transformed from flash lover to html5 lovers have raised a lot of concerns that has proved flash to be annoying for future use. When it&#8217;s good to have new options for doing same thing that flash did for last several years, I find people to have misunderstood flash till to-day. Let me point out some most frequently used terms to make flash heads down.</p>
<p><strong>1. Extra bandwidth / higher file size</strong></p>
<p>Personally I have never designed any thing that is heavier than it it were made with html. Instead I have used flash to reduce file size up to 1/20th of counter part image replacement.</p>
<p>I do agree in some cases flash file size are heavy. There are two things to conclude in this case:</p>
<p>a. The flash file contains heavy animation/video or high resolution graphics ( So this is obvious to have large size<strong> &#8211; </strong>there is no escape )</p>
<p>b. The designer/animator/programmer has less knowledge of using resources properly. ( This can happen to html programmers to also)</p>
<p><strong>2. Progress bars</strong></p>
<p>Most of the people hate progress bars. I do also. I never use a progress bar, or never let the user wait with a blank screen for more than 5secs. Progressive loading makes this happen. The total credit/blame goes to the developer. Yet some time I find progress bars so interesting that you get a feeling of worthiness of waiting a while.</p>
<p><strong>3. Flash overrides &#8220;no popup window&#8221; preference</strong></p>
<p>Flash never does it. It&#8217;s the owner of the application who needs it to be like that. Those stupid owners are like you and me, love new things, hate when they get old.</p>
<p><strong>4. Jacob Neilson&#8217;s alertbox &#8220;flash: 99% Bad&#8221;</strong></p>
<p>Most of us respect Jacob for his guidelines, but the above statement was given in the year 2000, when flash was infant. How can those statement hold good today?</p>
<p><strong>5. Non-standard interface</strong></p>
<p>It&#8217;s good to live with standards, but we can never live with standard creative mind. Standard blocks creativity &#8211; your thinking process. Flash was the first technology to provide personalization- if I need scroll bar to scroll in a semicircular path then I can make it possible without much coding.</p>
<p>I do agree to use standard interface, but some times I feel school dress code are really boring.</p>
<p><strong>6. Breaks web standards<br />
</strong></p>
<p>I don&#8217;t say it to be break of web-standard. I say it control over your content. When you don&#8217;t want your image to be saved, your text should not be copied, your video should not be downloaded, flash gives you more power to achieve this. If you want your users to copy/paste/cut text, it&#8217;s also possible- only you need to tell flash to give precise control over them.</p>
<p><strong>7. Without Flash you can&#8217;t access site</strong></p>
<p>I wish I could see web pages without a browser. I wish I could play God of war without buying a PS3.</p>
<p>In ideal development conditions, there should be html information for graceful degradation in absence of flash. But every programmer does it- because they don&#8217;t have such requirements.</p>
<p>Considering practical cases, it&#8217;s the wish of  the site&#8217;s owner who knows what he has to show to the world.</p>
<p><strong>8. SEO is difficult for flash contents</strong></p>
<p>I never find it to be a difficult issue. Content can be made accessible to search spiders with a little care. If your content is more of text based, it should not be made with flash. Flash is never meant to be the gateway of heavy textual content. It&#8217;s a way to showcase your presence. Do we wish to have seo for the text content in a video file?- or how we achieve if we had to do it?</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.newtonflash.com/blog/flash/misconceptions-about-flash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why people avoid buying adobe license in india?</title>
		<link>http://www.newtonflash.com/blog/technology/why-people-avoid-buying-adobe-license-in-india/</link>
		<comments>http://www.newtonflash.com/blog/technology/why-people-avoid-buying-adobe-license-in-india/#comments</comments>
		<pubDate>Thu, 21 Apr 2011 14:52:55 +0000</pubDate>
		<dc:creator>newton</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.newtonflash.com/blog/?p=349</guid>
		<description><![CDATA[It has been 8 years I have been using a pc &#38; a mac since last year. I have never spent a single rupee on any of the software(humm my mac was already having the OS- so exclude it and &#8230; <a href="http://www.newtonflash.com/blog/technology/why-people-avoid-buying-adobe-license-in-india/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It has been 8 years I have been using a pc &amp; a mac since last year. I have never spent a single rupee on any of the software(humm my mac was already having the OS- so exclude it and also the softwares that I use in office. ). I have been using a lot of software including Flash, Flex, Photoshop, windows xp, MS Word, Acrobat pro and many more. I know it takes a lot to create softwares like these, lot of coding, debugging, marketing and god knows what adobe, microsoft and other giant companies does to sale their products.</p>
<p>Now the question is why don&#8217;t I buy them? Do not I earn enough money to buy them? Or software companies want some users like us for their popularity?</p>
<p>I got to ask my friends and colleagues about it and took the reviews, there were some interesting reasons  came out. Here are some commonly questions/ statements given:</p>
<p>1. Why should I buy if I get the serial for free by searching net?</p>
<p>2. Oh, the cost of the software are too much.  Photoshop more than 25k INR, same for flash.</p>
<p>3. What is the benifit of getting genuine software( just getting updates?)</p>
<p>4. Even if I buy a version of the software, the next version does not take 6 months to come out. While the original version is not stable, I have to update to new for which again I have to pay at least 1/3rd of the amount in most of the cases.</p>
<p>5. Adobe does not ask us for money!!!</p>
<p>6. For home users it should be free&#8230; if it&#8217;s not free no matter, we have got free.</p>
<p>7. How much I earn to pay this large amount for a single software?</p>
<p>8. My friends will laugh on me if I buy a license. They have got it for free.</p>
<p>9. It&#8217;s a marketing strategy to get addictive.</p>
<p>10. My vendor has given it .. I dont know about license.</p>
<p>&#8230;&#8230;</p>
<p>What about me? my answer is: &#8220;if I calculate cost of all the softwares I use , it would be nearly 250000 INR, and if I spend this much I have to stop taking my food- I can not afford that. Again frequent changes in versions of the softwares are crazy. &#8220;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.newtonflash.com/blog/technology/why-people-avoid-buying-adobe-license-in-india/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>first blog</title>
		<link>http://www.newtonflash.com/blog/social/first-blog/</link>
		<comments>http://www.newtonflash.com/blog/social/first-blog/#comments</comments>
		<pubDate>Wed, 13 Apr 2011 10:24:32 +0000</pubDate>
		<dc:creator>Satinder</dc:creator>
				<category><![CDATA[Social Articles]]></category>

		<guid isPermaLink="false">http://www.newtonflash.com/blog/?p=347</guid>
		<description><![CDATA[This is my first blog. so i am happy.]]></description>
			<content:encoded><![CDATA[<p>This is my first blog. so i am happy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.newtonflash.com/blog/social/first-blog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prevent XML caching problem</title>
		<link>http://www.newtonflash.com/blog/as3/prevent-xml-caching-problem/</link>
		<comments>http://www.newtonflash.com/blog/as3/prevent-xml-caching-problem/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 15:44:00 +0000</pubDate>
		<dc:creator>newton</dc:creator>
				<category><![CDATA[AS3]]></category>

		<guid isPermaLink="false">http://www.newtonflash.com/blog/?p=327</guid>
		<description><![CDATA[When load xml files by URLLoaders, they are often cached by the browsers and do flash is unable to display the updated data. This is a very common problem &#38; I always find this some where around me once in &#8230; <a href="http://www.newtonflash.com/blog/as3/prevent-xml-caching-problem/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When load xml files by URLLoaders, they are often cached by the browsers and do flash is unable to display the updated data. This is a very common problem &amp; I always find this some where around me once in a month or so. Even my friends do face the same issue.</p>
<p>There is a very simple solution to this cute little problem. When ever you are loading by URLLoader.load method just add a time stamp to the URLRequest and everything will work fine except you might get some error message while compiling the swf.(&#8220;<span class="highlight"><em>Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL&#8221;</em></span>). You can ignore it and continue publishing. On the web it will not throw any such error- believe me.</p>
<p>Here is the little rabbit:</p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li>
<div  class="de1"><span class="kw2">var</span> xmlPath:<span class="kw3">String</span>=<span class="st0">&quot;replaceYourXMLPathHere.xml&quot;</span></div>
</li>
<li>
<div  class="de1"><span class="kw2">var</span> urlReq:URLRequest = <span class="kw2">new</span> URLRequest<span class="br0">&#40;</span>xmlPath+<span class="st0">&quot;?time=&quot;</span> + <span class="kw2">new</span> <span class="kw3">Date</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="kw3">getTime</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Let me know if the readers have some other idea..</p>
]]></content:encoded>
			<wfw:commentRss>http://www.newtonflash.com/blog/as3/prevent-xml-caching-problem/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>AS3 Event Handling- part 6</title>
		<link>http://www.newtonflash.com/blog/flash/as3-event-handling-part-6/</link>
		<comments>http://www.newtonflash.com/blog/flash/as3-event-handling-part-6/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 02:50:31 +0000</pubDate>
		<dc:creator>newton</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.newtonflash.com/blog/?p=308</guid>
		<description><![CDATA[In this small part of action script event handling we will learn about one of the effective event handling technique that can help us to dispose our objects towards garbage collection( I will be writing about this interesting topic soon.)- &#8230; <a href="http://www.newtonflash.com/blog/flash/as3-event-handling-part-6/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In this small part of action script event handling we will learn about one of the effective event handling technique that can help us to dispose our objects towards <strong>garbage collection</strong>( I will be writing about this interesting topic soon.)- in other way we can make efficient application without causing any <strong>memory leaking</strong>. The rule of thumb is to make use of <em>removeListener</em> and remove any event listener attached to some object before you remove or delete it by either <em>removeChild</em> or <em>delete</em> method. </p>
<p>When ever we create objects and attach events with them, events go on executing if that object resides in memory. Let me give you one small example: </p>
<p>Create a movieClip instance  on the stage and give it a name ( <em>foo_mc </em> in my example). Now on the first frame open action panel and write down code for ENTER_FRAME event of that movielClip and then remove the <em>foo_mc</em>. The example code is given below:</p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li>
<div  class="de1">foo_mc.addEventListener(Event.ENTER_FRAME, trackObject);</div>
</li>
<li>
<div  class="de1">&nbsp;</div>
</li>
<li>
<div  class="de1">function trackObject(evt:Event){</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; removeChild(foo_mc);</div>
</li>
<li>
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; trace(&quot;I am executing&quot;);</div>
</li>
<li>
<div  class="de1">}</div>
</li>
</ol>
</div>
<p>When you execute this code, even if you have removed the child by <em>removeChild</em> method, it will not be removed from memory and <em>trackObject</em> function will be executing. Even if you add <em>foo_mc=null, </em> it will still execute the function. The reason is <em>foo_mc</em> is not deleted completely from memory at this point of time. It may be removed latter some time when garbage collector will see <em>foo_mc</em> does not have any reference to other objects. Here this loop of enter frame will go on because <em>foo_</em><em>mc</em> has a listener to the enter frame event. One thing you should always remember that <strong>removeChild() never removes display objects from memory, </strong>it only removes from it&#8217;s parents display list. If this situation arises then it&#8217;s always wise to remove the event listener attached to it before you remove it from the display list. Also it&#8217;s a good programming practice to make the methods of a n object to null when not required in future so that they won&#8217;t eat up some memory. This case grow bigger when there are conditions for looping. So a better code may look like this:</p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li>
<div  class="de1">foo_mc.addEventListener(Event.ENTER_FRAME, trackObject);</div>
</li>
<li>
<div  class="de1">&nbsp;</div>
</li>
<li>
<div  class="de1">function trackObject(evt:Event){</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; foo_mc.removeEventListener(Event.ENTER_FRAME, trackObject);</div>
</li>
<li>
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; removeChild(foo_mc);</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; trace(&quot;I am executing&quot;);</div>
</li>
<li>
<div  class="de1">}</div>
</li>
</ol>
</div>
<p>If you feel some thing different about this, please share with me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.newtonflash.com/blog/flash/as3-event-handling-part-6/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>AS3 Event Handling- part 5</title>
		<link>http://www.newtonflash.com/blog/as3/as3-event-handling-part-5/</link>
		<comments>http://www.newtonflash.com/blog/as3/as3-event-handling-part-5/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 12:33:01 +0000</pubDate>
		<dc:creator>newton</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.newtonflash.com/blog/?p=296</guid>
		<description><![CDATA[Previous part of AS3 Event Handling series was about creating custom event class. In this part we will look at the one of the mostly unused parameters in addEventListener method handler.  addEventListener is the method used to add an listener &#8230; <a href="http://www.newtonflash.com/blog/as3/as3-event-handling-part-5/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.newtonflash.com/blog/2009/04/08/as3-event-handling-part-4/">Previous part</a> of AS3 Event Handling series was about creating custom event class. In this part we will look at the one of the mostly unused parameters in <em>addEventListener</em> method handler. </p>
<p><em>addEventListener </em>is the method used to add an listener to an object for a specified event. Hence we usually pass two parameters ( first one is the event name and second event handler name) and everything works perfectly. But if you need more control over the event flow you may be interested in the other parameters available. The other three parameters are <em>useCapture, priority </em>&amp;<em> use<span class="searchhilite">WeakReference.  <span style="font-style: normal;"> We will discuss about the first one in this part.</span></span></em></p>
<p><strong>useCapture</strong></p>
<p>This parameter tells about processing of event object in the phases of the event propagation. The default value is false, means event object can provide information about the target phase and the bubbling phase and not about the capture phase.</p>
<p>To understand the exact behaviour let&#8217;s create one small flash file and write some code. Open an AS3 flash document and create one big rectanglular movieclip and name is as &#8220;<em>parent_mc</em>&#8221; and a smaller rectangular movieclip inside it and name is as &#8220;<em>child_mc</em>&#8220;. Now select first frame and write the code. <a href="http://www.newtonflash.com/downloads/blog/as3_event_handling_part_5.zip">Download</a> the file to see what the trace statements say about mouse down event.</p>
<div class="dean_ch" style="white-space: nowrap; height: 450px;">
<ol>
<li>
<div  class="de1">parent_mc.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">MOUSE_DOWN</span>, truePhase, <span class="kw2">true</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1">parent_mc.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">MOUSE_DOWN</span>, falsePhase, <span class="kw2">false</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1">&nbsp;</div>
</li>
<li>
<div  class="de1"><span class="kw2">function</span> truePhase<span class="br0">&#40;</span>evt:MouseEvent<span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span></div>
</li>
<li>
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&quot;=====================use capture true===================================&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">switch</span><span class="br0">&#40;</span>evt.<span class="me1">eventPhase</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">case</span> EventPhase.<span class="me1">BUBBLING_PHASE</span>:</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&quot;BUBBLING_PHASE&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span>;</div>
</li>
<li>
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">case</span> EventPhase.<span class="me1">CAPTURING_PHASE</span>:</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; evt.<span class="me1">stopImmediatePropagation</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&quot;CAPTURING_PHASE&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">case</span> EventPhase.<span class="me1">AT_TARGET</span>:</div>
</li>
<li>
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&quot;AT_TARGET&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li>
<div  class="de1">&nbsp;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&quot;currenttarget: &quot;</span> +evt.<span class="me1">currentTarget</span>.<span class="kw3">name</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&quot;target: &nbsp; &nbsp; &nbsp; &nbsp;&quot;</span>+evt.<span class="kw3">target</span>.<span class="kw3">name</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1"><span class="br0">&#125;</span></div>
</li>
<li>
<div  class="de1">&nbsp;</div>
</li>
<li>
<div  class="de1"><span class="kw2">function</span> falsePhase<span class="br0">&#40;</span>evt:MouseEvent<span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&quot;=====================use capture false===================================&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">switch</span><span class="br0">&#40;</span>evt.<span class="me1">eventPhase</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">case</span> EventPhase.<span class="me1">BUBBLING_PHASE</span>:</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&quot;BUBBLING_PHASE&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">case</span> EventPhase.<span class="me1">CAPTURING_PHASE</span>:</div>
</li>
<li>
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&quot;CAPTURING_PHASE&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">case</span> EventPhase.<span class="me1">AT_TARGET</span>:</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&quot;AT_TARGET&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span>;</div>
</li>
<li>
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li>
<div  class="de1">&nbsp;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&quot;currenttarget: &quot;</span> +evt.<span class="me1">currentTarget</span>.<span class="kw3">name</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&quot;target: &nbsp; &nbsp; &nbsp; &nbsp;&quot;</span>+evt.<span class="kw3">target</span>.<span class="kw3">name</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>There are two event handlers that handle the mouse down event, it&#8217;s because if we set <em>useCapture</em> true then we wont be able to catch the target &amp; bubbling phase. So in two event handlers will handle the event with <em>useCapture</em> true and false respectively. When you down your mouse on the bigger rectangle, you can only see the target as parent_mc and in target phase of propagation. This is because there is no child element under the mouse pointer.  Notice that I have added evt.stopImmediatePropagation(); in the first event handler in second switch statement, this blocks further propagation of event and do not let the second event handler get execute. The event object stops navigation. You can see the results when you click the inner child_mc in this example. You can only be able to see<br />
<span class="highlight">=====================use capture true===================================<br />
CAPTURING_PHASE<br />
currenttarget: parent_mc<br />
target:        child_mc</span></p>
<p>If you uncomment that line then you will be able to see the events fired in bubbling phase also. So uncomment it and look at the results. You will see:<br />
<span class="highlight">=====================use capture true===================================<br />
CAPTURING_PHASE<br />
currenttarget: parent_mc<br />
target:        child_mc<br />
=====================use capture false===================================<br />
BUBBLING_PHASE<br />
currenttarget: parent_mc<br />
target:        child_mc</span></p>
<p>This tells us one good logic to control our events when we have to control the event flow while working with nested display objects.</p>
<p><a href="http://www.newtonflash.com/downloads/blog/as3_event_handling_part_5.zip">Click here</a> to download the example file.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.newtonflash.com/blog/as3/as3-event-handling-part-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3 Event Handling- part 4</title>
		<link>http://www.newtonflash.com/blog/uncategorized/as3-event-handling-part-4/</link>
		<comments>http://www.newtonflash.com/blog/uncategorized/as3-event-handling-part-4/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 05:46:25 +0000</pubDate>
		<dc:creator>newton</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.newtonflash.com/blog/?p=278</guid>
		<description><![CDATA[In the previous part we discussed about the event propagation. In this part we will look for creating a custom event class.  The need of creating a custom event class comes when you have to put your event system more systematic &#8230; <a href="http://www.newtonflash.com/blog/uncategorized/as3-event-handling-part-4/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In the <a href="http://www.newtonflash.com/blog/2009/03/30/as3-event-handling-part-3/">previous part</a> we discussed about the event propagation. In this part we will look for creating a<strong> custom event class</strong>. </p>
<p>The need of creating a custom event class comes when you have to put your event system more systematic and comprehensive. Let me give one example where you might need to have your won event class where you can define your event names, customize it to get values of the event related objects and use it with simplicity similar to inbuilt event classes. We are going to build a confirmation control box where we will have three buttons with labels <em>&#8216;&#8221;</em>Yes&#8221; , &#8220;No&#8221;, &#8220;Cancel&#8221;.<em> </em> We might have other type of utility boxes that have either of these three kind of controls or combination of two or a single control( alert windows). </p>
<p>For the above example let&#8217;s create a small project with flex builder and create a small custom component called ConfirmationBox. Put three buttons labeled as per required. And here is the similar code. that you may write for your self.</p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li>
<div  class="de1">&lt;?<span class="kw3">xml</span> <span class="kw3">version</span>=<span class="st0">&quot;1.0&quot;</span> encoding=<span class="st0">&quot;utf-8&quot;</span>?&gt;</div>
</li>
<li>
<div  class="de1">&lt;mx:Canvas xmlns:mx=<span class="st0">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span class="kw3">width</span>=<span class="st0">&quot;400&quot;</span> <span class="kw3">height</span>=<span class="st0">&quot;100&quot;</span>&gt;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &lt;mx:<span class="kw3">Button</span> x=<span class="st0">&quot;175&quot;</span> y=<span class="st0">&quot;68&quot;</span> label=<span class="st0">&quot;Yes&quot;</span> click=<span class="st0">&quot;yes()&quot;</span>/&gt;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &lt;mx:<span class="kw3">Button</span> x=<span class="st0">&quot;248&quot;</span> y=<span class="st0">&quot;68&quot;</span> label=<span class="st0">&quot;No&quot;</span> click=<span class="st0">&quot;no()&quot;</span>/&gt;</div>
</li>
<li>
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &lt;mx:<span class="kw3">Button</span> x=<span class="st0">&quot;321&quot;</span> y=<span class="st0">&quot;68&quot;</span> label=<span class="st0">&quot;Cancel&quot;</span> click=<span class="st0">&quot;cancel()&quot;</span>/&gt;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &lt;mx:HRule x=<span class="st0">&quot;10&quot;</span> y=<span class="st0">&quot;54&quot;</span> <span class="kw3">width</span>=<span class="st0">&quot;380&quot;</span> <span class="kw3">height</span>=<span class="st0">&quot;1&quot;</span>/&gt;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &lt;mx:<span class="kw3">Text</span> x=<span class="st0">&quot;31&quot;</span> y=<span class="st0">&quot;10&quot;</span> <span class="kw3">text</span>=<span class="st0">&quot;Are you sure you want to quit?&quot;</span> <span class="kw3">width</span>=<span class="st0">&quot;359&quot;</span> <span class="kw3">height</span>=<span class="st0">&quot;41&quot;</span> fontSize=<span class="st0">&quot;17&quot;</span> fontFamily=<span class="st0">&quot;Arial&quot;</span> fontWeight=<span class="st0">&quot;bold&quot;</span>/&gt;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &lt;mx:Script&gt;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;!<span class="br0">&#91;</span>CDATA<span class="br0">&#91;</span></div>
</li>
<li>
<div class="de2">&nbsp;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> cancel<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//TODO</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> no<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span></div>
</li>
<li>
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//TODO</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> yes<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//TODO</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li>
<div class="de2">&nbsp;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#93;</span><span class="br0">&#93;</span>&gt;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &lt;/mx:Script&gt;</div>
</li>
<li>
<div  class="de1">&lt;/mx:Canvas&gt;</div>
</li>
</ol>
</div>
<p>Each button has separate click handlers and we shall write some code so that our component can dispatch some custom event that we are soon going to create.  Generally we subclass the already existing flash.events.Event class to readily avail all the basic methods and properties of an event class. Now we shall create a event class called &#8220;WindowControlEvent&#8221; which will extends Event class of flash.events package. Add three string constants to denote the event names before the constructor. And your class will look like below.</p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li>
<div  class="de1">package</div>
</li>
<li>
<div  class="de1"><span class="br0">&#123;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">events</span>.<span class="me1">Event</span>;</div>
</li>
<li>
<div  class="de1">&nbsp;</div>
</li>
<li>
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">class</span> WindowControlEvent <span class="kw3">extends</span> Event</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw3">static</span> const YES:<span class="kw3">String</span>=<span class="st0">&quot;yes&quot;</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw3">static</span> const NO:<span class="kw3">String</span>=<span class="st0">&quot;no&quot;</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw3">static</span> const CANCEL:<span class="kw3">String</span>=<span class="st0">&quot;cancel&quot;</span>;</div>
</li>
<li>
<div class="de2">&nbsp;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> WindowControlEvent<span class="br0">&#40;</span><span class="kw3">type</span>:<span class="kw3">String</span>, bubbles:<span class="kw3">Boolean</span>=<span class="kw2">false</span>, cancelable:<span class="kw3">Boolean</span>=<span class="kw2">false</span><span class="br0">&#41;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//TODO: implement function</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">super</span><span class="br0">&#40;</span><span class="kw3">type</span>, bubbles, cancelable<span class="br0">&#41;</span>;</div>
</li>
<li>
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li>
<div  class="de1">&nbsp;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li>
<div  class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Declaring the constants with uppercase makes it clearer to avoid typing error. We can now attach this event class to some object with addEventListener method. Ex: objectName.addEventListener(WindowControlEvent.YES, eventHandler).That&#8217;s it for a very basic custom event class. Now let&#8217;s use it.</p>
<p>In the small application that we wrote before lets dispatch the events in the three event handlers.We have to dispatch a new <em>WindowControlEvent</em> and pass the event name (&#8220;cancel&#8221;, &#8220;no&#8221; or &#8220;yes&#8221;) by the constants defined for them.</p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li>
<div  class="de1">&lt;mx:Script&gt;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &lt;!<span class="br0">&#91;</span>CDATA<span class="br0">&#91;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> cancel<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatchEvent<span class="br0">&#40;</span><span class="kw2">new</span> WindowControlEvent<span class="br0">&#40;</span>WindowControlEvent.<span class="me1">CANCEL</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> no<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatchEvent<span class="br0">&#40;</span><span class="kw2">new</span> WindowControlEvent<span class="br0">&#40;</span>WindowControlEvent.<span class="me1">NO</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> yes<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span></div>
</li>
<li>
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatchEvent<span class="br0">&#40;</span><span class="kw2">new</span> WindowControlEvent<span class="br0">&#40;</span>WindowControlEvent.<span class="me1">YES</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#93;</span><span class="br0">&#93;</span>&gt;</div>
</li>
<li>
<div  class="de1">&lt;/mx:Script&gt;</div>
</li>
</ol>
</div>
<p>Now let&#8217;s use this in our application and capture the events.</p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li>
<div  class="de1">&lt;?<span class="kw3">xml</span> <span class="kw3">version</span>=<span class="st0">&quot;1.0&quot;</span> encoding=<span class="st0">&quot;utf-8&quot;</span>?&gt;</div>
</li>
<li>
<div  class="de1">&lt;mx:WindowedApplication xmlns:mx=<span class="st0">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span class="st0">&quot;absolute&quot;</span> xmlns:local=<span class="st0">&quot;*&quot;</span> applicationComplete=<span class="st0">&quot;init()&quot;</span>&gt;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &lt;local:ConfirmationBox id=<span class="st0">&quot;confBox&quot;</span>&gt;</div>
</li>
<li>
<div  class="de1">&nbsp;</div>
</li>
<li>
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &lt;/local:ConfirmationBox&gt;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &lt;mx:Script&gt;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;!<span class="br0">&#91;</span>CDATA<span class="br0">&#91;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> mx.<span class="me1">controls</span>.<span class="me1">Alert</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> init<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span></div>
</li>
<li>
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; confBox.<span class="me1">addEventListener</span><span class="br0">&#40;</span>WindowControlEvent.<span class="me1">YES</span>, saveAndExit<span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; confBox.<span class="me1">addEventListener</span><span class="br0">&#40;</span>WindowControlEvent.<span class="me1">NO</span>, dontSaveAndExit<span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; confBox.<span class="me1">addEventListener</span><span class="br0">&#40;</span>WindowControlEvent.<span class="me1">CANCEL</span>, stayBack<span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li>
<div  class="de1">&nbsp;</div>
</li>
<li>
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> stayBack<span class="br0">&#40;</span>evt:WindowControlEvent<span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Alert.<span class="kw3">show</span><span class="br0">&#40;</span><span class="st0">&quot;stayback&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li>
<div  class="de1">&nbsp;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> dontSaveAndExit<span class="br0">&#40;</span>evt:WindowControlEvent<span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span></div>
</li>
<li>
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Alert.<span class="kw3">show</span><span class="br0">&#40;</span><span class="st0">&quot;dontSaveAndExit&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li>
<div  class="de1">&nbsp;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> saveAndExit<span class="br0">&#40;</span>evt:WindowControlEvent<span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Alert.<span class="kw3">show</span><span class="br0">&#40;</span><span class="st0">&quot;saveAndExit&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li>
<div  class="de1">&nbsp;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#93;</span><span class="br0">&#93;</span>&gt;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &lt;/mx:Script&gt;</div>
</li>
<li>
<div  class="de1">&lt;/mx:WindowedApplication&gt;</div>
</li>
<li>
<div class="de2">&nbsp;</div>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.newtonflash.com/blog/uncategorized/as3-event-handling-part-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multiple tweening problem</title>
		<link>http://www.newtonflash.com/blog/as3/multiple-tweening-problem/</link>
		<comments>http://www.newtonflash.com/blog/as3/multiple-tweening-problem/#comments</comments>
		<pubDate>Sat, 04 Apr 2009 06:30:07 +0000</pubDate>
		<dc:creator>newton</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.newtonflash.com/blog/?p=270</guid>
		<description><![CDATA[While developing a multi player poker game I got strange problems with tweening using fl.transition.Tween class. There were 18 cards to be distributed among 9 players in sequence and with 100ms interval. I put them in a timer and fired &#8230; <a href="http://www.newtonflash.com/blog/as3/multiple-tweening-problem/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>While developing a multi player poker game I got strange problems with tweening using fl.transition.Tween class. There were 18 cards to be distributed among 9 players in sequence and with 100ms interval. I put them in a timer and fired tweens at each timer event. I was writing the tweening code inside a method and adding event listeners to capture the finish event of the tween event. Problems that raised by this process were:</p>
<p><strong>Problems:</strong></p>
<p>1. <em>Sometimes cards hangup while distribution.</em></p>
<p>2. <em>Cards could not reach the exact location specified.</em></p>
<p>In other words the tween freezes on the way. </p>
<p>This kind of problem arises mostly in the following cases:</p>
<p>1.<em> Tweening multiple objects either synchronously or asynchronously by using local variables to handle tween events.</em></p>
<p>2.<em> Tweening multiple properties of an object and adding event to one of them. ex:</em></p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li>
<div  class="de1"><span class="kw2">var</span> tweenObj:Tween=<span class="kw2">new</span> Tween<span class="br0">&#40;</span>targetClip, <span class="st0">&quot;x&quot;</span>,&#8230;.<span class="me1">other</span> params&#8230;<span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1"><span class="kw2">new</span> Tween<span class="br0">&#40;</span>targetClip,<span class="st0">&quot;y&quot;</span>,&#8230;..<span class="me1">other</span> params&#8230;<span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1">tweenObj.<span class="me1">addEventListener</span><span class="br0">&#40;</span>TweenEvent.<span class="me1">MOTION_FINISH</span>, eventHandler<span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Note: I have added event listener to the <em>tweenObj</em>  which modifies the &#8216;x&#8217; property of the<em> </em><em>targetClip</em>.</p>
<p><strong>Reason:</strong></p>
<p>The first problem arises because of garbage collection of the tween objects as because they are declared as local variables(variables declared within a method). So in the way of transition/transformation the tween is dumped to garbage area and tween stops. This case is not a regular case so can not be reproducible every time(or I might not have understand it well enough the exact time after which tween object looses its status).</p>
<p><strong></strong>For the second problem when event handlers are created for the tween object that is declared first, other properties may not be able to finish their motion when <em>MOTION_FINISH </em>is fired by the tween object. If the object is disabled by this event, then other properties may not complete their transformations and freeze.</p>
<p><strong>Solutions:</strong></p>
<p>To prevent objects from garbage collection we need to declare the tween objects in some global variables and apply them inside methods. Here is the example:</p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li>
<div  class="de1"><span class="kw3">private</span> <span class="kw2">var</span> _tween:Tween;</div>
</li>
<li>
<div  class="de1">&nbsp;</div>
</li>
<li>
<div  class="de1"><span class="kw3">private</span> <span class="kw2">function</span> createTween<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; _tween=<span class="kw2">new</span> Tween<span class="br0">&#40;</span>clip, <span class="st0">&quot;x&quot;</span>, Elastic.<span class="me1">easeOut</span>, <span class="nu0">0</span>, <span class="nu0">300</span>, <span class="nu0">3</span>, <span class="kw2">true</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div class="de2">&nbsp; &nbsp; &nbsp; _tween.<span class="me1">addEventListener</span><span class="br0">&#40;</span>TweenEvent.<span class="me1">MOTION_FINISH</span>, eventHandler<span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>This solution is wise to use when you have small no of tweens. But if you have to create more no of tweens or tween that are created at run-time based on iterations, it&#8217;s not a good solution.</p>
<p>Using a dictionary object to reference the tween objects is often helpful to overcome the situations of tweening by iterations. And it&#8217;s easy to handle the dictionary objects for effective control in garbage collection. Here is the example:</p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li>
<div  class="de1"><span class="kw3">private</span> <span class="kw2">var</span> _tweenDC:Dictionary=<span class="kw2">new</span> Dictionary;</div>
</li>
<li>
<div  class="de1">&nbsp;</div>
</li>
<li>
<div  class="de1"><span class="kw3">private</span> <span class="kw2">function</span> createTween<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; <span class="kw2">var</span> clipXTween:Tween=<span class="kw2">new</span> Tween<span class="br0">&#40;</span>clip, <span class="st0">&quot;x&quot;</span>, Elastic.<span class="me1">easeOut</span>, <span class="nu0">0</span>, <span class="nu0">300</span>, <span class="nu0">3</span>, <span class="kw2">true</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp;_tweenDC<span class="br0">&#91;</span>clip<span class="br0">&#93;</span>=clipXTween;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp;<span class="co1">// if you have more than one property to tween you may use</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp;<span class="co1">// _tweenDC[clipXTween]=clipXTween;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; clipXTween.<span class="me1">addEventListener</span><span class="br0">&#40;</span>TweenEvent.<span class="me1">MOTION_FINISH</span>, eventHandler<span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1"><span class="br0">&#125;</span></div>
</li>
<li>
<div class="de2"><span class="co1">// clear all the collected tweens</span></div>
</li>
<li>
<div  class="de1"><span class="kw3">private</span> <span class="kw2">function</span> eventHandler<span class="br0">&#40;</span>evt:TweenEvent<span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; _tweenDC=<span class="kw2">new</span> Dictionary;<span class="co1">// Indeed not a good option. why?</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; <span class="co1">// or you can do as follows for the second case discussed above.</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; <span class="co1">// _tweenDC[evt.currentTarget]=null;</span></div>
</li>
<li>
<div class="de2">&nbsp; &nbsp; <span class="co1">// &nbsp;delete &nbsp;_tweenDC[evt.currentTarget];</span></div>
</li>
<li>
<div  class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Another way of handling multiple tweening by iterations is to reference the tweens by creating dynamic<br />
properties of a movie clip which should be declared inside the class scope. This is specially for animating multiple properties of a same clip with iterations.</p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li>
<div  class="de1"><span class="kw3">private</span> <span class="kw2">var</span> _tweenCollector:<span class="kw3">MovieClip</span>=<span class="kw2">new</span> <span class="kw3">MovieClip</span>;</div>
</li>
<li>
<div  class="de1">&nbsp;</div>
</li>
<li>
<div  class="de1"><span class="kw3">private</span> <span class="kw2">function</span> createTween<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="kw2">var</span> i:<span class="kw3">int</span>=<span class="nu0">0</span>;i&lt;=<span class="nu0">23</span>; i++<span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li>
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> _mc:Clip=<span class="kw2">new</span> Clip;<span class="co1">//clip is some custom class</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span class="br0">&#40;</span>_mc<span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _tweenCollector<span class="br0">&#91;</span><span class="st0">&quot;scalexn&quot;</span>+i<span class="br0">&#93;</span>=<span class="kw2">new</span> Tween<span class="br0">&#40;</span>_mc, <span class="st0">&quot;scaleX&quot;</span>, Strong.<span class="me1">easeOut</span>, <span class="nu0">1</span>, <span class="nu0">1.3</span>, .<span class="nu0">4</span>, <span class="kw2">true</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _tweenCollector<span class="br0">&#91;</span><span class="st0">&quot;scaleyn&quot;</span>+i<span class="br0">&#93;</span>=<span class="kw2">new</span> Tween<span class="br0">&#40;</span>_mc, <span class="st0">&quot;scaleY&quot;</span>, Strong.<span class="me1">easeOut</span>, <span class="nu0">1</span>, <span class="nu0">1.3</span>, .<span class="nu0">4</span>, <span class="kw2">true</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _tweenCollector<span class="br0">&#91;</span><span class="st0">&quot;xn&quot;</span>+i<span class="br0">&#93;</span>=<span class="kw2">new</span> Tween<span class="br0">&#40;</span>_mc, <span class="st0">&quot;x&quot;</span>, Strong.<span class="me1">easeOut</span>, <span class="nu0">200</span>, <span class="nu0">280</span>, .<span class="nu0">4</span>, <span class="kw2">true</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _tweenCollector<span class="br0">&#91;</span><span class="st0">&quot;yn&quot;</span> + i<span class="br0">&#93;</span> = <span class="kw2">new</span> Tween<span class="br0">&#40;</span>_mc, <span class="st0">&quot;y&quot;</span>, Strong.<span class="me1">easeOut</span>, <span class="nu0">200</span>,<span class="nu0">200</span>, .<span class="nu0">4</span>, <span class="kw2">true</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _tweenCollector<span class="br0">&#91;</span><span class="st0">&quot;yn&quot;</span> + i<span class="br0">&#93;</span>.<span class="me1">addEventListener</span><span class="br0">&#40;</span>TweenEvent.<span class="me1">MOTION_FINISH</span>, eventHandler<span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li>
<div  class="de1"><span class="br0">&#125;</span></div>
</li>
<li>
<div  class="de1"><span class="co1">// clear all the collected tweens</span></div>
</li>
<li>
<div class="de2"><span class="kw3">private</span> <span class="kw2">function</span> eventHandler<span class="br0">&#40;</span>evt:TweenEvent<span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp;_tweenCollector=<span class="kw2">new</span> <span class="kw3">MovieClip</span>;</div>
</li>
<li>
<div  class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>At some cases the above method may be risky, yet this concept worked fine for me in some of my projects.</p>
<p>Let&#8217;s see if any other good way exists.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.newtonflash.com/blog/as3/multiple-tweening-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3 Event handling- Part 3</title>
		<link>http://www.newtonflash.com/blog/as3/as3-event-handling-part-3/</link>
		<comments>http://www.newtonflash.com/blog/as3/as3-event-handling-part-3/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 04:40:51 +0000</pubDate>
		<dc:creator>newton</dc:creator>
				<category><![CDATA[AS3]]></category>

		<guid isPermaLink="false">http://www.newtonflash.com/blog/?p=260</guid>
		<description><![CDATA[In previous post we got familiarized with some key words that are commonly used. Now let&#8217;s grab an example and try to understand the basic concepts. Create a movieclip instance on the stage and give it an instance name clip_mc . &#8230; <a href="http://www.newtonflash.com/blog/as3/as3-event-handling-part-3/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In previous post we got familiarized with some key words that are commonly used. Now let&#8217;s grab an example and try to understand the basic concepts.</p>
<p>Create a movieclip instance on the stage and give it an instance name <em>clip_mc </em>. Now you can either write your code in an external file or in the frame. For more simplicity let&#8217;s write the code in the first frame. Here goes the code.</p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li>
<div  class="de1">clip_mc.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">CLICK</span>, clickEventHandler<span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1"><span class="kw2">function</span> clickEventHandler<span class="br0">&#40;</span>event:MouseEvent<span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; &nbsp;<span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&quot;Hello Mr. X, you have clicked me&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li>
<div  class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Test the movie. Click on the clip_mc and you will find the string which we traced  in the output panel. This tells us that our program is correct. <em>click_mc</em> dispatches a click event when ever mouse is being clicked on it and our program is an listener to that event. Hence clickEventHandler is being called so that we can perform necesssary actions when this event occures.</p>
<p><strong>Event flow:<br />
</strong></p>
<p>The <em>event flow</em> describes how an event object moves through the display  list. when we have more than one nested displayobjects inside a movieclip, event object makes a &#8216;U&#8217; turn through the stage and the actual target object. So we have three stages(phases) of event flow. In the first stage it moves from the top-most parentobject(usually the stage) to the parent of the target object. The penitration phase is called <strong>Capture Phase, </strong>when event reaches the target it&#8217;s called <strong>Target Phase, </strong>and the returning phase is called <strong>Bubbling Phase</strong>. Here is the image that shows these phases ( I took this image from the help files of flash cs3).</p>
<p><a href="http://www.newtonflash.com/blog/wp-content/uploads/2009/03/stage_parent_node.png"><img class="alignnone size-medium wp-image-268" title="stage_parent_node" src="http://www.newtonflash.com/blog/wp-content/uploads/2009/03/stage_parent_node.png" alt="" width="309" height="197" /></a> </p>
<p>This flow of event can be controlled by actionscript. You can stop the propagation at any point of time or not let the event reach the target phase also. Which makes it easier to get work done by the parent elements when some event on the inner most child node is fired. </p>
<p>It&#8217;s note worthy to remember that there are exceptions to this event flowing. Some events like <em>init </em>&amp; enterFrame do not have capture or bubbling phase. They have only target phase. So other objects are not affected by these events. Event&#8217;s that are not attached to any display objects are also in the stream of the above kind of events. For example netStatus , metadata event etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.newtonflash.com/blog/as3/as3-event-handling-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3 Event handling- Part 2</title>
		<link>http://www.newtonflash.com/blog/flash/as3-event-handling-part-2/</link>
		<comments>http://www.newtonflash.com/blog/flash/as3-event-handling-part-2/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 10:16:16 +0000</pubDate>
		<dc:creator>newton</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.newtonflash.com/blog/?p=249</guid>
		<description><![CDATA[In the previous post we checked out some issues with AS2 event handling mechanism. In this post we will look at some well known words used  in AS3 event handling. AS3 has radical changes compared to AS2 version of action script. &#8230; <a href="http://www.newtonflash.com/blog/flash/as3-event-handling-part-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In the <a href="http://www.newtonflash.com/blog/2009/03/05/as3-event-handling-part-1/">previous post</a> we checked out some issues with AS2 event handling mechanism. In this post we will look at some well known words used  in AS3 event handling. AS3 has radical changes compared to AS2 version of action script. In terms of event handling, it provides you more control over event propagation( hey, I will tell you about this term latter, wait for this) . Here are the list of some keyword that are used in the event handling codes.</p>
<p><strong>EventDispatcher: </strong>It&#8217;s the object of a class that is able to dispatch some event. Internally this class has a base class <em>EventDispatcher</em>  which enables the class object dispatch event and keep the track of it&#8217;s listeners by a method called <em>addEventListener</em>. It dispatches any event by <em>dispatchEvent</em> method. An example is given below.</p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li>
<div  class="de1">dispatchEvent<span class="br0">&#40;</span><span class="kw2">new</span> Event<span class="br0">&#40;</span>Event.<span class="kw3">CLOSE</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p><strong>EventObject:</strong> Event object is an instance of the event class or or it&#8217;s subclass which holds information about the event (occurrence, source of the event, event flow and other details). For example when we click by the help of the mouse on an sprite instance, it dispatches an mouse click event. This mouse click event object is an instance of the <em>MouseEvent </em>and provides details of the event.<br />
<strong>Event Target: </strong>Target of an event is usually the object that is responsible for the event dispatch. In the above example the class containing the code is the default target. But not necessarily it&#8217;s always. If the object has some inner child objects then the event target changes to the innermost child( We will discuss about this complex thing latter in details).</p>
<p><strong>Event Listeners</strong>: These are the methods we write how to handle the event when it occurred. An example might clarify this. So look below.</p>
<div class="dean_ch" style="white-space: nowrap;">
<ol>
<li>
<div  class="de1"><span class="kw3">private</span> <span class="kw2">function</span> eventHandler<span class="br0">&#40;</span>eventObject:EventType<span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li>
<div  class="de1"><span class="br0">&#123;</span></div>
</li>
<li>
<div  class="de1">&nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span>eventObject.<span class="kw3">target</span><span class="br0">&#41;</span>;<span class="co1">// this would give you name of the class that dispatches the event.(e ventTarget name).</span></div>
</li>
<li>
<div  class="de1"><span class="br0">&#125;</span></div>
</li>
<li>
<div class="de2">&nbsp;</div>
</li>
<li>
<div  class="de1">eventTarget.<span class="me1">addEventListener</span><span class="br0">&#40;</span>EventType.<span class="me1">EVENT_NAME</span>, eventHandler<span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>In the next post we will create an example and study it to explore more about the AS3 events.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.newtonflash.com/blog/flash/as3-event-handling-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

