<?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>Ghost23 Blog &#187; Flash in general</title>
	<atom:link href="http://www.ghost23.de/category/flash-in-general/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ghost23.de</link>
	<description>A blog about Flash and stuff</description>
	<lastBuildDate>Tue, 03 Jan 2012 15:21:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Mercedes Facebook game &#8211; flash</title>
		<link>http://www.ghost23.de/2011/07/mercedes-facebook-game-flash/</link>
		<comments>http://www.ghost23.de/2011/07/mercedes-facebook-game-flash/#comments</comments>
		<pubDate>Sun, 03 Jul 2011 08:31:22 +0000</pubDate>
		<dc:creator>Sven Busse</dc:creator>
				<category><![CDATA[AS3 / Flex]]></category>
		<category><![CDATA[Flash in general]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://www.ghost23.de/?p=538</guid>
		<description><![CDATA[Juten Tach, another project just went online this week, in which i was involved: Drive and Seek &#8211; The Prologue. Together with Harald, who was the lead here, we were responsible for the development. I took special care of the interface to facebook and the customization features of the end video, in which you can [...]]]></description>
			<content:encoded><![CDATA[<p>Juten Tach,</p>
<p>another project just went online this week, in which i was involved: <a title="Drive and Seek - The Prologue" href="http://www.facebook.com/MercedesBenz?sk=app_214093555274968" target="_blank">Drive and Seek &#8211; The Prologue</a>. Together with <a title="Harald Tobler" href="http://www.seriouscircus.com/" target="_blank">Harald</a>, who was the lead here, we were responsible for the development. I took special care of the interface to facebook and the customization features of the end video, in which you can put your own picture either by uploading one or via webcam.</p>
<p>It was a fun project, going for a about a month.</p>
<p>What did i learn? First of all, i have mixed feelings about robotlegs. I like the DI part, but i cannot get used to these top-down mvc structures, which seem to put too much emphasis on infrastructure and too little on conceptual entities. I have to admit, that robotlegs technically does not tell you how to structure your application, but the best practices documentation does promote the approach of using mediators, commands and so on and tying it all together via bunch of events. This sounds all nice in theory, in practice for me, it is too technical and does not reflect the individual, conceptual relations of the components and modules i like to build. But this is stuff for another post.</p>
<p>I do like the Facebook API, although its documentation leaves a lot to be desired. The JavaScript SDK is nice and after fighting with the Facebook ActionScript library initially (couldn&#8217;t get it to initialize reliably), i soon abandoned it and used the JavaScript SDK directly via ExternalInterface.</p>

<div class="ngg-galleryoverview" id="ngg-gallery-4-538">


	
	<!-- Thumbnails -->
		
	<div id="ngg-image-54" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.ghost23.de/wp-content/gallery/mercedesfacebook/game.jpg" title=" " class="shutterset_set_4" >
								<img title="game" alt="game" src="http://www.ghost23.de/wp-content/gallery/mercedesfacebook/thumbs/thumbs_game.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-55" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.ghost23.de/wp-content/gallery/mercedesfacebook/start.jpg" title=" " class="shutterset_set_4" >
								<img title="start" alt="start" src="http://www.ghost23.de/wp-content/gallery/mercedesfacebook/thumbs/thumbs_start.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-56" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.ghost23.de/wp-content/gallery/mercedesfacebook/userphotoinsert.jpg" title=" " class="shutterset_set_4" >
								<img title="userphotoinsert" alt="userphotoinsert" src="http://www.ghost23.de/wp-content/gallery/mercedesfacebook/thumbs/thumbs_userphotoinsert.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-57" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.ghost23.de/wp-content/gallery/mercedesfacebook/webcam.jpg" title=" " class="shutterset_set_4" >
								<img title="webcam" alt="webcam" src="http://www.ghost23.de/wp-content/gallery/mercedesfacebook/thumbs/thumbs_webcam.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 	 	
	<!-- Pagination -->
 	<div class='ngg-clear'></div>
 	
</div>


]]></content:encoded>
			<wfw:commentRss>http://www.ghost23.de/2011/07/mercedes-facebook-game-flash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jump &#8216;n run &#8211; Lego builders of infinity</title>
		<link>http://www.ghost23.de/2011/05/jump-n-run-lego-builders-of-infinity/</link>
		<comments>http://www.ghost23.de/2011/05/jump-n-run-lego-builders-of-infinity/#comments</comments>
		<pubDate>Mon, 09 May 2011 10:06:53 +0000</pubDate>
		<dc:creator>Sven Busse</dc:creator>
				<category><![CDATA[Flash in general]]></category>
		<category><![CDATA[Stuff]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[box2d]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://www.ghost23.de/?p=506</guid>
		<description><![CDATA[Jump 'n Run game for Lego, produced by plan.net. This game consists of standalone game app and a microsite, where you can build levels with lego bricks and publish them.
Technologies involved: Flash / ActionScript3, Box2D
I was responsible for the development of the game. It took roughly about 1.5 months. This one won a silver lion in Cannes.]]></description>
			<content:encoded><![CDATA[<p>Juten Tach,</p>
<p>it doesn&#8217;t happen that often, that you work on a project for some time and finish it as smoothly as you started it. That happened to me while developing the jump &#8216;n run game <a title="Lego - builders of infinity" href="http://www.buildersofinfinity.com" target="_blank">Lego &#8211; builders of infinity</a>. Working with the nice people at Plan.net here in hamburg, we just finished this project together (If you like it, you might want to express that with a <a title="Lego - builders of infinity at FWA" href="http://thefwa.com/submissions/lego-builders-of-infinity" target="_blank">vote</a>?).</p>
<p><strong>Update:</strong> Nice: Just got notified, that the project won a <a title="Silver lion in Cannes" href="http://www.canneslions.com/work/direct/entry.cfm?entryid=23379&amp;award=3" target="_blank">silver lion in Cannes</a>!</p>
<p><strong>Update 2</strong>: Double nice: <a title="Site of the day at FWA." href="http://thefwa.com/site/lego-builders-of-infinity" target="_blank">FWA site of the day</a>.</p>
<p><strong>Update 3:</strong> Triple nice: <a title="Dope Award" href="http://www.dopeawards.com/?winner=2255&amp;cat=0" target="_blank">Dope Award</a></p>
<p><a href="http://www.ghost23.de/wp-content/uploads/lego-boi-1.jpg"><img class="size-full wp-image-507 alignnone" title="Lego - builders of infinity" src="http://www.ghost23.de/wp-content/gallery/legojump/lego-boi-1.jpg" alt="" /></a></p>
<p>This took roughly two months. It&#8217;s based on Flash Player 10 and uses the Box2d wck alchemy port. Its basically two apps: the game and the microsite. You can embed the game in your own website or blog, if you like.</p>
<p>The whole project consists of 103 ActionScript files (mostly classes) and around 6640 lines of code (no comments, no blanks, no libs).</p>
<p><a href="http://www.ghost23.de/wp-content/uploads/lego-boi-2.jpg"><img class="alignnone size-full wp-image-508" title="Lego - builders of infinity" src="http://www.ghost23.de/wp-content/gallery/legojump/lego-boi-2.jpg" alt="" /></a></p>
<p>The most challenging thing was, that Box2D has issues with letting boxes slide over a set of other boxes. From time to time, the box sticks at the edge from one underlying box to another, even if they are perfectly aligned. I first used the &#8220;normal&#8221; Box2D Flash port, but as it seems, there has not been a lot of development going on there, lately. So i switched to the Box2D wck alchemy port, which requires Flash Player 10. That port is more up to date with the original C implementation and thus can take advantage of some changes, which help fix the sliding issue. You can now cut off the corners of your boxes and thus let it slide over the corners of two adjacent boxes (which actually don&#8217;t exist, but as i said, box2d thinks they do exist). This trick does not work in the old &#8220;normal&#8221; Box2D Flash port.</p>
<p>Hope you enjoy the game.</p>
<div class="ngg-galleryoverview" id="ngg-gallery-3-506">


	
	<!-- Thumbnails -->
		
	<div id="ngg-image-39" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.ghost23.de/wp-content/gallery/legojump/lego-boi-1.jpg" title=" " class="shutterset_set_3" >
								<img title="lego-boi-1" alt="lego-boi-1" src="http://www.ghost23.de/wp-content/gallery/legojump/thumbs/thumbs_lego-boi-1.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-42" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.ghost23.de/wp-content/gallery/legojump/lego-boi-2.jpg" title=" " class="shutterset_set_3" >
								<img title="lego-boi-2" alt="lego-boi-2" src="http://www.ghost23.de/wp-content/gallery/legojump/thumbs/thumbs_lego-boi-2.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 	 	
	<!-- Pagination -->
 	<div class='ngg-clear'></div>
 	
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.ghost23.de/2011/05/jump-n-run-lego-builders-of-infinity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Tweens with Box2D 2.0.1</title>
		<link>http://www.ghost23.de/2011/02/using-tweens-with-box2d-2-0-1/</link>
		<comments>http://www.ghost23.de/2011/02/using-tweens-with-box2d-2-0-1/#comments</comments>
		<pubDate>Mon, 21 Feb 2011 18:39:09 +0000</pubDate>
		<dc:creator>Sven Busse</dc:creator>
				<category><![CDATA[AS3 / Flex]]></category>
		<category><![CDATA[Flash in general]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[box2d]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[tweening]]></category>

		<guid isPermaLink="false">http://www.ghost23.de/?p=484</guid>
		<description><![CDATA[Juten tach, i am currently involved in a fun project, where i am told to build a classical jump &#8216;n run game. Very nice. I am using the flash port of Box2d in its version 2.0.1. I know, that there is version 2.1, but it&#8217;s still alpha and i generally do not feel so comfortable [...]]]></description>
			<content:encoded><![CDATA[<p>Juten tach,</p>
<p>i am currently involved in a fun project, where i am told to build a classical jump &#8216;n run game. Very nice. I am using the flash port of Box2d in its version 2.0.1. I know, that there is version 2.1, but it&#8217;s still alpha and i generally do not feel so comfortable using alpha software.</p>
<p>Like in most jump &#8216;n run games, we have moving obstacles, like little bricks, that move from left to right and back again and you have to jump on them to get over a giant abyss.</p>
<p>Now these moving bricks should move autonomously and indefinitely. Being a flash developer, first thing, that comes to mind is tweening them. But as we learn from many sources in the box2d community, this is actually a no-go, because we should rather use velocities and the real physics of Box2d to make things move. Makes sense to me.</p>
<p>So my first attempt was to reuse some of the <a href="http://www.kerp.net/box2d/displaylesson.php?chapter=2&amp;lesson=26" target="_blank">smart scripts from Todd</a>. And that worked quite well. Here is an excerpt of the script (actually with slight changes from my side), that will run in the usual world update method (box2d specific):</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>currentPosition<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">&gt;</span>= initialPosition<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span> movementDistance<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
   _direction = <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span><span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>currentPosition<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">&lt;</span>= initialPosition<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
   _direction = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> idealLocation<span style="color: #000066; font-weight: bold;">:</span>b2Vec2 = <span style="color: #0033ff; font-weight: bold;">new</span> b2Vec2<span style="color: #000000;">&#40;</span>currentPosition<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span>_direction <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000;">&#40;</span>TRAVEL_SPEED <span style="color: #000066; font-weight: bold;">/</span> PhysiVals<span style="color: #000066; font-weight: bold;">.</span>RATIO<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> initialPosition<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> directionToTravel<span style="color: #000066; font-weight: bold;">:</span>b2Vec2 = idealLocation<span style="color: #000066; font-weight: bold;">.</span>Copy<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
directionToTravel<span style="color: #000066; font-weight: bold;">.</span>Subtract<span style="color: #000000;">&#40;</span>currentPosition<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
directionToTravel<span style="color: #000066; font-weight: bold;">.</span>Multiply<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">30</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
_body<span style="color: #000066; font-weight: bold;">.</span>SetLinearVelocity<span style="color: #000000;">&#40;</span>directionToTravel<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>So looking at this, after a while i thought, idealLocation is a point, that changes on every box2d world step and reflects the position, where the body should be. Isn&#8217;t that the same thing, that a tweener does? Of course, it is.<br />
So changing this script to use a tweener like TweenLite or something is pretty easy. In my case, i am using TimelineMax, because i want to let my body to move back and forth infinitely (code simplified):</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> positionTracker<span style="color: #000066; font-weight: bold;">:</span>b2Vec2<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> initialize<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
   positionTracker = initialPosition<span style="color: #000066; font-weight: bold;">.</span>Copy<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   timeline = <span style="color: #0033ff; font-weight: bold;">new</span> TimelineMax<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#123;</span>repeat<span style="color: #000066; font-weight: bold;">:-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   timeline<span style="color: #000066; font-weight: bold;">.</span>append<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> TweenLite<span style="color: #000000;">&#40;</span>positionTracker<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000;">&#123;</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">:</span>initialPosition<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">+</span> movementDistance<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   timeline<span style="color: #000066; font-weight: bold;">.</span>append<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> TweenLite<span style="color: #000000;">&#40;</span>positionTracker<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000;">&#123;</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">:</span>initialPosition<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onWorldUpdate<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
   <span style="color: #6699cc; font-weight: bold;">var</span> currentPosition<span style="color: #000066; font-weight: bold;">:</span>b2Vec2 = myBody<span style="color: #000066; font-weight: bold;">.</span>GetXForm<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">position</span><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #6699cc; font-weight: bold;">var</span> directionToTravel<span style="color: #000066; font-weight: bold;">:</span>b2Vec2 = positionTracker<span style="color: #000066; font-weight: bold;">.</span>Copy<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   directionToTravel<span style="color: #000066; font-weight: bold;">.</span>Subtract<span style="color: #000000;">&#40;</span>currentPosition<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   directionToTravel<span style="color: #000066; font-weight: bold;">.</span>Multiply<span style="color: #000000;">&#40;</span>Environment<span style="color: #000066; font-weight: bold;">.</span>TIME_STEP<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   myBody<span style="color: #000066; font-weight: bold;">.</span>SetLinearVelocity<span style="color: #000000;">&#40;</span>directionToTravel<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>So, what is happening here? Well, we keep a helper object, the positionTracker. This is our object, that gets modified by our tweener. It is a b2Vec2 instance, which has x and y attributes. We give the positionTracker our initialPosition of our box2d body. Then we create our tween, just the normal way we always use tweens. But we use our positionTracker with it.</p>
<p>Now, somewhere in our program we usually have a world update method, because that&#8217;s how Box2D works. And here we simply use the approach <a href="http://www.kerp.net/box2d/displaylesson.php?chapter=2&amp;amp;lesson=26" target="_blank">Todd uses in his tutorial</a>, we take the current position of our body, calculate the difference from our desired location (which now is the location our tweener has calculated) and the current location and build a velocity vector from it, which we then set to our body.</p>
<p>The result is a crystal clear animation just the way we have defined it in our tween. But since we are setting a velocity, our body is still open for other forces, that have an impact on it. So in my case, when my character jumps on the brick, the brick eases off a bit, but quickly goes back on its path, which is a rather nice behavior, i think.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghost23.de/2011/02/using-tweens-with-box2d-2-0-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ActionScript 3 library CommandCollection released</title>
		<link>http://www.ghost23.de/2010/12/actionscript-3-library-commandcollection-released/</link>
		<comments>http://www.ghost23.de/2010/12/actionscript-3-library-commandcollection-released/#comments</comments>
		<pubDate>Tue, 14 Dec 2010 16:49:49 +0000</pubDate>
		<dc:creator>Sven Busse</dc:creator>
				<category><![CDATA[AS3 / Flex]]></category>
		<category><![CDATA[Flash in general]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[commands]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[library]]></category>

		<guid isPermaLink="false">http://www.ghost23.de/?p=434</guid>
		<description><![CDATA[Juten Tach, today i release a little library i have been working on for quite a while. It contains three little class collections, i have used in the past and i thought, they might be useful for some. CommandCollection is a little ActionScript 3 library around using commands. It includes three tools: Process BranchProcess StateMachine [...]]]></description>
			<content:encoded><![CDATA[<p>Juten Tach,</p>
<p>today i release a little library i have been working on for quite a while. It contains three little class collections, i have used in the past and i thought, they might be useful for some.</p>
<p>CommandCollection is a little ActionScript 3 library around using commands. It includes three tools:</p>
<ul>
<li>Process</li>
<li>BranchProcess</li>
<li>StateMachine</li>
</ul>
<p><em>Process</em> is essentially a queue, in which you can put commands (synchronous or asynchronous), which will be executed sequentially.</p>
<p><em>BranchProcess</em> is similar, but allows you to build a tree of commands with the ability of one commands result having an impact on which command comes next.</p>
<p><em>StateMachine</em> is a classical finite state machine, that supports input commands for each state and is navigable. Means, you can aim for a state and the state machine will calculate a path to the target state and will try to reach it.</p>
<p>CommandCollection comes as .swc for integration into your project. Go check it out at <a href="http://code.google.com/p/command-collection/">http://code.google.com/p/command-collection/</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghost23.de/2010/12/actionscript-3-library-commandcollection-released/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MouseEvent.relatedObject</title>
		<link>http://www.ghost23.de/2010/11/mouseevent-relatedobject/</link>
		<comments>http://www.ghost23.de/2010/11/mouseevent-relatedobject/#comments</comments>
		<pubDate>Sun, 14 Nov 2010 16:03:54 +0000</pubDate>
		<dc:creator>Sven Busse</dc:creator>
				<category><![CDATA[AS3 / Flex]]></category>
		<category><![CDATA[Flash in general]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[mouse]]></category>

		<guid isPermaLink="false">http://www.ghost23.de/?p=405</guid>
		<description><![CDATA[Juten Tach, i just recently stumbled upon this little gem: MouseEvent.relatedObject. It turns out, it already exists since FlashPlayer 9.0, but i missed it. It is a pretty useful property. In a nutshell, it holds a reference to the object, which either lost or gained focus during mouse over or mouse out respectively. So i thought, i [...]]]></description>
			<content:encoded><![CDATA[<p>Juten Tach,</p>
<p>i just recently stumbled upon this little gem: MouseEvent.relatedObject. It turns out, it already exists since FlashPlayer 9.0, but i missed it. It is a pretty useful property. In a nutshell, it holds a reference to the object, which either lost or gained focus during mouse over or mouse out respectively. So i thought, i make a little example:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
&nbsp;
   <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
   <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> HelloWorld <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> panel<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> button1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> button2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> HelloWorld<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
         panel = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
         panel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span>0x777777<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
         panel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">drawRect</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">150</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
         panel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
         panel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span>
         panel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
         button1 = createButton<span style="color: #000000;">&#40;</span>0xff0000<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
         button2 = createButton<span style="color: #000000;">&#40;</span>0x0000ff<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">120</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
         panel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span>      = <span style="color: #990000;">&quot;Panel&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
         button1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span>   = <span style="color: #990000;">&quot;Button 1&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
         button2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span>   = <span style="color: #990000;">&quot;Button 2&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
         <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>panel<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
         <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>button1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
         <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>button2<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
         <span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_OVER</span><span style="color: #000066; font-weight: bold;">,</span> onMouseOver<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onMouseOver<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
         <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>
            <span style="color: #990000;">&quot;Mouse now over: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span> <span style="color: #000066; font-weight: bold;">+</span>
            <span style="color: #990000;">&quot;. Used to be over: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">relatedObject</span> <span style="color: #000066; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000066; font-weight: bold;">?</span> event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">relatedObject</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #990000;">&quot;n/a&quot;</span><span style="color: #000000;">&#41;</span>
         <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> createButton<span style="color: #000000;">&#40;</span><span style="color: #004993;">color</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
&nbsp;
         <span style="color: #6699cc; font-weight: bold;">var</span> result<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
         result<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">color</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
         result<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">drawRect</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
         result<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
         result<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">;</span>
         result<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
         <span style="color: #0033ff; font-weight: bold;">return</span> result<span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
   <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Instead of explaining everything, simply take a look at the result (in which i added a textfield, so you can see the traces). You will see, that whenever you roll on the panel from the main stage (which is colored in this aesthetically bright yellow), the relatedObject is null.</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_0" width="300" height="250">
      <param name="movie" value="http://www.ghost23.de/wp-content/uploads/HelloWorld.swf" />
      <param name="bgcolor" value="#ffffee" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://www.ghost23.de/wp-content/uploads/HelloWorld.swf" width="300" height="250" bgcolor="#ffffee">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

]]></content:encoded>
			<wfw:commentRss>http://www.ghost23.de/2010/11/mouseevent-relatedobject/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Eventhandlers &#8211; should they be class members? [Update: probably yes]</title>
		<link>http://www.ghost23.de/2010/10/eventhandlers-should-they-be-class-members/</link>
		<comments>http://www.ghost23.de/2010/10/eventhandlers-should-they-be-class-members/#comments</comments>
		<pubDate>Sun, 10 Oct 2010 12:27:22 +0000</pubDate>
		<dc:creator>Sven Busse</dc:creator>
				<category><![CDATA[AS3 / Flex]]></category>
		<category><![CDATA[Flash in general]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[events]]></category>

		<guid isPermaLink="false">http://www.ghost23.de/?p=376</guid>
		<description><![CDATA[Juten Tach, you probably know this setting perfectly well: package &#123; public class Example &#123; &#160; private var myDispatchingObject:DispatchingObject; &#160; // ... &#160; private function createSomething&#40;&#41;:void &#123; &#160; myDispacthingObject = new DispatchingObject&#40;&#41;; myDispatchingObject.addEventListener&#40;SomeEvent.COMPLETE, onDispatcherComplete&#41;; myDispatchingObject.start&#40;&#41;; &#160; // ... &#125; &#160; private function onDispatcherComplete&#40;evt:SomeEvent&#41;:void &#123; &#160; if&#40;evt.something == true&#41; doSomethingImportant&#40;&#41;; &#125; &#160; private function doSomethingImportant&#40;&#41;:void &#123; [...]]]></description>
			<content:encoded><![CDATA[<p>Juten Tach,</p>
<p>you probably know this setting perfectly well:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
   <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Example <span style="color: #000000;">&#123;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> myDispatchingObject<span style="color: #000066; font-weight: bold;">:</span>DispatchingObject<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
      <span style="color: #009900; font-style: italic;">// ...</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> createSomething<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
         myDispacthingObject = <span style="color: #0033ff; font-weight: bold;">new</span> DispatchingObject<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
         myDispatchingObject<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>SomeEvent<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> onDispatcherComplete<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
         myDispatchingObject<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
         <span style="color: #009900; font-style: italic;">// ...</span>
      <span style="color: #000000;">&#125;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onDispatcherComplete<span style="color: #000000;">&#40;</span>evt<span style="color: #000066; font-weight: bold;">:</span>SomeEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
         <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>evt<span style="color: #000066; font-weight: bold;">.</span>something == <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span> doSomethingImportant<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> doSomethingImportant<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
         <span style="color: #009900; font-style: italic;">// ...</span>
      <span style="color: #000000;">&#125;</span>
   <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>This class is very simple, it has an object which apparently dispatches an event. You add yourself as a listener and implement an event handler.</p>
<p>You also know, that if your class uses a bunch of objects, which dispatch events, your own class becomes littered with event handler methods. Here&#8217;s a thought i just had, which aims for making this a bit more readable (which in the end is the opposite of being new. I just noticed, that for some reason, i have stopped doing it this way in the past):</p>
<p>The purpose of an event handler should be:</p>
<ul>
<li>check, if the event is relevant.</li>
<li>If yes, call some functionality.</li>
</ul>
<p>Now, this is important. If you do not agree with these two things, you don&#8217;t have to read any further. A lot of times, we tend to put more into our event handlers, than these two things. But we shouldn&#8217;t, because all the additional functionality is then bound to that event. As soon as you recognize, that you might want to call that functionality at another point in time, too, you will separate the handling part from the actual functionality anyway.</p>
<p>So, if you&#8217;re still with me, you will probably also agree, that you never want to call the event handler function directly, because it is purely meant to be invoked by, well, an event.</p>
<p>So i thought, why actually defining it as a class member? If the whole purpose is for wiring an event to another function, wouldn&#8217;t it be more appropriate to use an inner function instead?</p>
<p><strong>[Update]</strong>: OK, that was quick. As Hristo points out, this whole thing makes no sense, if you ever want to remove yourself as a listener and don&#8217;t want to do tricks like using arguments.callee. Bummer.</p>
<p>Let&#8217;s rewrite the above example accordingly:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
   <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Example <span style="color: #000000;">&#123;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> myDispatchingObject<span style="color: #000066; font-weight: bold;">:</span>DispatchingObject<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
      <span style="color: #009900; font-style: italic;">// ...</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> createSomething<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
         myDispacthingObject = <span style="color: #0033ff; font-weight: bold;">new</span> DispatchingObject<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
         myDispatchingObject<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>SomeEvent<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #000000;">&#40;</span>evt<span style="color: #000066; font-weight: bold;">:</span>SomeEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>evt<span style="color: #000066; font-weight: bold;">.</span>something == <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span> doSomethingImportant<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
         <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
         myDispatchingObject<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
         <span style="color: #009900; font-style: italic;">// ...</span>
      <span style="color: #000000;">&#125;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> doSomethingImportant<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
         <span style="color: #009900; font-style: italic;">// ...</span>
      <span style="color: #000000;">&#125;</span>
   <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>By the way, i was a bit astonished at first, that it works this way. Like, that doSomethingImportant() is available within the inner function. Seems like closures do not only have access to their parent function, but also to class members. I think, that used not to work in the past, or am i mixing things up?!</p>
<p>Anyway, doing it this way, has a couple of advantages in my opinion:</p>
<ul>
<li>The wiring of the event becomes directly apparent and it happens at a place, you would search for anyway, because the DispatchingObject is created there.</li>
<li>Since the event handler function is now an inner function of the createSomething method, it cannot accidentally be called directly.</li>
<li>All methods in the class are ones, that are valid to be called. No litter of event handler methods.</li>
</ul>
<p>So, again, this not new at all, but i know a lot of developers, who have not been doing event handlers this way for ages anymore (including me). You might say, that using inner functions brings a bad smell with it. But perhaps this is just a &#8220;i&#8217;m not used to this&#8221; feeling?!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghost23.de/2010/10/eventhandlers-should-they-be-class-members/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Events &#8211; still no first-class citizens of ActionScript</title>
		<link>http://www.ghost23.de/2010/10/events-still-no-first-class-citizens-of-actionscript/</link>
		<comments>http://www.ghost23.de/2010/10/events-still-no-first-class-citizens-of-actionscript/#comments</comments>
		<pubDate>Fri, 08 Oct 2010 20:17:49 +0000</pubDate>
		<dc:creator>Sven Busse</dc:creator>
				<category><![CDATA[Flash in general]]></category>
		<category><![CDATA[Stuff]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[language]]></category>

		<guid isPermaLink="false">http://www.ghost23.de/?p=367</guid>
		<description><![CDATA[Juten Tach, today i was juggling with Events quite a bit. By the way, isn&#8217;t it odd, that EventDispatcher does not reveal its listeners? At least to its subclasses? Or at the very least have some kind of &#8220;removeAllListeners()&#8221; method (like Robert Penner already noticed)? Anyway, i was thinking: Events in Flash are all over [...]]]></description>
			<content:encoded><![CDATA[<p>Juten Tach,</p>
<p>today i was juggling with Events quite a bit. By the way, isn&#8217;t it odd, that EventDispatcher does not reveal its listeners? At least to its subclasses? Or at the very least have some kind of &#8220;removeAllListeners()&#8221; method (like <a href="http://flashblog.robertpenner.com/2009/09/my-critique-of-as3-events-part-2.html" target="_blank">Robert Penner</a> already noticed)?</p>
<p>Anyway, i was thinking: Events in Flash are all over the place nowadays. You use them in DisplayObjects, in your classes and also Flex has them everywhere. The good thing about them is, they could make threads needless. I sometimes see some developers shout for threads in Flash and i want to shout back: &#8220;Are you kidding?&#8221; To whomever Java developer i speak to, they all say, handling threads is a mess. I have no practical experience myself, but i know the basics of threads in Java. Events come to the rescue. They are easy to understand and to handle. It would only take the ability to dispatch an Event, which only fires AFTER the return of the method, that wanted to fire it. This way, we would be able to avoid weird issues like: &#8220;ClassA instantiates ClassB, adds itself as a listener to ClassB, but ClassB already fires an event in its constructor&#8221; (yeah, i know, not the best example, but i hope you get the point). And all the multicore and threading stuff could be managed in the background.</p>
<p>I think, Events should become first-class citizens of the ActionScript language at long last. It would allow for some cool new ways of expressing things. Imagine this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
&nbsp;
   <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>sample<span style="color: #000066; font-weight: bold;">.</span>CoolEvent<span style="color: #000066; font-weight: bold;">;</span>
   <span style="color: #0033ff; font-weight: bold;">import</span> org<span style="color: #000066; font-weight: bold;">.</span>sample<span style="color: #000066; font-weight: bold;">.</span>OtherEvent<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
   <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Example dispatches CoolEvent<span style="color: #000066; font-weight: bold;">,</span>OtherEvent <span style="color: #000000;">&#123;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">private</span> listener myListener<span style="color: #000066; font-weight: bold;">:</span>EventFromCoolOtherClass<span style="color: #000066; font-weight: bold;">.</span>STARTED<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Example<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
         <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
         someOtherClass = <span style="color: #0033ff; font-weight: bold;">new</span> CoolOtherClass<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
         myListener = someOtherClass <span style="color: #000066; font-weight: bold;">&amp;</span>gt<span style="color: #000066; font-weight: bold;">;&amp;</span>gt<span style="color: #000066; font-weight: bold;">;</span> someHandlerMethod<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
         <span style="color: #009900; font-style: italic;">// blah, doing stuff</span>
&nbsp;
         dispatch async <span style="color: #0033ff; font-weight: bold;">new</span> CoolEvent<span style="color: #000000;">&#40;</span>CoolEvent<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> someHandlerMethod<span style="color: #000000;">&#40;</span>evt<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
         myListener = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
&nbsp;
      <span style="color: #009900; font-style: italic;">// ...</span>
&nbsp;
      <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> someOtherFunction<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
         <span style="color: #009900; font-style: italic;">// blah, doing more stuff</span>
&nbsp;
         dispatch <span style="color: #0033ff; font-weight: bold;">new</span> OtherEvent<span style="color: #000000;">&#40;</span>OtherEvent<span style="color: #000066; font-weight: bold;">.</span>STOPPED<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      <span style="color: #000000;">&#125;</span>
   <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>These are just some thoughts, that came out of my head within the last hours. For example, it would be nice to be able to define officially, which events a class dispatches. And if you define it in the class header, you have to implement the dispatching, otherwise you&#8217;d get a compile time error (we could need this for errors as well, by the way, but different story). Then the &#8216;listener&#8217; property. It works a bit like a pipe. Yo specify the listener and give it the Event type, you&#8217;re interested in. And in code you wire the dispatcher together with your handler method. Simply unwire by setting the listener to null.</p>
<p>Dispatching an event is almost like today, but you have the async option, which let&#8217;s the init method return, before the event is fired, which releases the stack (only works, if dispatch is the last statement in the method body, of course).</p>
<p>Probably i have forgotten some details, which might make these things not work the way i imagine, but anyway: Events should finally become a part of the ActionScript DNA.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghost23.de/2010/10/events-still-no-first-class-citizens-of-actionscript/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Multiframe swf files and external libraries</title>
		<link>http://www.ghost23.de/2010/10/multiframe-swf-files-and-external-libraries/</link>
		<comments>http://www.ghost23.de/2010/10/multiframe-swf-files-and-external-libraries/#comments</comments>
		<pubDate>Mon, 04 Oct 2010 17:29:02 +0000</pubDate>
		<dc:creator>Sven Busse</dc:creator>
				<category><![CDATA[AS3 / Flex]]></category>
		<category><![CDATA[Flash in general]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[compiler]]></category>

		<guid isPermaLink="false">http://www.ghost23.de/?p=362</guid>
		<description><![CDATA[Juten Tach, today i stumbled upon a weird bug in the mxmlc compiler. I filed a bug, which turned out to be a duplicate of an earlier report here. It basically goes like this: Say, you have a swf file, which wants to spread its classes over multiple frames (if you read my previous post, [...]]]></description>
			<content:encoded><![CDATA[<p>Juten Tach,</p>
<p>today i stumbled upon a weird bug in the mxmlc compiler. I filed a bug, which turned out to be a duplicate of an <a href="https://bugs.adobe.com/jira/browse/SDK-26802" target="_blank">earlier report here</a>.</p>
<p>It basically goes like this:</p>
<p>Say, you have a swf file, which wants to spread its classes over multiple frames (if you read my <a href="http://www.ghost23.de/2010/10/one-swf-multiple-classes-multiple-applicationdomains/" target="_blank">previous post</a>, it might sound familiar). So, to keep things simple, let&#8217;s say, you want to have two frames, each holding one class, let&#8217;s call them FirstFrameClass and SecondFrameClass. And additionally this swf file uses an external library, means, a .swc that should NOT be compiled into our .swf. Let&#8217;s assume, in that .swf there is one class, we call it LibraryClass.</p>
<p>Now the weirdness starts. If FirstFrameClass references LibraryClass, LibraryClass gets compiled into our resulting swf, although we specified the library to be an external one (using external-library-path in the compiler configuration). If instead SecondFrameClass references LibraryClass and not FirstFrameClass, LibraryClass gets NOT compiled into our resulting .swf file, just the way we want it.</p>
<p>In the end, the issue is, only if you reference a class from an external library in a class, which sits on the last frame of your own .swf file, the external-library option works, otherwise it is simply ignored.</p>
<p>In the <a href="https://bugs.adobe.com/jira/browse/SDK-26802" target="_blank">bug report</a> it says, the issue will be resolved for the upcoming Flex Hero release. I tested with the current build, but the issue is not resolved yet (which makes sense, because the bug entry in Adobes bug tracker is not set to Resolved yet).</p>
<p>If you find this as weird as i do, please <a href="https://bugs.adobe.com/jira/browse/SDK-26802" target="_blank">vote for the bug</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghost23.de/2010/10/multiframe-swf-files-and-external-libraries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Another singleton</title>
		<link>http://www.ghost23.de/2010/05/another-singleton/</link>
		<comments>http://www.ghost23.de/2010/05/another-singleton/#comments</comments>
		<pubDate>Sun, 02 May 2010 08:41:47 +0000</pubDate>
		<dc:creator>Sven Busse</dc:creator>
				<category><![CDATA[AS3 / Flex]]></category>
		<category><![CDATA[Flash in general]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[singleton]]></category>

		<guid isPermaLink="false">http://www.ghost23.de/?p=304</guid>
		<description><![CDATA[Juten Tach, i know, everybody hates Singletons, and i do, too. But i find it an entertaining exercise to come up with new ways of circumventing the lack of private constructors for Singletons. Today this new one came to my mind: First, we define an Interface, which specifies, how our Singleton should look like: IMySingelton.as: [...]]]></description>
			<content:encoded><![CDATA[<p>Juten Tach,</p>
<p>i know, everybody hates Singletons, and i do, too. But i find it an entertaining exercise to come up with new ways of circumventing the lack of private constructors for Singletons. Today this new one came to my mind:</p>
<p>First, we define an Interface, which specifies, how our Singleton should look like:</p>
<p>IMySingelton.as:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> interface IMySingleton <span style="color: #000000;">&#123;</span>
		<span style="color: #339966; font-weight: bold;">function</span> doodle<span style="color: #000000;">&#40;</span>something<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Ok, next we define our Singleton.</p>
<p>myInstance.as:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> myInstance<span style="color: #000066; font-weight: bold;">:</span>IMySingleton = <span style="color: #0033ff; font-weight: bold;">new</span> MySingleton<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #9900cc; font-weight: bold;">class</span> MySingleton implements IMySingleton <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> MySingleton<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;MySingleton is now there!&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> doodle<span style="color: #000000;">&#40;</span>something<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;yippee: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> something<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Very simple, isn&#8217;t it? We could optionally also go without the Interface, but then we loose code completion in our editors, because the class MySingleton will be ignored by most editors, although it would compile and run just fine. I do agree, that this is not really exactly the idea of a Singleton, because it has no getInstance() method, but in the end, the result is the same, we only have one global instance of MySingleton.</p>
<p>And since the variable is already global, we don&#8217;t even have to declare it in our class, we can directly use it:</p>
<p>Main.as:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Main <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			myInstance<span style="color: #000066; font-weight: bold;">.</span>doodle<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;loodle&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.ghost23.de/2010/05/another-singleton/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Flash/iphone chapter closed, let&#8217;s move on</title>
		<link>http://www.ghost23.de/2010/04/flashiphone-chapter-closed-lets-move-on/</link>
		<comments>http://www.ghost23.de/2010/04/flashiphone-chapter-closed-lets-move-on/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 08:45:06 +0000</pubDate>
		<dc:creator>Sven Busse</dc:creator>
				<category><![CDATA[Flash in general]]></category>
		<category><![CDATA[Stuff]]></category>
		<category><![CDATA[androiod]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flash player]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://www.ghost23.de/?p=300</guid>
		<description><![CDATA[Juten Tach, now, that this flash / iphone thing is closed, Adobe, can you please make sure, that Flash Player 10.1 on Android will be nothing else but mind-blowing? You know, not like &#8220;it works OK&#8221;, but more like &#8220;wtf, is this flash? you&#8217;re kidding. this is flash? Can&#8217;t believe it, this is sooo fast!&#8221;. [...]]]></description>
			<content:encoded><![CDATA[<p>Juten Tach,</p>
<p>now, that this <a href="http://www.mikechambers.com/blog/2010/04/20/on-adobe-flash-cs5-and-iphone-applications/" target="_blank">flash / iphone thing is closed</a>, Adobe, can you please make sure, that Flash Player 10.1 on Android will be nothing else but mind-blowing? You know, not like &#8220;it works OK&#8221;, but more like &#8220;wtf, is this flash? you&#8217;re kidding. this is flash? Can&#8217;t believe it, this is sooo fast!&#8221;. It doesn&#8217;t matter matter, if it takes another month, but please get this right.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghost23.de/2010/04/flashiphone-chapter-closed-lets-move-on/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

