<?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>danielbunte.de - the actionscripter</title>
	<atom:link href="http://danielbunte.de/feed/" rel="self" type="application/rss+xml" />
	<link>http://danielbunte.de</link>
	<description>ActionScript, PHP and others</description>
	<lastBuildDate>Fri, 03 Sep 2010 10:28:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Flash&#8217;s Text Engine and it&#8217;s incredible behavior</title>
		<link>http://danielbunte.de/2010/09/03/flashs-text-engine-and-its-incredible-behaviour/</link>
		<comments>http://danielbunte.de/2010/09/03/flashs-text-engine-and-its-incredible-behaviour/#comments</comments>
		<pubDate>Fri, 03 Sep 2010 10:28:05 +0000</pubDate>
		<dc:creator>Daniel Bunte</dc:creator>
				<category><![CDATA[ActionScript]]></category>

		<guid isPermaLink="false">http://danielbunte.de/?p=192</guid>
		<description><![CDATA[It&#8217;s been a while since my last post concering AS3. I&#8217;m currently developing the HUD/GUI for awesay and yesterday, I came in contact with the new flash text engine for the first time. For the HUD, I created a window, where I want to display a title centered on a sprite (horizontally, as well as [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a while since my last post concering AS3. I&#8217;m currently developing the HUD/GUI for awesay and yesterday, I came in contact with the new flash text engine for the first time.<br />
For the HUD, I created a window, where I want to display a title centered on a sprite (horizontally, as well as vertically).</p>
<p>So, after reading some docs about how to create a simple line of text, I finally got it on the screen. To me, the process of creating such a simple line of text, seems horrific. However, you&#8217;re able to do a lot of nice things with the FTE, and the good old TextField won&#8217;t be improved in future, but is still supported. Because we want our HUD to be multilingual, I decided using the FTE would be a good choice. OK, I went a bit off-topic, so let&#8217;s get back to it.</p>
<p>How do I positon a simple line of text (flash.text.engine.TextLine) centered on a sprite? The horizontal positioning is easy, because it behaves like every DisplayObject, so we do it like this:</p>
<div class="geshi no actionscript">
<div class="head">var sptMyTitleSprite:Sprite = new Sprite;</div>
<ol>
<li class="li1">
<div class="de1">sptMyTitleSprite.<span class="me1">graphics</span>.<span class="kw3">beginFill</span><span class="br0">&#40;</span>0xDEDEDE<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">sptMyTitleSprite.<span class="me1">graphics</span>.<span class="me1">drawRect</span><span class="br0">&#40;</span><span class="nu0">100</span>, <span class="nu0">25</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">sptMyTitleSprite.<span class="me1">graphics</span>.<span class="kw3">endFill</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">this</span>.<span class="me1">addChild</span><span class="br0">&#40;</span>sptMyTitleSprite<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> tlSimpleTextLine:TextLine = myTextBlock.<span class="me1">createTextLine</span><span class="br0">&#40;</span><span class="kw2">null</span>, <span class="nu0">100</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">sptMyTitleSprite.<span class="me1">addChild</span><span class="br0">&#40;</span>tlSimpleTextLine<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">tlSimpleTextLine.<span class="me1">x</span> = <span class="br0">&#40;</span>sptMyTitleSprite.<span class="kw3">width</span> <span class="sy0">&gt;&gt;</span> <span class="nu0">1</span><span class="br0">&#41;</span> &#8211; <span class="br0">&#40;</span>tlSimpleTextLine.<span class="kw3">width</span> <span class="sy0">&gt;&gt;</span> <span class="nu0">1</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>What I do in the code above, is creating a Sprite and draw a rectangle (100 width, 25 height) onto that Sprite. After adding the Sprite onto my displayList, I create my textLine from a TextBlock(not defined in the code above), and finally add the textLine onto my Sprite. When this is done, the textLine&#8217;s x-position is centered with the calculation(bitShift by 1 is a simple divison by 2, where the result is an integer).</p>
<p>Ok, that wasn&#8217;t too hard, it&#8217;s something I do very often. Well, I thought positioning the title in the vertical center of my Sprite is even that simple &#8211; Naaah, it&#8217;s not! Did you really thought it was that simple, hrhr <img src='http://danielbunte.de/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1">tlSimpleTextLine.<span class="me1">y</span> = <span class="br0">&#40;</span>sptMyTitleSprite.<span class="kw3">height</span> <span class="sy0">&gt;&gt;</span> <span class="nu0">1</span><span class="br0">&#41;</span> &#8211; <span class="br0">&#40;</span>tlSimpleTextLine.<span class="kw3">height</span> <span class="sy0">&gt;&gt;</span> <span class="nu0">1</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>That does not work. The 0, 0 Point of a TextLine (Roman) is always on the very left of the baseline.<br />
<img src="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/images/TextLine.gif" alt="TextLineDiagram" /><br />
(I catched this image from the Adobe docs).</p>
<p>This behaviour causes the main part of our textLine to be in the negative y-direction(up) of it&#8217;s DisplayObject. The Adobe-People may again have smoked one pipe too much while coding this <img src='http://danielbunte.de/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  just kidding!<br />
So when I calculate the vertical center of the Sprite (sprite.height >> 1), and I position the textLine at that position, it will nearly be centered, because it&#8217;s baseline is now at y: (sprite.height >> 1).<br />
What we have to do, to position it at the absoule center, is subtracting the half of the textLine&#8217;s decent-value. That is everything what&#8217;s below the baseline. For example the lower parts of &#8220;j, g, y&#8221;.<br />
The final solution will be:</p>
<pre lang="actionscript">tlSimpleTextLine.y = (sptMyTitleSprite.height >> 1) - (tlSimpleTextLine.descent >> 1);</pre>
<p>I wrote this post, because I didn&#8217;t find any solution to this in the net. This will hopefully help other people.</p>
]]></content:encoded>
			<wfw:commentRss>http://danielbunte.de/2010/09/03/flashs-text-engine-and-its-incredible-behaviour/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>awesay.com &#8211; presentation website online</title>
		<link>http://danielbunte.de/2010/07/07/awesay-com-presentation-website-online/</link>
		<comments>http://danielbunte.de/2010/07/07/awesay-com-presentation-website-online/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 10:16:39 +0000</pubDate>
		<dc:creator>Daniel Bunte</dc:creator>
				<category><![CDATA[ActionScript]]></category>

		<guid isPermaLink="false">http://danielbunte.de/2010/07/07/awesay-com-presentation-website-online/</guid>
		<description><![CDATA[badnoob.com just published the presentation website of our project awesay. awesay is going to become a virtual, interactive shoppingmall in 3D! Visit http://www.awesay.com (German language only)]]></description>
			<content:encoded><![CDATA[<p>badnoob.com just published the presentation website of our project awesay.<br />
awesay is going to become a virtual, interactive shoppingmall in 3D!</p>
<p>Visit <a href="http://www.awesay.com">http://www.awesay.com</a> (German language only)</p>
]]></content:encoded>
			<wfw:commentRss>http://danielbunte.de/2010/07/07/awesay-com-presentation-website-online/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>company blog started</title>
		<link>http://danielbunte.de/2010/05/26/company-blog-started/</link>
		<comments>http://danielbunte.de/2010/05/26/company-blog-started/#comments</comments>
		<pubDate>Wed, 26 May 2010 08:09:01 +0000</pubDate>
		<dc:creator>Daniel Bunte</dc:creator>
				<category><![CDATA[ActionScript]]></category>

		<guid isPermaLink="false">http://danielbunte.de/2010/05/26/company-blog-started/</guid>
		<description><![CDATA[I just wan&#8217;t to inform my visitors that we (my company badnoob.com) has started it&#8217;s own blog. Main topics are our new Flash 3D-Engine, which is currently under heavy development, and also our project called &#8220;awesay&#8221; &#8211; more information can be found on the blog: http://blog.badnoob.com]]></description>
			<content:encoded><![CDATA[<p>I just wan&#8217;t to inform my visitors that we (my company badnoob.com) has started it&#8217;s own blog. Main topics are our new Flash 3D-Engine, which is currently under heavy development, and also our project called &#8220;awesay&#8221; &#8211; more information can be found on the <a href="http://blog.badnoob.com">blog: http://blog.badnoob.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://danielbunte.de/2010/05/26/company-blog-started/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash&#8217;s internal functions scuk!</title>
		<link>http://danielbunte.de/2010/04/29/flashs-internal-functions-scuk/</link>
		<comments>http://danielbunte.de/2010/04/29/flashs-internal-functions-scuk/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 18:41:07 +0000</pubDate>
		<dc:creator>Daniel Bunte</dc:creator>
				<category><![CDATA[ActionScript]]></category>

		<guid isPermaLink="false">http://danielbunte.de/2010/04/29/flashs-internal-function-scuk/</guid>
		<description><![CDATA[yeah, it&#8217;s not a typo in the title, but it&#8217;s almost true! Flash&#8217;s own functions and/or method are slow as I can say. I first noticed this while having a look at TweenLite&#8217;s easings. Math.pow is slow. It&#8217;s faster doing x * x * x and so on &#8211; yeah really! Don&#8217;t believe me? Give [...]]]></description>
			<content:encoded><![CDATA[<p>yeah, it&#8217;s not a typo in the title, but it&#8217;s almost true!<br />
Flash&#8217;s own functions and/or method are slow as I can say. I first noticed this while having a look at TweenLite&#8217;s easings.<br />
Math.pow is slow. It&#8217;s faster doing x * x * x and so on &#8211; yeah really! Don&#8217;t believe me? Give it a try!<br />
I assume this behaviour not only to sin, cos and other trigonometric functions (as already found out to be right by polygonal labs), but also to Flash&#8217;s own graphics-library.<br />
So I&#8217;m on trip atm where I&#8217;ll do EVERYTHING myself. I&#8217;ve already done a small Bitmap-based Font-Engine, Textfields, unbelievable fast OBJ-Parser and a lot of more stuff&#8230; just wanted to let you know this <img src='http://danielbunte.de/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  (if anyone reads this at all &#8211; I dunno)</p>
<p>I also think about y everyone doing flash 3d on this planet, uses sin/cos and so on with radians, instead of creating a lookup-table &#8220;once&#8221;. horrific &#8211; it&#8217;s just that what&#8217;s done in code these days&#8230; ugly code! ever had a look at papervision, away3d, and some more google code project? blehyawk.<br />
enough for know &#8211; have a nice day <img src='http://danielbunte.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://danielbunte.de/2010/04/29/flashs-internal-functions-scuk/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ListenerProxy v2</title>
		<link>http://danielbunte.de/2010/02/14/listenerproxy-v2/</link>
		<comments>http://danielbunte.de/2010/02/14/listenerproxy-v2/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 19:28:06 +0000</pubDate>
		<dc:creator>Daniel Bunte</dc:creator>
				<category><![CDATA[ActionScript]]></category>

		<guid isPermaLink="false">http://danielbunte.de/?p=173</guid>
		<description><![CDATA[I just found some improvements on my ListenerProxy-Class and packed them into a new &#8220;Version 2&#8243;. I also added a license-information. You can get the new Version 2 of ListenerProxy here.]]></description>
			<content:encoded><![CDATA[<p>I just found some improvements on my ListenerProxy-Class and packed them into a new &#8220;Version 2&#8243;. I also added a license-information. You can get the new Version 2 of ListenerProxy <a href='http://danielbunte.de/listenerproxy-handle-as3-eventlisteners-easily/'>here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://danielbunte.de/2010/02/14/listenerproxy-v2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updated List of References</title>
		<link>http://danielbunte.de/2009/08/12/updated-list-of-references/</link>
		<comments>http://danielbunte.de/2009/08/12/updated-list-of-references/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 15:08:04 +0000</pubDate>
		<dc:creator>Daniel Bunte</dc:creator>
				<category><![CDATA[ActionScript]]></category>

		<guid isPermaLink="false">http://danielbunte.de/?p=133</guid>
		<description><![CDATA[I updated the List of References, because the link to the old version of the HugoBoss Flash-Shop was incorrect. Check it out: List of Refrences]]></description>
			<content:encoded><![CDATA[<p>I updated the List of References, because the link to the old version of the HugoBoss Flash-Shop was incorrect.<br />
Check it out: <a href="http://danielbunte.de/list-of-references/">List of Refrences</a></p>
]]></content:encoded>
			<wfw:commentRss>http://danielbunte.de/2009/08/12/updated-list-of-references/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ListenerProxy::BUGFIX</title>
		<link>http://danielbunte.de/2009/08/07/listenerproxybugfix/</link>
		<comments>http://danielbunte.de/2009/08/07/listenerproxybugfix/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 06:02:20 +0000</pubDate>
		<dc:creator>Daniel Bunte</dc:creator>
				<category><![CDATA[ActionScript]]></category>

		<guid isPermaLink="false">http://danielbunte.de/?p=119</guid>
		<description><![CDATA[I updated the ListenerProxy-class, because I detected a bug with adding/removing multiple listeners to multiple objects. I also removed duplicate entries of &#8220;if(objToAdd.hasOwnProperty(&#8216;addEventListener&#8217;))&#8221; Get the newest version[v1.3.4-stable]: ListenerProxy]]></description>
			<content:encoded><![CDATA[<div align="left">I updated the ListenerProxy-class, because I detected a bug with adding/removing multiple listeners to multiple objects.<br />
I also removed duplicate entries of &#8220;if(objToAdd.hasOwnProperty(&#8216;addEventListener&#8217;))&#8221;</div>
<p>Get the newest version[v1.3.4-stable]: <a href='http://danielbunte.de/listenerproxy-handle-as3-eventlisteners-easily/'>ListenerProxy</a></p>
]]></content:encoded>
			<wfw:commentRss>http://danielbunte.de/2009/08/07/listenerproxybugfix/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Add methods to native Classes in ActionScript 3.0 &#8211; Prototype functions</title>
		<link>http://danielbunte.de/2009/07/09/add-methods-to-native-classes-in-actionscript-3-0-prototype-functions/</link>
		<comments>http://danielbunte.de/2009/07/09/add-methods-to-native-classes-in-actionscript-3-0-prototype-functions/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 07:23:23 +0000</pubDate>
		<dc:creator>Daniel Bunte</dc:creator>
				<category><![CDATA[ActionScript]]></category>

		<guid isPermaLink="false">http://danielbunte.de/?p=108</guid>
		<description><![CDATA[Hi again! Yesterday I&#8217;ve found out a cool new feature of ActionScript 3.0. You will sometimes have to use associative Arrays. The problem with these is that you can&#8217;t easily loop through them with a for-loop like var &#160; &#160;myAssocArray:Array = &#91;&#93;, &#160; &#160; &#160; &#160; i &#160; &#160; &#160; &#160; &#160; &#160;:int, &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Hi again!<br />
Yesterday I&#8217;ve found out a cool new feature of ActionScript 3.0. You will sometimes have to use associative Arrays. The problem with these is that you can&#8217;t easily loop through them with a for-loop like</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> &nbsp; &nbsp;myAssocArray:<span class="kw3">Array</span> = <span class="br0">&#91;</span><span class="br0">&#93;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; i &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:<span class="kw3">int</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; intLength &nbsp; &nbsp;:<span class="kw3">int</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">myAssocArray<span class="br0">&#91;</span><span class="st0">&#39;foo&#39;</span><span class="br0">&#93;</span> = <span class="st0">&#39;one&#39;</span>;</div>
</li>
<li class="li1">
<div class="de1">myAssocArray<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span> = <span class="st0">&#39;two&#39;</span>;</div>
</li>
<li class="li1">
<div class="de1">myAssocArray<span class="br0">&#91;</span><span class="st0">&#39;bar&#39;</span><span class="br0">&#93;</span> = <span class="st0">&#39;three&#39;</span>;</div>
</li>
<li class="li1">
<div class="de1">myAssocArray<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> = <span class="st0">&#39;four&#39;</span>;</div>
</li>
<li class="li1">
<div class="de1">intLength = myAssocArray.<span class="kw3">length</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">for</span><span class="br0">&#40;</span>; i<span class="sy0">&lt;</span> intLength; ++i<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span>myAssocArray<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>The trace will probably print out &#8220;four, two, undefined, undefined&#8221;. The fact is that you can get the elements 0 &#038; 1 via the variable i, but the the other keys can&#8217;t be accessed with this method.<br />
As I also like PHP very much, I also know the function array_keys(array) of PHP, which returns the key-values of the array given in the parameters. I thought that I really need this functionality within AS3, so I tried a lot, searched the internet and finally got it! It&#8217;s pretty simple for those knowing AS2 &#8211; prototype functions.<br />
What do we need to do? Place the following code in your main, unnamed package below or above the class-definition and you can use it everywhere else in the code:
</pre>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1">package</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">class</span> foo</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> foo<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&#39;bar&#39;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">Array</span>.<span class="kw3">prototype</span>.<span class="me1">arrayKeys</span> = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">Array</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> &nbsp; &nbsp;arrReturn &nbsp; &nbsp;:<span class="kw3">Array</span> = <span class="br0">&#91;</span><span class="br0">&#93;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strKey &nbsp; &nbsp; &nbsp; &nbsp;:<span class="kw3">String</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span>strKey <span class="kw1">in</span> <span class="kw3">this</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">typeof</span> <span class="kw3">this</span><span class="br0">&#91;</span>strKey<span class="br0">&#93;</span> == <span class="st0">&#39;function&#39;</span><span class="br0">&#41;</span> <span class="kw1">continue</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&#39;in Array:: value-&gt;&#39;</span>+ strKey +<span class="st0">&#39; typeOf:&#39;</span>+ <span class="kw3">typeof</span> strKey +<span class="st0">&#39; proto:&#39;</span>+ <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="kw3">this</span><span class="br0">&#91;</span>strKey<span class="br0">&#93;</span> <span class="sy0">!</span>== <span class="kw2">false</span><span class="br0">&#41;</span> ? <span class="kw3">typeof</span> <span class="kw3">this</span><span class="br0">&#91;</span>strKey<span class="br0">&#93;</span> : <span class="st0">&#39;NULL&#39;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; arrReturn<span class="br0">&#91;</span>arrReturn.<span class="kw3">length</span><span class="br0">&#93;</span> = strKey;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> arrReturn;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">Number</span>.<span class="kw3">prototype</span>.<span class="me1">give</span> = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">String</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="st0">&#39;Number::giveItToMeBaby&#39;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>You can now use this method to get the keys of the variable:</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> arrKeys &nbsp; &nbsp; &nbsp; &nbsp;:<span class="kw3">Array</span> = myAssocArray.<span class="me1">arrayKeys</span><span class="br0">&#40;</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; i &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:<span class="kw3">int</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; intLength &nbsp; &nbsp;:<span class="kw3">int</span> = arrKeys.<span class="kw3">length</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">for</span><span class="br0">&#40;</span>; i <span class="sy0">&lt;</span> intLength; ++i<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span>myAssocArray<span class="br0">&#91;</span>arrKeys<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Pretty easy, isn't it? Well, it is easy because the native Array-Class is dynamic, but what do we do with Number (final class)? Let's see...
</pre>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> num:<span class="kw3">Number</span> = <span class="nu0">4</span>;</div>
</li>
<li class="li1">
<div class="de1">num.<span class="me1">give</span><span class="br0">&#40;</span><span class="br0">&#41;</span>; <span class="co1">//doesn&#39;t work! final class, can&#39;t add methods to it?</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">num<span class="br0">&#91;</span><span class="st0">&#39;give&#39;</span><span class="br0">&#93;</span><span class="br0">&#40;</span><span class="br0">&#41;</span>; <span class="co1">//does work <img src='http://danielbunte.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  you can dynamically add methods to a class even if it&#39;s final; problem is that this code is hard to read, but it actually works</span></div>
</li>
</ol>
</div>
<p>So far...<br />
 Daniel</p>
]]></content:encoded>
			<wfw:commentRss>http://danielbunte.de/2009/07/09/add-methods-to-native-classes-in-actionscript-3-0-prototype-functions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ActionScript 3.0 ListenerProxy goes public</title>
		<link>http://danielbunte.de/2009/07/06/actionscript-30-listenerproxy-goes-public/</link>
		<comments>http://danielbunte.de/2009/07/06/actionscript-30-listenerproxy-goes-public/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 08:01:34 +0000</pubDate>
		<dc:creator>Daniel Bunte</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Event]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Listener]]></category>

		<guid isPermaLink="false">http://danielbunte.de/?p=77</guid>
		<description><![CDATA[Hello everybody! Since February I wanted to put my great ListenerProxy-class onto the page, but I forgot it every day&#8230; So now I&#8217;m here and remembered that there was a Class to publish! Hey Daniel, tell me what the heck is a ListenerProxy and why did ya write that piece of code man? Let&#8217;s go [...]]]></description>
			<content:encoded><![CDATA[<p>Hello everybody!<br />
Since February I wanted to put my great ListenerProxy-class onto the page, but I forgot it every day&#8230; So now I&#8217;m here and remembered that there was a Class to publish!</p>
<p>Hey Daniel, tell me what the heck is a ListenerProxy and why did ya write that piece of code man? Let&#8217;s go on&#8230;<br />
Since ActionScript is enourmously memory-consuming, I often tried to get rid of this. Once I found out that you can&#8217;t remove any objects that are still having a Listener registered on them. So what do you have to do, to get an object out of the memory? Setting the value to null or probably 0 (ints and so on), doesn&#8217;t seem to do the trick. You also have to remove the EventListeners &#8211; and of course &#8211; ALL of them!<br />
Some time ago in an old Flash CS3-Version, you could find a listeners-Array of every object when you debugged the movie, but you can&#8217;t access this array &#8211; no way!<br />
Well that was really <a href="http://parentingforprogrammers.blogspot.com/2007/08/kid-funnies-part-21.html" target="_blank">annoising</a> me, so I decided to write a class that keeps track of all the listeners registered on an object.</p>
<p>So what else can we do with your ListenerProxy, Daniel?<br />
You probably already had some code where you needed to add multiple Listeners with the same callback-function. You then had to write code like this:</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> myLoader:Loader = <span class="kw2">new</span> Loader<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; myLoader.<span class="me1">addEventListener</span><span class="br0">&#40;</span>Event.<span class="me1">COMPLETE</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw3">this</span>.<span class="me1">loadHandler</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; myLoader.<span class="me1">addEventListener</span><span class="br0">&#40;</span>IOErrorEvent.<span class="me1">IO_ERROR</span>, &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw3">this</span>.<span class="me1">loadHandler</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; myLoader.<span class="me1">addEventListener</span><span class="br0">&#40;</span>HTTPStatusEvent.<span class="me1">HTTP_STATUS</span>, &nbsp; &nbsp;<span class="kw3">this</span>.<span class="me1">loadHandler</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; myLoader.<span class="me1">addEventListener</span><span class="br0">&#40;</span>ProgressEvent.<span class="me1">PROGRESS</span>, &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw3">this</span>.<span class="me1">loadHandler</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>This are four lines of code for the listeners&#8230;. Wanna do it within a single line? Watch this:</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1">ListenerProxy.<span class="me1">getInstance</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="kw3">addListener</span><span class="br0">&#40;</span>myLoader, <span class="br0">&#91;</span>Event.<span class="me1">COMPLETE</span>, IOErrorEvent.<span class="me1">IO_ERROR</span>, HTTPStatusEvent.<span class="me1">HTTP_STATUS</span>, ProgressEvent.<span class="me1">PROGRESS</span><span class="br0">&#93;</span>, <span class="kw3">this</span>.<span class="me1">loadHandler</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>You can of course add a single Listener for a object, just pass the type as second parameter without the brackets:</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1">ListenerProxy.<span class="me1">getInstance</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="kw3">addListener</span><span class="br0">&#40;</span>myLoader, Event.<span class="me1">COMPLETE</span>, <span class="kw3">this</span>.<span class="me1">loadHandler</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Ok that&#8217;s nice, isn&#8217;t it? So you have multiple objects to listen for the same Event calling the same callback-function? Hmmm&#8230;.</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> myLoader_1:Loader = <span class="kw2">new</span> Loader<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> myLoader_2:Loader = <span class="kw2">new</span> Loader<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> myLoader_3:Loader = <span class="kw2">new</span> Loader<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> myLoader_4:Loader = <span class="kw2">new</span> Loader<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; myLoader_1.<span class="me1">addEventListener</span><span class="br0">&#40;</span>Event.<span class="me1">COMPLETE</span>, &nbsp; &nbsp;<span class="kw3">this</span>.<span class="me1">loadHandler</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; myLoader_2.<span class="me1">addEventListener</span><span class="br0">&#40;</span>Event.<span class="me1">COMPLETE</span>, &nbsp; &nbsp;<span class="kw3">this</span>.<span class="me1">loadHandler</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; myLoader_3.<span class="me1">addEventListener</span><span class="br0">&#40;</span>Event.<span class="me1">COMPLETE</span>, &nbsp; &nbsp;<span class="kw3">this</span>.<span class="me1">loadHandler</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; myLoader_4.<span class="me1">addEventListener</span><span class="br0">&#40;</span>Event.<span class="me1">COMPLETE</span>, &nbsp; &nbsp;<span class="kw3">this</span>.<span class="me1">loadHandler</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Argh*!$# I hate such crappy code <img src='http://danielbunte.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1">ListenerProxy.<span class="me1">getInstance</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="kw3">addListener</span><span class="br0">&#40;</span><span class="br0">&#91;</span>myLoader_1, myLoader_2, myLoader_3, myLoader_4<span class="br0">&#93;</span>, Event.<span class="me1">COMPLETE</span>, <span class="kw3">this</span>.<span class="me1">loadHandler</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Yeeehaa! It makes the whole thing a bit easier, don&#8217;t you think so?</p>
<p>And that&#8217;s not all. If you have multiple objects with multiple listeners and the same callback-function, you can simply pass the elements as arrays as shown above.</p>
<p>So what are the key-functions to use?</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1"><span class="nu0">1</span>. <span class="me1">ListenerProxy</span>.<span class="me1">getInstance</span><span class="br0">&#40;</span><span class="br0">&#41;</span>:ListenerProxy <span class="co1">//Singleton-Pattern is used</span></div>
</li>
<li class="li1">
<div class="de1"><span class="nu0">2</span>. <span class="kw3">addListener</span><span class="br0">&#40;</span>objToAddTo:<span class="sy0">*</span>, strListenerType:<span class="sy0">*</span>, funcCallback:<span class="kw2">Function</span><span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="co1">//to add Listeners</span></div>
</li>
<li class="li1">
<div class="de1"><span class="nu0">3</span>. <span class="kw3">removeListener</span><span class="br0">&#40;</span>objToRemoveFrom:<span class="sy0">*</span>, strListenerType:<span class="sy0">*</span>, funcCallback:<span class="kw2">Function</span><span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="co1">//to remove Listeners</span></div>
</li>
<li class="li1">
<div class="de1"><span class="nu0">4</span>. <span class="me1">hasListener</span><span class="br0">&#40;</span>objToAsk:<span class="sy0">*</span>, strListenerType:<span class="kw3">String</span>, funcCallback:<span class="kw2">Function</span> = <span class="kw2">null</span><span class="br0">&#41;</span>:<span class="kw3">Boolean</span> <span class="co1">//check whether the specified object has that listener or not</span></div>
</li>
<li class="li1">
<div class="de1"><span class="nu0">5</span>. <span class="kw3">pop</span><span class="br0">&#40;</span>objToPop:<span class="sy0">*</span>, blnRemoveAllListeners:<span class="kw3">Boolean</span> = <span class="kw2">false</span><span class="br0">&#41;</span>:<span class="sy0">*</span> <span class="co1">//remove the object from ListenerProxy&#39;s Dictionary (the 2nd param is VERY USEFUL!)</span></div>
</li>
</ol>
</div>
<p>Get the Code <a href="http://danielbunte.de/listenerproxy-handle-as3-eventlisteners-easily/">here</a>!</p>
<p>[UPDATE]</p>
<blockquote><p>
::06th August 2009 { fixed bug with adding/removing multiple listeners to multiple objects; also remove duplicate entries of &#8220;if(objToAdd.hasOwnProperty(&#8216;addEventListener&#8217;))&#8221; }
</p></blockquote>
<p>[/UPDATE]</p>
]]></content:encoded>
			<wfw:commentRss>http://danielbunte.de/2009/07/06/actionscript-30-listenerproxy-goes-public/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>if-statements &#8211; checking strings for being null</title>
		<link>http://danielbunte.de/2009/02/12/if-statements-checking-strings-for-being-null/</link>
		<comments>http://danielbunte.de/2009/02/12/if-statements-checking-strings-for-being-null/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 08:08:19 +0000</pubDate>
		<dc:creator>Daniel Bunte</dc:creator>
				<category><![CDATA[ActionScript]]></category>

		<guid isPermaLink="false">http://danielbunte.de/?p=72</guid>
		<description><![CDATA[hello again! Yesterday I wrote some code again and had to check if a String is null or not. The check was performed in a for-loop. Below is some example code: public var arrToFill:Array = []; &#91;&#8230; some more code here &#8230;&#93; private function foo&#40;&#41;:void &#123; &#160; var i:uint; &#160; for&#40; i = 0; i [...]]]></description>
			<content:encoded><![CDATA[<p>hello again!<br />
Yesterday I wrote some code again and had to check if a String is null or not. The check was performed in a for-loop.<br />
Below is some example code:</p>
<div class="geshi no actionscript">
<div class="head">public var arrToFill:Array = [];</div>
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>&#8230; <span class="me1">some</span> more code here &#8230;<span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">private</span> <span class="kw2">function</span> foo<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">var</span> i:uint;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">for</span><span class="br0">&#40;</span> i = <span class="nu0">0</span>; i <span class="sy0">&lt;</span> <span class="nu0">10</span>; ++i<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="sy0">!</span>arrToFill<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; arrToFill<span class="br0">&#91;</span>i<span class="br0">&#93;</span> = <span class="st0">&#39;&#39;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>This function was called different times and I wondered, that the if-statement returned false everytime.<br />
For me it was theoretically correct that an Array-Element with a value of &#8221; is not empty, because &#8221; is an empty String for me, but it is something.<br />
ActionScript3 doesn&#8217;t work like that, so for AS3 a String with a value of &#8221; is equal to null or 0.</p>
<p>Conclusion:<br />
If you have code like this and want to preallocate an element, just set it to 1. Then you can do a simpy </pre>
<pre lang="actionscript">if(!arrToFill[i])</pre>
<p> and everything would be fine.</p>
]]></content:encoded>
			<wfw:commentRss>http://danielbunte.de/2009/02/12/if-statements-checking-strings-for-being-null/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 1.587 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2010-09-05 16:05:43 -->
<!-- Compression = gzip -->