<?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>Barklund.org &#187; Flash Platform</title>
	<atom:link href="http://www.barklund.org/blog/category/programming/flash-platform/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.barklund.org/blog</link>
	<description>work smarter when building current web trends</description>
	<lastBuildDate>Wed, 26 May 2010 09:49:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Why events suck in ActionScript 3</title>
		<link>http://www.barklund.org/blog/2010/05/07/events-suck-actionscript-3/</link>
		<comments>http://www.barklund.org/blog/2010/05/07/events-suck-actionscript-3/#comments</comments>
		<pubDate>Thu, 06 May 2010 22:04:45 +0000</pubDate>
		<dc:creator>Barklund</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Trends]]></category>

		<guid isPermaLink="false">http://www.barklund.org/blog/?p=788</guid>
		<description><![CDATA[I&#8217;ve had it with events in ActionScript 3! They are annoying to structure, annoying to extend, annoying to dispatch but most importantly annoying to consume &#8211; and I consume events a lot more than write or dispatch my own. But! The idea of listening for stuff I really do like. I have some ideas about [...]


Related posts:<ol><li><a href='http://www.barklund.org/blog/2009/11/23/link-sharing-spam-facebook/' rel='bookmark' title='Permanent Link: Link sharing spam on Facebook'>Link sharing spam on Facebook</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div id="attachment_804" class="wp-caption alignright" style="width: 336px"><a href="http://www.barklund.org/blog/wp-content/uploads/2010/05/ignoring_the_event.png"><img src="http://www.barklund.org/blog/wp-content/uploads/2010/05/ignoring_the_event.png" alt="" title="Ignoring the event" width="326" height="93" class="size-full wp-image-804" /></a><p class="wp-caption-text">I actually took this from production code!</p></div>
<p>I&#8217;ve had it with events in ActionScript 3! They are annoying to structure, annoying to extend, annoying to dispatch but most importantly annoying to consume &#8211; and I consume events a lot more than write or dispatch my own.</p>
<p>But! The idea of listening for stuff I really do like. I have some ideas about how this could be done a lot easier. Oh, and please stick around until the very end of this post.</p>
<p><span id="more-788"></span></p>
<h3 id="toc-background">Background</h3>
<p>For those who can&#8217;t remember exactly, events in AS3 are consumed by listening for certain events and passing a function, that will be called when this event occurs. The function will <strong>always</strong> be invoked with the event type, that you listen for &#8211; and only that argument will be given to the callback. You cannot define extra arguments in any way or not accept the event argument. Let&#8217;s for example listen for when the use clicks a button &#8211; which is the <code>MouseEvent.CLICK</code> event (of type <code>MouseEvent</code> of course):</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</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: #000000; 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> myButton<span style="color: #000000; 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>;
  ...
  myButton.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>, buttonPressed<span style="color: #000000;">&#41;</span>;
  ...
<span style="color: #000000;">&#125;</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> buttonPressed<span style="color: #000000;">&#40;</span>me<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; 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;the button has been pressed, hurray&quot;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>We abidingly accept the <code>me:MouseEvent</code> argument even though we don&#8217;t intend to use it.</p>
<p>The event object has information about the event, about who sent it, information related to the bubbling nature of events (that very few people ever use in ActionScript 3) and additional specific attributes only relevant for specific events. For instance, if we have several buttons representing different related actions, we can examine the <code>event.target</code property to see which of the dispatcher send the event:</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> selectRed<span style="color: #000000; font-weight: bold;">:</span>ColorButton;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> selectGreen<span style="color: #000000; font-weight: bold;">:</span>ColorButton ;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> selectBlue<span style="color: #000000; font-weight: bold;">:</span>ColorButton;
<span style="color: #0033ff; font-weight: bold;">public</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: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
  ...
  selectRed.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>, selectColor<span style="color: #000000;">&#41;</span>;
  selectGreen.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>, selectColor<span style="color: #000000;">&#41;</span>;
  selectBlue.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>, selectColor<span style="color: #000000;">&#41;</span>;
  ...
<span style="color: #000000;">&#125;</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> selectColor<span style="color: #000000;">&#40;</span>me<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; 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> <span style="color: #004993;">color</span><span style="color: #000000; font-weight: bold;">:</span>ColorButton = me.<span style="color: #004993;">target</span> <span style="color: #0033ff; font-weight: bold;">as</span> ColorButton;
  <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span><span style="color: #004993;">color</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">throw</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Error</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;color selected was not actually a color&quot;</span><span style="color: #000000;">&#41;</span>;
  <span style="color: #000000;">&#125;</span>
  <span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">color</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">case</span> selectRed<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;you chose a red Papa Smurf&quot;</span><span style="color: #000000;">&#41;</span>; <span style="color: #0033ff; font-weight: bold;">break</span>;
    <span style="color: #0033ff; font-weight: bold;">case</span> selectGreen<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;you chose a green Papa Smurf&quot;</span><span style="color: #000000;">&#41;</span>; <span style="color: #0033ff; font-weight: bold;">break</span>;
    <span style="color: #0033ff; font-weight: bold;">case</span> selectBlue<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;you chose a blue Papa Smurf&quot;</span><span style="color: #000000;">&#41;</span>; <span style="color: #0033ff; font-weight: bold;">break</span>;
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Here, we do use the <code>MouseEvent</code>-object, but we cast the target property to the type we expect it to have and then we need to check, if the cast went well. Because, technically we could have used the same function as a listener for something else somewhere else (even though we know we didn't) and thus <code>target</code> could have been something entirely different.</p>
<h3 id="toc-personal-experiences">Personal experiences</h3>
<p>I've just checked a recent, larger project with 185 (home-made) classes. In general I try to minimize my event usage, but a lot of things I have to use events for event though I don't really need them, so I ran a simple script counting how many times I had a function that took an event as an argument, and how many of these actually used the event object. The result was 121 functions accepting an event as argument (10 of those had default null values), and in only 4 of those I actually used the event argument (one of them a <code>KeyboardEvent</code>, the others were all the same home-made <code>PageEvent</code>). 83 of the events accepted were <code>MouseEvent</code>s (which is no surprise), and never was the <code>me:MouseEvent</code> variable used in the function body.</p>
<p>Then, I tested an even earlier project from before I started minimizing event usage (almost maximized it back then). It consisted of 50 (home-made) classes. It had 113 functions (a lot more per class than the above) accepting event arguments (16 of those defaulting to null) and 74 of those were <code>MouseEvent</code>s. And this time around, I used the event argument 25 times, but 18 of these usages were accessing <code>event.target</code> or <code>event.data</code> and casting it to the right class. Thus, yes I did use the event argument in some cases (22% of the time I accepted an argument), but in most of them I still had to do manual casting of the <code>event.target</code> (or <code>event.data</code>) attribute to get the type I knew I was accessing. This leaves only 7 "true" usages or about 6%. Please see the background section about why using the event object for casting only just moves the problem around and makes the code even more verbose.</p>
<h3 id="toc-dream-scenario">Dream scenario</h3>
<p>So, what would I like instead? Something intelligent, that allows me to accept the arguments I need <em>when</em> I need them. For instance, take this snippet here:</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> <span style="color: #004993;">close</span><span style="color: #000000; font-weight: bold;">:</span>CloseButton;
<span style="color: #0033ff; font-weight: bold;">public</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: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
  <span style="color: #004993;">close</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>, closeDialog<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> closeDialog<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
  someDialog.fadeToOblivion<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>It is simple, I do not need any argument, so I do not expect one.</p>
<p>A often used situation is when you have several instances of the same type and attach the same listener to all of these, then you use the event argument's target attribute for switching on which instance was invoked and handling the result correspondingly:</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> downloadLowRes<span style="color: #000000; font-weight: bold;">:</span>DownloadButton;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> downloadMediumRes<span style="color: #000000; font-weight: bold;">:</span>DownloadButton;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> downloadHighRes<span style="color: #000000; font-weight: bold;">:</span>DownloadButton;
<span style="color: #0033ff; font-weight: bold;">public</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: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
  downloadLowRes.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>, <span style="color: #004993;">download</span><span style="color: #000000;">&#41;</span>;
  downloadMediumRes.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>, <span style="color: #004993;">download</span><span style="color: #000000;">&#41;</span>;
  downloadHighRes.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>, <span style="color: #004993;">download</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">download</span><span style="color: #000000;">&#40;</span>db<span style="color: #000000; font-weight: bold;">:</span>DownloadButton<span style="color: #000000;">&#41;</span><span style="color: #000000; 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;">switch</span> <span style="color: #000000;">&#40;</span>db<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">case</span> downloadLowRes<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">open</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;file_360p.avi&quot;</span><span style="color: #000000;">&#41;</span>; <span style="color: #0033ff; font-weight: bold;">break</span>;
    <span style="color: #0033ff; font-weight: bold;">case</span> downloadMediumRes<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">open</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;file_720p.avi&quot;</span><span style="color: #000000;">&#41;</span>; <span style="color: #0033ff; font-weight: bold;">break</span>;
    <span style="color: #0033ff; font-weight: bold;">case</span> downloadHighRes<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">open</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;file_1080p.avi&quot;</span><span style="color: #000000;">&#41;</span>; <span style="color: #0033ff; font-weight: bold;">break</span>;
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The function expects a reference to the button clicked - not to an event, who references the button clicked, because only the actual button reference is necessary.</p>
<p>Finally, a more elaborate example of different other component listeners expecting just what they need and nothing else:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</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: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
  <span style="color: #009900;">// listen for selections in a dropdown</span>
  countryDropdown.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">SELECT</span>, selectCountry<span style="color: #000000;">&#41;</span>;
&nbsp;
  <span style="color: #009900;">// listen for checkbox changes</span>
  acceptTermsCheckbox.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">CHANGE</span>, acceptTerms<span style="color: #000000;">&#41;</span>;
&nbsp;
  <span style="color: #009900;">// listen for focus changes between password input fields</span>
  passwordInput.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">FocusEvent</span>.<span style="color: #004993;">FOCUS_OUT</span>, checkPasswords<span style="color: #000000;">&#41;</span>;
  passwordConfirmInput.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">FocusEvent</span>.<span style="color: #004993;">FOCUS_OUT</span>, checkPasswords<span style="color: #000000;">&#41;</span>;
&nbsp;
  <span style="color: #009900;">// listen for three different radio buttons changing</span>
  languageDanish.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">SELECT</span>, selectLanguage<span style="color: #000000;">&#41;</span>;
  languageSwedish.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">SELECT</span>, selectLanguage<span style="color: #000000;">&#41;</span>;
  languageNorwegian.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span>.<span style="color: #004993;">SELECT</span>, selectLanguage<span style="color: #000000;">&#41;</span>;
&nbsp;
  <span style="color: #009900;">// listen for submit button presses</span>
  submitButton.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>, submit<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> selectCountry<span style="color: #000000;">&#40;</span>country<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
  selectedCountry = country;
<span style="color: #000000;">&#125;</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> acceptTerms<span style="color: #000000;">&#40;</span>accepted<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
  termsAccepted = accepted;
<span style="color: #000000;">&#125;</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> checkPassword<span style="color: #000000;">&#40;</span>fe<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">FocusEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; 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><span style="color: #000000; font-weight: bold;">!</span><span style="color: #000000;">&#40;</span>fe.<span style="color: #004993;">relatedObject</span> <span style="color: #0033ff; font-weight: bold;">in</span> <span style="color: #000000;">&#91;</span>passwordInput, passwordConfirmInput<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #009900;">// focus moved away from either input field</span>
    <span style="color: #009900;">// show mismatch alert if texts are not the same</span>
    passwordMismatchAlert.<span style="color: #004993;">visible</span> = passwordInput.<span style="color: #004993;">text</span> <span style="color: #000000; font-weight: bold;">!</span>== passwordConfirmInput.<span style="color: #004993;">text</span>;
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> selectLanguage<span style="color: #000000;">&#40;</span><span style="color: #004993;">language</span><span style="color: #000000; font-weight: bold;">:</span>LanguageRadioButton<span style="color: #000000;">&#41;</span><span style="color: #000000; 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;">switch</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">language</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">case</span> languageDanish<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;texts_da.xml&quot;</span><span style="color: #000000;">&#41;</span>; <span style="color: #0033ff; font-weight: bold;">break</span>;
    <span style="color: #0033ff; font-weight: bold;">case</span> languageSwedish<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;texts_se.xml&quot;</span><span style="color: #000000;">&#41;</span>; <span style="color: #0033ff; font-weight: bold;">break</span>;
    <span style="color: #0033ff; font-weight: bold;">case</span> languageNorwegian<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;texts_no.xml&quot;</span><span style="color: #000000;">&#41;</span>; <span style="color: #0033ff; font-weight: bold;">break</span>;
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> submit<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
  sendForm<span style="color: #000000;">&#40;</span>withParameters<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>One notable example among the above is, that if an event is needed, you can always have it. I only dislike events, when I don't need them but have to accept them anyway. When I actually need it, they do come quite handy - like the <code>FocusEvent.relatedObject</code> used in the above example.<br />
<h3 id="toc-announcement">Announcement</h3>
<p>Actually, I have made the above work! It is a dirty, dirty triple-hack, but it feels quite sweet to use on both ends. I need to clean it up a lot, need to come up with a good name for it and need to benchmark it to see, that it doesn't kill performance (too much).</p>
<p>So please, stay tuned. But do not fear commenting on the above ideas anyway.</p>


<p>Related posts:<ol><li><a href='http://www.barklund.org/blog/2009/11/23/link-sharing-spam-facebook/' rel='bookmark' title='Permanent Link: Link sharing spam on Facebook'>Link sharing spam on Facebook</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.barklund.org/blog/2010/05/07/events-suck-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Vimeo highly vulnerable to CSRF attacks &#8211; now fixed</title>
		<link>http://www.barklund.org/blog/2010/02/12/vimeo-vulnerable-csrf/</link>
		<comments>http://www.barklund.org/blog/2010/02/12/vimeo-vulnerable-csrf/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 00:33:36 +0000</pubDate>
		<dc:creator>Barklund</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Flash Platform]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.barklund.org/blog/?p=683</guid>
		<description><![CDATA[I recently found, that vimeo.com had a cross-domain policy, that allowed anyone to connect, which was an open invitation for CSRF attacks. I alerted them to the issue, and it has now been fixed. As has been said over and over, allow-all cross-domain policy files should never be used on domains, where users log on. [...]


Related posts:<ol><li><a href='http://www.barklund.org/blog/2009/07/15/sys-con-aral-balkan-stupidity-ignorance/' rel='bookmark' title='Permanent Link: Sys-Con once again attacks Aral Balkan with stupidity and ignorance'>Sys-Con once again attacks Aral Balkan with stupidity and ignorance</a></li>
<li><a href='http://www.barklund.org/blog/2009/11/23/link-sharing-spam-facebook/' rel='bookmark' title='Permanent Link: Link sharing spam on Facebook'>Link sharing spam on Facebook</a></li>
<li><a href='http://www.barklund.org/blog/2010/01/10/re-youtube-january-2010-idea/' rel='bookmark' title='Permanent Link: Re-Youtube &#8211; January 2010 Ideas'>Re-Youtube &#8211; January 2010 Ideas</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p> I recently found, that <a href="http://vimeo.com/">vimeo.com</a> had a cross-domain policy, that allowed anyone to connect, which was an open invitation for CSRF attacks. I alerted them to the issue, and it has now been fixed.</p>
<p><span id="more-683"></span></p>
<p>As has been said <a href="http://shiflett.org/blog/2006/sep/the-dangers-of-cross-domain-ajax-with-flash">over</a> and <a href="http://shiflett.org/blog/2009/nov/facebook-myspace-and-crossdomain.xml">over</a>, allow-all cross-domain policy files should never be used on domains, where users log on. This leaves the site open for <a href="http://en.wikipedia.org/wiki/Cross-site_request_forgery">CSRF attacks</a> from flash clients on different domains, that can load pages from the target domain utilizing the user&#8217;s automated log-in and thus the flash load&#8217;s the pages, like the user himself would. This not only allows the flash file to (without the user knowing it) load all his private information from the target site, but potentially also post data to the site, which could include updating the user&#8217;s password, email, profile or in worse circumstances add/remove content or even make purchases, if the target site has any feature like that.
<p>This has been done against large sites like Facebook, MySpace, Adobe and Youtube &#8211; the latter was ironically <a href="http://www.vimeo.com/1762861">documented via a video on Vimeo</a> by Jeremiah Grossman.</p>
<p>In Vimeo&#8217;s case, you can &#8220;only&#8221; upload videos, but an attacker could actually perform any action on the user&#8217;s behalf, that the user himself could &#8211; including changing the user&#8217;s bio, add/remove videos, comment on/like other videos etc. I made a <a href="http://barklund.org/examples/fun_with_vimeo/fun_with_vimeo.html">small, seemingly innocent page</a>, that included a hidden flash element, which first loaded the user&#8217;s info from <a href="http://vimeo.com/settings/personal">vimeo.com/settings/personal</a> and then re-posted this info back to the same page adding an extra line to the bio &#8211; namely &#8220;You have been bwned&#8221;, as it can seen on <a href="http://vimeo.com/barklund">my vimeo profil</a>e.</p>
<p>Someone at vimeo has clearly seen this demo, (<a href="http://vimeo.com/julia">Julia Quinn has indeed</a>) and now <a href="http://vimeo.com/crossdomain.xml">the cross-domain policy only allows *.vimeo.com</a> (the new file is served with a Last-Modified timestamp of <code>Thu, 11 Feb 2010 23:32:05 GMT</code>, so the change is only an hour old). The strange thing is, that if you go back via <a href="http://web.archive.org/">the Wayback Machine from archive.org</a>, you can see, that they had much better security back <a href="http://web.archive.org/web/20070224144110/http://www.vimeo.com/crossdomain.xml">in 2007</a> and <a href="http://web.archive.org/web/20080610033603/http://www.vimeo.com/crossdomain.xml">2008</a> (html render fails, but view source), so I have no idea how such a relaxed policy suddenly appeared on their site. <a href="http://74.125.77.132/search?q=cache:Kssyyl60UAUJ:www.vimeo.com/crossdomain.xml">Google&#8217;s cache still show the allow-all policy</a> as it dates back to January 20th (again, view source to see contents).</p>
<p>I found this while playing around attempting to load videos from Vimeo directly in a custom FLV-player on a different host than vimeo.com and found that this was actually possible, as all videos from their site are hosted from av.vimeo.com and this has an allow-all cross-domain policy. And this makes sense, as this domain is only used for serving videos and nothing else &#8211; no cookies or authentication info shared to this domain.</p>
<p>I haven&#8217;t heard from Vimeo yet &#8211; neither stating that they are looking at the issue nor that it has been fixed. I only post this after now seeing, that it has been fixed.</p>


<p>Related posts:<ol><li><a href='http://www.barklund.org/blog/2009/07/15/sys-con-aral-balkan-stupidity-ignorance/' rel='bookmark' title='Permanent Link: Sys-Con once again attacks Aral Balkan with stupidity and ignorance'>Sys-Con once again attacks Aral Balkan with stupidity and ignorance</a></li>
<li><a href='http://www.barklund.org/blog/2009/11/23/link-sharing-spam-facebook/' rel='bookmark' title='Permanent Link: Link sharing spam on Facebook'>Link sharing spam on Facebook</a></li>
<li><a href='http://www.barklund.org/blog/2010/01/10/re-youtube-january-2010-idea/' rel='bookmark' title='Permanent Link: Re-Youtube &#8211; January 2010 Ideas'>Re-Youtube &#8211; January 2010 Ideas</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.barklund.org/blog/2010/02/12/vimeo-vulnerable-csrf/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Game of Life &#8211; January 2010 Ideas</title>
		<link>http://www.barklund.org/blog/2010/01/21/game-of-life-january-2010-idea/</link>
		<comments>http://www.barklund.org/blog/2010/01/21/game-of-life-january-2010-idea/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 08:00:09 +0000</pubDate>
		<dc:creator>Barklund</dc:creator>
				<category><![CDATA[Flash Platform]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[January 2010 Ideas]]></category>

		<guid isPermaLink="false">http://www.barklund.org/blog/?p=636</guid>
		<description><![CDATA[The twenty-first idea for my 365 social ideas is another gaming idea: create a set of classic flash-based games along the lines of break-out, tetris etc, but integrate a simple storyline with good and bad characters, places and items involved and make these configurable. You could through this create a game of your own life [...]


Related posts:<ol><li><a href='http://www.barklund.org/blog/2010/01/13/game-console-api-social-connectivity-january-2010-idea/' rel='bookmark' title='Permanent Link: Game Console Progress API for Social Connectivity &#8211; January 2010 Ideas'>Game Console Progress API for Social Connectivity &#8211; January 2010 Ideas</a></li>
<li><a href='http://www.barklund.org/blog/2010/01/15/twitter-gaming-mechanic-january-2010-idea/' rel='bookmark' title='Permanent Link: A Twitter Gaming Mechanic &#8211; January 2010 Ideas'>A Twitter Gaming Mechanic &#8211; January 2010 Ideas</a></li>
<li><a href='http://www.barklund.org/blog/2010/01/25/facebook-notes-images-competition-january-2010-idea/' rel='bookmark' title='Permanent Link: Facebook Notes and Images for Competition Results &#8211; January 2010 Ideas'>Facebook Notes and Images for Competition Results &#8211; January 2010 Ideas</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>The twenty-first idea for my <a href="/blog/365ideas/" title="365 Social Ideas from Barklund.org">365 social ideas</a> is another gaming idea: create a set of classic flash-based games along the lines of break-out, tetris etc, but integrate a simple storyline with good and bad characters, places and items involved and make these configurable. You could through this create a game of your own life by inserting persons from your surroundings, places where you meet, stuff that you work with etc. and you could send this game to your friends and family and they could then play out the big game of your life.</p>
<p><span id="more-636"></span></p>
<p>This is still fairly simple, but then imagine automatic integration with social networks, so you simply connect via Facebook, Twitter or any other interesting friendship services and you can pick between your friends, recent updates etc. and it would automatically try to create this game.</p>
<p>Or what about having it automatically parse articles etc. for creating games about anything. Say this blogpost &#8211; it would automatically recognize names of persons, places and interactable items and then generate the game. It could be used for all sorts of fun things and the great thing would be, that anything could happen. You could re-enact Obama&#8217;s presidential campaign victory, the Algerian War or Romeo and Juliet &#8211; simply by using the right characters, places and items combined with the right storyline.</p>
<h4 id="toc-why">Why?</h4>
<p>Because it is fun. And putting news and other items in a new perspective adds to the fun of information sharing. Plus, having fun with your friends and family the same way would be an added benefit.</p>
<h4 id="toc-whats-next">What&#8217;s next?</h4>
<p>Do with this idea whatever you like &#8211; expand, implement, trash or forget. Just remember, that if you use it in anyway make sure to attribute me according to the Creative Commons Attribution 3.0 License, that all these <a href="/blog/365ideas" title="365 Social Ideas from Barklund.org">365 Social Ideas</a> are published under.</p>


<p>Related posts:<ol><li><a href='http://www.barklund.org/blog/2010/01/13/game-console-api-social-connectivity-january-2010-idea/' rel='bookmark' title='Permanent Link: Game Console Progress API for Social Connectivity &#8211; January 2010 Ideas'>Game Console Progress API for Social Connectivity &#8211; January 2010 Ideas</a></li>
<li><a href='http://www.barklund.org/blog/2010/01/15/twitter-gaming-mechanic-january-2010-idea/' rel='bookmark' title='Permanent Link: A Twitter Gaming Mechanic &#8211; January 2010 Ideas'>A Twitter Gaming Mechanic &#8211; January 2010 Ideas</a></li>
<li><a href='http://www.barklund.org/blog/2010/01/25/facebook-notes-images-competition-january-2010-idea/' rel='bookmark' title='Permanent Link: Facebook Notes and Images for Competition Results &#8211; January 2010 Ideas'>Facebook Notes and Images for Competition Results &#8211; January 2010 Ideas</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.barklund.org/blog/2010/01/21/game-of-life-january-2010-idea/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Advanced E4X &#8211; Assignment to XMLLists</title>
		<link>http://www.barklund.org/blog/2009/11/04/advanced-e4x-assignment-xmllists/</link>
		<comments>http://www.barklund.org/blog/2009/11/04/advanced-e4x-assignment-xmllists/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 10:22:47 +0000</pubDate>
		<dc:creator>Barklund</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[E4X]]></category>

		<guid isPermaLink="false">http://www.barklund.org/blog/?p=422</guid>
		<description><![CDATA[Setup Direct children Descendants Conclusion I was playing around with E4X last night working on an upcoming blog post about the capabilities of E4X. While playing, I was thoroughly reading the ECMA-357 standard, and found that there are some special rules about assignment and compound assignment, that produce truely unexpected results. I will try to [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<div class="toc">
<ol>
<li><a href="http://www.barklund.org/blog/2009/11/04/advanced-e4x-assignment-xmllists/#toc-setup">Setup</a></li>
<li><a href="http://www.barklund.org/blog/2009/11/04/advanced-e4x-assignment-xmllists/#toc-direct-children">Direct children</a></li>
<li><a href="http://www.barklund.org/blog/2009/11/04/advanced-e4x-assignment-xmllists/#toc-descendants">Descendants</a></li>
<li><a href="http://www.barklund.org/blog/2009/11/04/advanced-e4x-assignment-xmllists/#toc-conclusion">Conclusion</a></li>
</ol>
</div>
<p>I was playing around with E4X last night working on an upcoming blog post about the capabilities of E4X. While playing, I was thoroughly reading the ECMA-357 standard, and found that there are some special rules about assignment and compound assignment, that produce truely unexpected results.</p>
<p>I will try to summarize common pitfalls and provide valid work-arounds.</p>
<p><span id="more-422"></span></p>
<h3 id="toc-setup">Setup</h3>
<p>This post will for most examples work on the following document:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">XML</span> = <span style="color: #000000; font-weight: bold;">&lt;</span>employees<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>person<span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>name<span style="color: #000000; font-weight: bold;">&gt;</span>John<span style="color: #000000; font-weight: bold;">&lt;/</span>name<span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>age<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">35</span><span style="color: #000000; font-weight: bold;">&lt;/</span>age<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;/</span>person<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>person<span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>name<span style="color: #000000; font-weight: bold;">&gt;</span>Joe<span style="color: #000000; font-weight: bold;">&lt;/</span>name<span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>age<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">25</span><span style="color: #000000; font-weight: bold;">&lt;/</span>age<span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>hobby<span style="color: #000000; font-weight: bold;">&gt;</span>Swimming<span style="color: #000000; font-weight: bold;">&lt;/</span>hobby<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;/</span>person<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>employees<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>Sometimes other documents will be used explicitly.</p>
<h3 id="toc-direct-children">Direct children</h3>
<p>How would you go about changing the hobby of Joe to running? Well, we could traverse all the way to the node:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">e.person<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span>.hobby = <span style="color: #990000;">&quot;Running&quot;</span>;</pre></div></div>

<p>This of course works as expected. Actually, we ought to be able to skip the index [1], as only the second person has a hobby and thus only this node ought to be the target for the update:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">e.person.hobby = <span style="color: #990000;">&quot;Running&quot;</span>;</pre></div></div>

<p>But no, this throws a runtime-error:</p>
<blockquote><p>TypeError: Error #1089: Assignment to lists with more than one item is not supported.</p></blockquote>
<p>But it is not a list with more than one item, is it?</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>e.person.hobby.<span style="color: #004993;">length</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// traces 1</span></pre></div></div>

<p>The issue here (I expect, I had a hard time figuring out what the spec actually said about it) is, that the second-to-last list in the assignment target has more than one item:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>e.person.<span style="color: #004993;">length</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// traces 2</span></pre></div></div>

<p>This can be tested by introducing some extra level of nodes and try to update one of these:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> more_nodes<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">XML</span> = <span style="color: #000000; font-weight: bold;">&lt;</span>employees<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>person<span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>name<span style="color: #000000; font-weight: bold;">&gt;</span>John<span style="color: #000000; font-weight: bold;">&lt;/</span>name<span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>age<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">35</span><span style="color: #000000; font-weight: bold;">&lt;/</span>age<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;/</span>person<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>person<span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>name<span style="color: #000000; font-weight: bold;">&gt;</span>Joe<span style="color: #000000; font-weight: bold;">&lt;/</span>name<span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>age<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">25</span><span style="color: #000000; font-weight: bold;">&lt;/</span>age<span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>hobby<span style="color: #000000; font-weight: bold;">&gt;</span>
			<span style="color: #000000; font-weight: bold;">&lt;</span>primary<span style="color: #000000; font-weight: bold;">&gt;</span>Swimming<span style="color: #000000; font-weight: bold;">&lt;/</span>primary<span style="color: #000000; font-weight: bold;">&gt;</span>
			<span style="color: #000000; font-weight: bold;">&lt;</span>secondary<span style="color: #000000; font-weight: bold;">&gt;</span>Sewing<span style="color: #000000; font-weight: bold;">&lt;/</span>secondary<span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;/</span>hobby<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;/</span>person<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>employees<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>more_nodes.person.<span style="color: #004993;">length</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// traces 2</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>more_nodes.person.hobby.<span style="color: #004993;">length</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// traces 1</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>more_nodes.person.hobby.primary.<span style="color: #004993;">length</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// traces 1</span>
more_nodes.person.hobby.primary = <span style="color: #990000;">&quot;Running&quot;</span>; <span style="color: #009900;">// no error, updated as expected</span></pre></div></div>

<p>Voila, it works. What this means is, that the error is not related to the actual XMLList, that you are assigning to &#8211; but to the XMLList, that is the parent of this in the statement. We could actually have reached the desired result by adding an extra level to reach the text node inside the (single) hobby node:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">e.person.hobby.<span style="color: #000000; font-weight: bold;">*</span> = <span style="color: #990000;">&quot;Running&quot;</span>; <span style="color: #009900;">// no error, updated as expected</span></pre></div></div>

<p>In this case again, the second-to-last XMLList (the target object for the assignment) has a length of 1, and the update can be accomplished.</p>
<h3 id="toc-descendants">Descendants</h3>
<p>But if we really just wanted to update the single hobby, that we know only one of the employees have, then we would normally try:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">e..hobby = <span style="color: #990000;">&quot;Running&quot;</span>;</pre></div></div>

<p>Now things start to get really interesting. Because, what happened? No error was thrown, but the document after this update looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;</span>employees<span style="color: #000000; font-weight: bold;">&gt;</span>
  <span style="color: #000000; font-weight: bold;">&lt;</span>person<span style="color: #000000; font-weight: bold;">&gt;</span>
    <span style="color: #000000; font-weight: bold;">&lt;</span>name<span style="color: #000000; font-weight: bold;">&gt;</span>John<span style="color: #000000; font-weight: bold;">&lt;/</span>name<span style="color: #000000; font-weight: bold;">&gt;</span>
    <span style="color: #000000; font-weight: bold;">&lt;</span>age<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">35</span><span style="color: #000000; font-weight: bold;">&lt;/</span>age<span style="color: #000000; font-weight: bold;">&gt;</span>
  <span style="color: #000000; font-weight: bold;">&lt;/</span>person<span style="color: #000000; font-weight: bold;">&gt;</span>
  <span style="color: #000000; font-weight: bold;">&lt;</span>person<span style="color: #000000; font-weight: bold;">&gt;</span>
    <span style="color: #000000; font-weight: bold;">&lt;</span>name<span style="color: #000000; font-weight: bold;">&gt;</span>Joe<span style="color: #000000; font-weight: bold;">&lt;/</span>name<span style="color: #000000; font-weight: bold;">&gt;</span>
    <span style="color: #000000; font-weight: bold;">&lt;</span>age<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">25</span><span style="color: #000000; font-weight: bold;">&lt;/</span>age<span style="color: #000000; font-weight: bold;">&gt;</span>
    <span style="color: #000000; font-weight: bold;">&lt;</span>hobby<span style="color: #000000; font-weight: bold;">&gt;</span>Swimming<span style="color: #000000; font-weight: bold;">&lt;/</span>hobby<span style="color: #000000; font-weight: bold;">&gt;</span>
  <span style="color: #000000; font-weight: bold;">&lt;/</span>person<span style="color: #000000; font-weight: bold;">&gt;</span>
  <span style="color: #000000; font-weight: bold;">&lt;</span>hobby<span style="color: #000000; font-weight: bold;">&gt;</span>Running<span style="color: #000000; font-weight: bold;">&lt;/</span>hobby<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>employees<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>That is, the existing hobby was unchanged, but a new hobby node has been appended to the end of the outermost node? The statement works the same, as if I had just written:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">e.hobby = <span style="color: #990000;">&quot;Running&quot;</span>;</pre></div></div>

<p>Which would do exactly that &#8211; create and append a new hobby node to the outermost node and set its text value to &#8220;Running&#8221;. But the two lists aren&#8217;t identical in the original document:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>e..hobby.<span style="color: #004993;">length</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// traces 1</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>e.hobby.<span style="color: #004993;">length</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// traces 0</span></pre></div></div>

<p>But again, assignment to xml (and xmllists) does not really have to do with the last part of the assignment target but the penultimate. And again, adding an extra level to reach the text node(s) works:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">e..hobby.<span style="color: #000000; font-weight: bold;">*</span> = <span style="color: #990000;">&quot;Running&quot;</span>; <span style="color: #009900;">// no error, and this time updated as expected</span></pre></div></div>

<p>Why the previous statement seemed to ignore the descendant-part of the statement, I&#8217;m not really sure. Could be a bug, could be a loop-hole, but it definitely does not make sense.</p>
<p>There are many other ways to reach the same list of the single hobby node when simply consuming, but they cannot all be used in the same way when updating:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">e..<span style="color: #000000; font-weight: bold;">*</span>.hobby = <span style="color: #990000;">&quot;Running&quot;</span>; <span style="color: #009900;">// throws the same Error #1089 about more-than-one element lists</span>
e..<span style="color: #000000; font-weight: bold;">*</span>.hobby.<span style="color: #000000; font-weight: bold;">*</span> = <span style="color: #990000;">&quot;Running&quot;</span>; <span style="color: #009900;">// and it works again</span>
&nbsp;
e.<span style="color: #004993;">descendants</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.hobby = <span style="color: #990000;">&quot;Running&quot;</span>; <span style="color: #009900;">// throws the same Error #1089 about more-than-one element lists</span>
e.<span style="color: #004993;">descendants</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.hobby.<span style="color: #000000; font-weight: bold;">*</span> = <span style="color: #990000;">&quot;Running&quot;</span>; <span style="color: #009900;">// and it works again</span>
&nbsp;
e.<span style="color: #004993;">descendants</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">'hobby'</span><span style="color: #000000;">&#41;</span> = <span style="color: #990000;">&quot;Running&quot;</span>; <span style="color: #009900;">// compile-time error</span>
<span style="color: #009900;">// the parser simply does not allow assigning to a function invocation</span>
e.<span style="color: #004993;">descendants</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">'hobby'</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000; font-weight: bold;">*</span> = <span style="color: #990000;">&quot;Running&quot;</span>; <span style="color: #009900;">// and it works again</span>
&nbsp;
e..<span style="color: #000000; font-weight: bold;">*</span>.<span style="color: #000000;">&#40;</span><span style="color: #004993;">localName</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>==<span style="color: #990000;">'hobby'</span><span style="color: #000000;">&#41;</span> = <span style="color: #990000;">&quot;Running&quot;</span>; <span style="color: #009900;">// compile-time error</span>
<span style="color: #009900;">// the parser simply does not allow assigning to (what looks like) a function invocation</span>
e..<span style="color: #000000; font-weight: bold;">*</span>.<span style="color: #000000;">&#40;</span><span style="color: #004993;">localName</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>==<span style="color: #990000;">'hobby'</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000; font-weight: bold;">*</span> = <span style="color: #990000;">&quot;Running&quot;</span>; <span style="color: #009900;">// and it works again</span></pre></div></div>

<h3 id="toc-conclusion">Conclusion</h3>
<p>Be aware that assignments to XMLLists does not care about the last list &#8211; it is the second-to-last list, that must contain only one value. Internally, a statement like:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">expression.property = <span style="color: #004993;">value</span>;</pre></div></div>

<p>Is not a new thing at all, but it is handled in a new, special way, when <code>expression</code> has a value of either XML or XMLList. Thus, if you either get compile-time errors, runtime-errors or nodes appended in completely wrong places, just add extra level of element traversal with the wildcard-identifier <code>.*</code> to reach the text node of the single node you want to update.</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.barklund.org/blog/2009/11/04/advanced-e4x-assignment-xmllists/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Weird bitmap fill crash error in Flash CS4.</title>
		<link>http://www.barklund.org/blog/2009/10/21/bitmap-fill-crash-flash-cs4/</link>
		<comments>http://www.barklund.org/blog/2009/10/21/bitmap-fill-crash-flash-cs4/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 11:57:16 +0000</pubDate>
		<dc:creator>Barklund</dc:creator>
				<category><![CDATA[Flash Platform]]></category>

		<guid isPermaLink="false">http://www.barklund.org/blog/?p=414</guid>
		<description><![CDATA[As part of a larger project, I noticed an annoying thing, that kept consequently crashing Flash CS4 (on a Mac OS X Intel 10.6.1): Whenever I tried to copy or cut this one symbol from the stage (to place it in another layer), Flash crashed completely. There were many conditions, that could have been the [...]


Related posts:<ol><li><a href='http://www.barklund.org/blog/2009/07/06/flash-development-scripted-layout/' rel='bookmark' title='Permanent Link: Flash development and the practice of Scripted Layout'>Flash development and the practice of Scripted Layout</a></li>
<li><a href='http://www.barklund.org/blog/2009/06/08/using-addthis-with-flash/' rel='bookmark' title='Permanent Link: Using AddThis with Flash'>Using AddThis with Flash</a></li>
<li><a href='http://www.barklund.org/blog/2009/07/01/minor-change-in-handling-nan-positions-in-flash-player-10-0-22/' rel='bookmark' title='Permanent Link: Minor change in handling NaN positions in Flash Player 10,0,22'>Minor change in handling NaN positions in Flash Player 10,0,22</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>As part of a larger project, I noticed an annoying thing, that kept consequently crashing Flash CS4 (on a Mac OS X Intel 10.6.1): Whenever I tried to copy or cut this one symbol from the stage (to place it in another layer), Flash crashed completely.</p>
<p>There were many conditions, that could have been the cause of this, but I managed to boil it down to something reportable.</p>
<p><span id="more-414"></span></p>
<p>Complete the following simple 9 steps (the fifth one is the strangest IMHO):</p>
<ol>
<li>Open Flash CS4.</li>
<li>Create new AS3 FLA document.</li>
<li>Import an image to stage (Cmd+R).</li>
<li>Break the image (Cmd+B) creating a shape with the bitmap as fill &#8220;color&#8221;.</li>
<li>Remove a slice from the top of the image by selecting a part of the shape and deleting it. By slice I mean a rectangle from the top in the full width of the shape reducing the overall height of the shape.</li>
<li>Convert the shape to a symbol.</li>
<li>Rotate the symbol 90 degrees via the transform panel.</li>
<li>Cut or copy the symbol.</li>
<li>Watch Flash CS4 crash and burn.</li>
</ol>
<p>The strangest parts are, that I had to remove a slice in the full width of the image to make this crash. If I didn&#8217;t remove anything or just removed a rectangle from the corner of from the middle, it did not work (or actually, it did work &#8211; but it did not crash), it had to be a slice in the entire width of the shape.</p>
<p>Furthermore, the rotation had to be exactly 90 degrees. Not -90, 180, 89 or anything else, but 90 degrees.</p>
<p>The shape had to be converted to a symbol &#8211; and inside the symbol the shape had to be at 0 degrees rotation. If the symbol was at 50 and the shape inside at 40, it would seem the same, but the crash did not happen.</p>
<p>I did not try all different permutations, so if you find, that this can happen under even simpler circumstances, similar circumstances or maybe not all on other operating systems, please share in the comments below. I have found this to cause the crash on both my own Mac OS X Intel 10.6.1 and a coworker&#8217;s Mac OS X Intel 10.5.</p>
<p>I have reported this to Adobe as well, but it seems that the Flash CS4 bug database is not public &#8211; only the Flash Player bug database.</p>


<p>Related posts:<ol><li><a href='http://www.barklund.org/blog/2009/07/06/flash-development-scripted-layout/' rel='bookmark' title='Permanent Link: Flash development and the practice of Scripted Layout'>Flash development and the practice of Scripted Layout</a></li>
<li><a href='http://www.barklund.org/blog/2009/06/08/using-addthis-with-flash/' rel='bookmark' title='Permanent Link: Using AddThis with Flash'>Using AddThis with Flash</a></li>
<li><a href='http://www.barklund.org/blog/2009/07/01/minor-change-in-handling-nan-positions-in-flash-player-10-0-22/' rel='bookmark' title='Permanent Link: Minor change in handling NaN positions in Flash Player 10,0,22'>Minor change in handling NaN positions in Flash Player 10,0,22</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.barklund.org/blog/2009/10/21/bitmap-fill-crash-flash-cs4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MXHR4AS3 Released</title>
		<link>http://www.barklund.org/blog/2009/10/09/mxhr4as3-released/</link>
		<comments>http://www.barklund.org/blog/2009/10/09/mxhr4as3-released/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 09:19:42 +0000</pubDate>
		<dc:creator>Barklund</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[MXHR4AS3]]></category>

		<guid isPermaLink="false">http://www.barklund.org/blog/?p=376</guid>
		<description><![CDATA[I finally got the time to clean up the code for MXHR4AS3 &#8211; an implementation of the Digg-introduced concept of requesting several files from the server in one request and returning it as a multipart/mixed http response to reduce overhead. The original was implemented in JS, and I have further re-implemented it in AS3. As [...]


Related posts:<ol><li><a href='http://www.barklund.org/blog/2009/09/04/mxhr4as3-multipart-mixed-file-download-flash/' rel='bookmark' title='Permanent Link: Announcing MXHR4AS3: Multipart/mixed-file download by Flash clients'>Announcing MXHR4AS3: Multipart/mixed-file download by Flash clients</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I finally got the time to clean up the code for <a href="http://www.barklund.org/blog/2009/09/04/mxhr4as3-multipart-mixed-file-download-flash/" title="Announcing MXHR4AS3: Multipart/mixed-file download by Flash clients from Barklund.org">MXHR4AS3</a> &#8211; an implementation of the <a href="http://blog.digg.com/?p=621" title="DUI.Stream and MXHR from the official Digg blog">Digg-introduced concept</a> of requesting several files from the server in one request and returning it as a multipart/mixed http response to reduce overhead. The original was implemented in JS, and I have further re-implemented it in AS3.</p>
<p>As promised, the code <a href="http://bitbucket.org/barklund/mxhr4as3/">has been uploaded</a> to <a href="http://bitbucket.org/" title="Bitbucket home">Bitbucket</a>. Please enjoy and by all means request access if necessary. Please refer to the <a href="http://barklund.org/blog/projects/mxhr4as3">new project page here</a> for details.</p>


<p>Related posts:<ol><li><a href='http://www.barklund.org/blog/2009/09/04/mxhr4as3-multipart-mixed-file-download-flash/' rel='bookmark' title='Permanent Link: Announcing MXHR4AS3: Multipart/mixed-file download by Flash clients'>Announcing MXHR4AS3: Multipart/mixed-file download by Flash clients</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.barklund.org/blog/2009/10/09/mxhr4as3-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Announcing MXHR4AS3: Multipart/mixed-file download by Flash clients</title>
		<link>http://www.barklund.org/blog/2009/09/04/mxhr4as3-multipart-mixed-file-download-flash/</link>
		<comments>http://www.barklund.org/blog/2009/09/04/mxhr4as3-multipart-mixed-file-download-flash/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 11:32:38 +0000</pubDate>
		<dc:creator>Barklund</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Trends]]></category>

		<guid isPermaLink="false">http://www.barklund.org/blog/?p=336</guid>
		<description><![CDATA[After having read about and experimented with Digg&#8217;s MXHR concept and DUI.Stream, I have now implemented the very same thing for ActionScript 3. In my tests it really shows a performance-boost over conventional queued download. Introduction Results Source Introduction I have implemented the MXHR client to be able to use multiple concurrent http-streams to load [...]


Related posts:<ol><li><a href='http://www.barklund.org/blog/2009/10/09/mxhr4as3-released/' rel='bookmark' title='Permanent Link: MXHR4AS3 Released'>MXHR4AS3 Released</a></li>
<li><a href='http://www.barklund.org/blog/2009/07/06/flash-development-scripted-layout/' rel='bookmark' title='Permanent Link: Flash development and the practice of Scripted Layout'>Flash development and the practice of Scripted Layout</a></li>
<li><a href='http://www.barklund.org/blog/2009/06/08/using-addthis-with-flash/' rel='bookmark' title='Permanent Link: Using AddThis with Flash'>Using AddThis with Flash</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>After having read about and experimented with <a href="http://blog.digg.com/?p=621" title="DUI.Stream and MXHR from the Digg Blog">Digg&#8217;s MXHR concept</a> and <a href="http://github.com/digg/stream" title="DUI.Stream repository on Github">DUI.Stream</a>, I have now implemented the very same thing for ActionScript 3. In my tests it really shows a performance-boost over conventional queued download.</p>
<div class="toc">
<ol>
<li><a href="http://www.barklund.org/blog/2009/09/04/mxhr4as3-multipart-mixed-file-download-flash/#toc-introduction">Introduction</a></li>
<li><a href="http://www.barklund.org/blog/2009/09/04/mxhr4as3-multipart-mixed-file-download-flash/#toc-results">Results</a></li>
<li><a href="http://www.barklund.org/blog/2009/09/04/mxhr4as3-multipart-mixed-file-download-flash/#toc-source">Source</a></li>
</ol>
</div>
<p><span id="more-336"></span></p>
<h3 id="toc-introduction">Introduction</h3>
<p>I have implemented the MXHR client to be able to use multiple concurrent http-streams to load the files even faster. This is done in order to make sure that the MXHR client can have the same advantage as conventional downloading, where concurrent streams perform better than simple queued streams.</p>
<p>The MXHR client is implemented pretty straight-forward in AS3 with 3 simple classes &ndash; <code>MXHR</code>, <code>MXHRFile</code> and <code>MXHREvent</code>. The serverside implementation, that I choose, was in PHP, and since the folks at Digg did not provide one such sample implementation, I did my own. It is done in PHP 5 through a single class <code>MXHR</code> taking file names and building a aggregated response (in conformance with specifications of course) &#8211; and it supports caching.</p>
<h3 id="toc-results">Results</h3>
<p>Some example download times by my tests:</p>
<table border="1">
<caption><em>Download times for different clients</em></caption>
<col style="width:100px" />
<col style="width:100px" />
<col style="width:150px" />
<col style="width:150px" />
<thead>
<tr>
<th>Method</th>
<th>Streams</th>
<th>Uncached load time</th>
<th>Cached load time</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2">Conventional</td>
<td>1</td>
<td>37094 ms</td>
<td>15854 ms</td>
</tr>
<tr>
<td>8</td>
<td>5319 ms</td>
<td>3126 ms</td>
</tr>
<tr>
<td rowspan="2">MXHR4AS3</td>
<td>1</td>
<td>4386 ms</td>
<td>1473 ms</td>
</tr>
<tr>
<td>8</td>
<td>3695 ms</td>
<td>1421 ms</td>
</tr>
</tbody>
</table>
<p>Try it out for yourself here:</p>
<ul>
<li><a href="/examples/mxhr4as3/conventional_single.swf" title="Link to conventional single-threaded download">Conventional single-threaded download</a></li>
<li><a href="/examples/mxhr4as3/conventional_concurrent.swf" title="Link to conventional multi-threaded download">Conventional multi-threaded download</a></li>
<li><a href="/examples/mxhr4as3/demo_single.swf" title="Link to MXHR-based single-threaded download">MXHR-based single-threaded download</a></li>
<li><a href="/examples/mxhr4as3/demo_concurrent.swf" title="Link to MXHR-based multi-threaded download">MXHR-based multi-threaded download</a></li>
</ul>
<p>As you can see, when the files are cached there is almost no difference between MXHR-based single- or multi-threaded download. And both are significantly faster (both cached and uncached) compared to either type of conventional download.</p>
<h3 id="toc-source">Source</h3>
<p>I will need to do a little bit of further testing and clean-up before I put the full source-code up for download, but when I do, it will be on <s><a href="http://code.google.com" title="Google Code">Google Code</a></s> <a href="http://bitbucket.org" title="Home of Bitbucket.org">Bitbucket</a> under the <a href="/blog/site-license" title="Site License for barklund.org content">site license</a>.</p>


<p>Related posts:<ol><li><a href='http://www.barklund.org/blog/2009/10/09/mxhr4as3-released/' rel='bookmark' title='Permanent Link: MXHR4AS3 Released'>MXHR4AS3 Released</a></li>
<li><a href='http://www.barklund.org/blog/2009/07/06/flash-development-scripted-layout/' rel='bookmark' title='Permanent Link: Flash development and the practice of Scripted Layout'>Flash development and the practice of Scripted Layout</a></li>
<li><a href='http://www.barklund.org/blog/2009/06/08/using-addthis-with-flash/' rel='bookmark' title='Permanent Link: Using AddThis with Flash'>Using AddThis with Flash</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.barklund.org/blog/2009/09/04/mxhr4as3-multipart-mixed-file-download-flash/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Web Sockets in HTML 5 might solve the http pull problem once and for all</title>
		<link>http://www.barklund.org/blog/2009/08/20/web-sockets-html-5-solve-http-pull/</link>
		<comments>http://www.barklund.org/blog/2009/08/20/web-sockets-html-5-solve-http-pull/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 10:28:22 +0000</pubDate>
		<dc:creator>Barklund</dc:creator>
				<category><![CDATA[Flash Platform]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[Trends]]></category>

		<guid isPermaLink="false">http://www.barklund.org/blog/?p=283</guid>
		<description><![CDATA[The truth be told, us ActionScript programmers have always had it easy when it came to creating real-time, multi-user applications. We might not have had much processing power back then, but as early as Flash 5 introduced back in 2000, we got the XMLSocket object, which enabled a whole series of multi-user-applications like isometric chat [...]


Related posts:<ol><li><a href='http://www.barklund.org/blog/2009/08/28/html-5-datasets/' rel='bookmark' title='Permanent Link: Datasets in HTML 5 and what they&#8217;re good for'>Datasets in HTML 5 and what they&#8217;re good for</a></li>
<li><a href='http://www.barklund.org/blog/2009/07/06/flash-development-scripted-layout/' rel='bookmark' title='Permanent Link: Flash development and the practice of Scripted Layout'>Flash development and the practice of Scripted Layout</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>The truth be told, us ActionScript programmers have always had it easy when it came to creating real-time, multi-user applications. We might not have had much processing power back then, but as early as Flash 5 introduced back in 2000, we got the <a href="http://livedocs.adobe.com/flash/9.0/main/00002367.html" title="XMLSocket API reference in Adobe LiveDocs">XMLSocket</a> object, which enabled a whole series of multi-user-applications like isometric chat worlds etc. This leaves us JavaScript programmers a bit stranded. We do have Comet and similar technologies, but true persistent connections, we have never had &#8211; unless we used a Flash object in the document somewhere, but who wants to use Flash anyway?</p>
<p>But with the dawn of <a href="http://en.wikipedia.org/wiki/HTML_5" title="HTML 5 on Wikipedia">HTML 5</a>, this worry is irrelevant, because with HTML 5 and the greatly improved JavaScript API, we also get <a href="http://dev.w3.org/html5/websockets/" title="Web Sockets API from w3.org">a brand new Web Sockets API</a>. This will have the same basic low-level access to bi-directional communication as ActionScript got with the XMLSocket API &#8211; it wasn&#8217;t XML only, it was just the (widely used) default transport method, but it could easily be circumvented.</p>
<p>Quite stunning though, how such a simple mechanism arrives in JavaScript 10 years later than it did in ActionScript!</p>
<p><span id="more-283"></span></p>
<p>When this becomes standard in new browsers across vendors, we will see it implemented in so many popular applications, that currently use all sorts of tricks to achieve the same results &#8211; like <a href="http://www.facebook.com">Facebook</a>, who uses Comet to &#8220;push&#8221; JavaScript notifications. With this API, doing stuff like that becomes much easier and much cleaner. Or <a href="http://docs.google.com">Google Docs</a>, who use Comet as well as HTTP pulling. Or NFL live match view, who use a Flash object in the document to receive events about the match being watched.</p>
<p>And this of course also increase the opportunity for creating new multi-user applications &#8211; and games &#8211; in HTML and JavaScript. And given the extra computational strengths, that most JavaScript engines are being equipped with currently (Chrome started the race and IE8 perform surprisingly well), and given some of the other fun things in HTML 5 like canvas, things will really start to get interesting.</p>
<p>Go HTML 5 &#8211; get yourself final as soon as possible! Give us JavaScript programmers the same tools that we ActionScript programmers have had for a decade.</p>


<p>Related posts:<ol><li><a href='http://www.barklund.org/blog/2009/08/28/html-5-datasets/' rel='bookmark' title='Permanent Link: Datasets in HTML 5 and what they&#8217;re good for'>Datasets in HTML 5 and what they&#8217;re good for</a></li>
<li><a href='http://www.barklund.org/blog/2009/07/06/flash-development-scripted-layout/' rel='bookmark' title='Permanent Link: Flash development and the practice of Scripted Layout'>Flash development and the practice of Scripted Layout</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.barklund.org/blog/2009/08/20/web-sockets-html-5-solve-http-pull/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Top 6 AS3 features you miss when switching back to AS2</title>
		<link>http://www.barklund.org/blog/2009/07/19/top-6-as3-features-you-miss-when-switching-back-to-as2/</link>
		<comments>http://www.barklund.org/blog/2009/07/19/top-6-as3-features-you-miss-when-switching-back-to-as2/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 21:40:58 +0000</pubDate>
		<dc:creator>Barklund</dc:creator>
				<category><![CDATA[AS2]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Lists]]></category>

		<guid isPermaLink="false">http://www.barklund.org/blog/?p=234</guid>
		<description><![CDATA[I have been doing ActionScript 3 projects for quite a while, but every now and then I (as well as many others in the trade) have to switch back to AS2 or even AS1 &#8211; the line between them is quite blurry really in retrospective. When doing AS3 projects, there are many features that really [...]


Related posts:<ol><li><a href='http://www.barklund.org/blog/2009/07/01/minor-change-in-handling-nan-positions-in-flash-player-10-0-22/' rel='bookmark' title='Permanent Link: Minor change in handling NaN positions in Flash Player 10,0,22'>Minor change in handling NaN positions in Flash Player 10,0,22</a></li>
<li><a href='http://www.barklund.org/blog/2009/11/04/advanced-e4x-assignment-xmllists/' rel='bookmark' title='Permanent Link: Advanced E4X &#8211; Assignment to XMLLists'>Advanced E4X &#8211; Assignment to XMLLists</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I have been doing ActionScript 3 projects for quite a while, but every now and then I (as well as many others in the trade) have to switch back to AS2 or even AS1 &#8211; the line between them is quite blurry really in retrospective. When doing AS3 projects, there are many features that really come in handy, but it is only when you don&#8217;t have them available, that you really find out which are the true improvements, that you cannot live without, and which are just nice little tweaks, that make your everyday scripting easier.
<p>The latter category includes e.g. <a href="http://www.barklund.org/blog/2009/05/21/for-each-in-loops-in-actionscript-3/" title="For-each-in loops in ActionScript 3 from barklund.org">the for-each-in construct</a>, <a href="http://livedocs.adobe.com/flash/9.0/main/00000047.html" title="Data type descriptions from Adobe LiveDocs">different number types</a>, <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/package.html#describeType%28%29" title="describeType() in the flash.utils package description from Adobe LiveDocs">class introspection</a> or <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/package.html#getDefinitionByName%28%29" title="getDefinitionByName() in the flash.utils package description from Adobe LiveDocs">built-in class look-up by string</a>, but these are my top 6 AS3 features, that I find myself constantly missing when fixing or improving scripts in older versions of ActionScript:</p>
<p><span id="more-234"></span></p>
<h3 id="toc-number-6-default-values-for-parameters">Number 6: Default values for parameters</h3>
<blockquote><p>if (!scale) scale = 1;</p></blockquote>
<p>It is very simple, it doesn&#8217;t really look nice (at least the first couple of times you read/write it), but it gets the job done and it is consistent with how other languages does it. If it is the best possible choice for implementation, I cannot really say, but I wouldn&#8217;t be without it now that I have it &#8211; though I can easily think of improvements.</p>
<p>Okay, you are going to ask anyway, so here it is: It can be greatly improved by adding the ability to add parameters by name like in Python &#8211; e.g.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">ftp.<span style="color: #0066CC;">connect</span><span style="color: #66cc66;">&#40;</span>host=<span style="color: #ff0000;">&quot;www.server.com&quot;</span>,username=<span style="color: #ff0000;">&quot;administrator&quot;</span>,<span style="color: #0066CC;">password</span>=password_input.<span style="color: #0066CC;">text</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>It looks a bit strange but it is a great improvement &#8211; just compare it to how you need to specify the third (useCapture) and fourth (priority) arguments to addEventListener whenever you need to specify, that you want it to use weak references (the fifth argument set to true) &#8211; it does not look that good and could be a lot easier to use with named arguments.</p>
<h3 id="toc-number-5-e4x">Number 5: E4X</h3>
<blockquote><p>firstChild.firstChild.childNodes[i].lastChild.firstChild.attributes.id</p></blockquote>
<p>XML-based configuration files have been around for ages. I have done banners back in Flash 5, that used external configuration files for texts, layout, flow, paths, connection properties or something similiar. Of course, back then you always loaded the ignoreWhite script (wasn&#8217;t it XMLNitro.as from Branden Hall?), but you still had to either create your own serialization schemes, load someone else&#8217;s or go through the staggering pain of navigating through the XML-node tree through simple node references without knowing their names in advance.</p>
<p>With E4X we have been equipped with XPath-like traversal schemes, that still allow for basic node traversal, but makes it infinitely much easier to reach that specific node, that you need and know the name (and maybe some of the path) of.</p>
<h3 id="toc-number-4-instantiate-movieclips-even-across-swfs">Number 4: Instantiate movieclips &#8211; even across SWF&#8217;s</h3>
<blockquote><p>No more duplicateMovieClip madness</p></blockquote>
<p>I did a large isometric chat world in the good old Flash 5 days (and it only just recently got improved &#8211; which meant doubling the version number from Flash 5 to Flash 10 &#8211; now that is rare) and split code out in several FLA-files compiled to several SWF-files. But as everything needed to be possible to lay in-between each other all graphics needed to be in the same SWF-file. Which meant they had to come from the same FLA-file (unless we used <a href="http://www.swfmill.org" title="The home of SWFMill">swfmill</a> or something similarly fancy, which were in their infancy back then). Everything had to be exportable from the library and as items in the library couldn&#8217;t really be linked to classes directly, all item script had to be placed on the timeline. Of course it was a big mess and already back then we were hoping for a better way of loading content from external files (did anyone <strong>ever</strong> find out how to utilize &#8220;shared libraries&#8221; for actual production value?).</p>
<p>And now we have this feature &#8211; it is so much better. Create a symbol in a library in any FLA-file, load the resulting SWF-file in your production and instantiate any symbol from it and attach it anywhere you like. Clean and beautiful and exactly what we needed back then &#8211; and when going back, you really get that feeling again.</p>
<h3 id="toc-number-3-error-handling-and-run-time-validation">Number 3: Error handling and run-time validation</h3>
<blockquote><p>When it doesn&#8217;t say anything, does that mean no error happened?</p></blockquote>
<p>Imagine having put your AS2 production live, have it loaded in the browser and an error happens (because you visually can see that something is wrong) &#8211; how the h¤ll do you find out what happened? There were the old debugger, but it was crap &#8211; simply crap. You could only hope that you had enough trace&#8217;s spread around to debug based on your flashlog.txt file.</p>
<p>With AS3 we got run-time validation. If something is wrong, we (most of the time) get a huge ugly error popping out. It might look bad, might give bad user experience (if so, they ought to stop using the debug player though) but to the developer it gives the necessary feedback (thank you stack trace). And not to mention all the other advantages that run-time validation gives.</p>
<h3 id="toc-number-2-function-scoping">Number 2: Function scoping</h3>
<blockquote><p>I simply <strong>hate</strong> delegate.</p></blockquote>
<p>When doing pseudo-OOP like in ActionScript 2 (or AS1 or JavaScript), you constantly need to bind your functions as methods of your class instances in order to be sure, that if passed by reference, they are invoked in the right place. In ActionScript 3, this is no longer necessary. Basically, when passing a reference to a method of a class to someone or somewhere else, the scope of the method (being the originating instance) remains intact:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> a<span style="color: #000000; 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: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">b</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Object</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">c</span><span style="color: #000000; 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: #004993;">b</span>.<span style="color: #004993;">addChild</span> = a.<span style="color: #004993;">addChild</span>;
<span style="color: #004993;">b</span>.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">c</span><span style="color: #000000;">&#41;</span>;
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>a.<span style="color: #004993;">numChildren</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// traces &quot;1&quot;</span></pre></div></div>

<p>Anyone using AS3 knows this by now, but this was just to re-iterate and give an example.</p>
<p>Actually, it is not function scoping. It is more about creating a clear distinction between functions and methods. Functions are anonymous and created inline and don&#8217;t really use a &#8220;this&#8221;-scope but a reference scope. Methods are attributes of classes and are always invoked <strong>on</strong> instances of the class.</p>
<p>It does remove some &#8220;scriptability&#8221; in ActionScript, as currying and similar tricks aren&#8217;t as useful anymore and actually you never use &#8220;normal&#8221; functions at all &#8211; only methods. But intelligent use of patterns can have the same effects as such minor tricks and though they require more typing, they produce cleaner and often more intelligent, re-usable code. But that is the target of a whole other discussion.</p>
<h3 id="toc-number-1-the-display-list-instead-of-depths">Number 1: The display-list instead of depths</h3>
<blockquote><p>myClip.getNextHighestDepthLowerThanTheDepthOfTheMenu()</p></blockquote>
<p>Depth. The most annoying part of AS2. I didn&#8217;t realize it back then, you were so accustomed to writing foo.createEmptyMovieClip(&#8220;myclip&#8221;, foo.getNextHighestDepth()) and then swapDepths&#8217;ing it all around afterwards, but now that I don&#8217;t need it anymore but have to go back to using it &#8211; it is so time consuming.</p>
<p>At first, the display list sounded a bit scary to me and the very first demos of the language explaining MXML and layout schemes gave horrible flashbacks to the script-consuming &#8220;layout engine&#8221;, that Java and SWING employs. But most of us never use any of those layout schemes, simply add items to stage on coordinates with the display list being the best tool to ensure proper depth management. Thank you!</p>
<p>&nbsp;</p>
<p>Please leave comments, if you have other features than you constantly find yourself missing, or in other ways believe you can improve this list. Oh, and if you have suggestions for other lists, then by all means add them here.</p>


<p>Related posts:<ol><li><a href='http://www.barklund.org/blog/2009/07/01/minor-change-in-handling-nan-positions-in-flash-player-10-0-22/' rel='bookmark' title='Permanent Link: Minor change in handling NaN positions in Flash Player 10,0,22'>Minor change in handling NaN positions in Flash Player 10,0,22</a></li>
<li><a href='http://www.barklund.org/blog/2009/11/04/advanced-e4x-assignment-xmllists/' rel='bookmark' title='Permanent Link: Advanced E4X &#8211; Assignment to XMLLists'>Advanced E4X &#8211; Assignment to XMLLists</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.barklund.org/blog/2009/07/19/top-6-as3-features-you-miss-when-switching-back-to-as2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Sys-Con once again attacks Aral Balkan with stupidity and ignorance</title>
		<link>http://www.barklund.org/blog/2009/07/15/sys-con-aral-balkan-stupidity-ignorance/</link>
		<comments>http://www.barklund.org/blog/2009/07/15/sys-con-aral-balkan-stupidity-ignorance/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 14:44:16 +0000</pubDate>
		<dc:creator>Barklund</dc:creator>
				<category><![CDATA[Flash Platform]]></category>
		<category><![CDATA[Trends]]></category>

		<guid isPermaLink="false">http://www.barklund.org/blog/?p=198</guid>
		<description><![CDATA[Sys-Con Media has again and again tried to spread libel about Aral Balkan because he originally bad-mouthed them on Twitter and in other places, because they stole an article from him and claimed his endorsement of their products and services. Apparently they continue to try and spread rumors about him and recently Turks in general. [...]


Related posts:<ol><li><a href='http://www.barklund.org/blog/2010/02/12/vimeo-vulnerable-csrf/' rel='bookmark' title='Permanent Link: Vimeo highly vulnerable to CSRF attacks &#8211; now fixed'>Vimeo highly vulnerable to CSRF attacks &#8211; now fixed</a></li>
<li><a href='http://www.barklund.org/blog/2009/11/23/iphone-developer-boycott-in-the-works/' rel='bookmark' title='Permanent Link: The iPhone developer boycott in the works'>The iPhone developer boycott in the works</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.sys-con.com" title="Home of Sys-Con Media" rel="no-follow nofollow">Sys-Con Media</a> has <a href="http://aralbalkan.com/2056" title="From aralbalkan.com: And Sys-Con defames me ">again</a> and <a href="http://aralbalkan.com/2067" title="From aralbalkan.com: And Sys-Con libels me *again*">again</a> tried to spread libel about <a href="http://aralbalkan.com" title="Personal homepage and blog">Aral Balkan</a> because he originally bad-mouthed them on Twitter and in other places, because <a href="http://aralbalkan.com/2022" title="From aralbalkan.com: Sys-Con goes from bad to worse, launches Ulitzer, attacks community and content creators">they stole an article from him and claimed his endorsement of their products and services</a>. Apparently <a href="http://aralbalkan.com/2274" title="From aralbalkan.com: Aral Balkan - Are you bored yet? Sys-Con attacks me once more">they continue to try and spread rumors about him and recently Turks in general</a>.</p>
<p><span id="more-198"></span></p>
<p>And coming to Aral&#8217;s defense might not really work, as Sys-Con apparently isn&#8217;t web-savvy enough to know how e.g. Twitter works, as they claim that <a href="http://twitter.com/adobeted" title="@adobeted on Twitter">@adobeted</a>&#8216;s <a href="http://www.barklund.org/blog/2009/07/15/sys-con-aral-balkan-stupidity-ignorance/adobeted/" rel="attachment wp-att-202" title="Snapshot of @adobeteds's update">update about him wanting the company to die</a> in Sys-Con&#8217;s eyes becomes &#8220;Aral Balkan&#8217;s Twitter post on Adobe Ted&#8217;s (Ted Patrick) home page declaring death to SYS-CON Media&#8221; even though it is clearly @adobeted, who in this instance has this wish &#8211; as well as the rest of the Flash community and also a large part of the internet community in general, as the entire practice of Sys-Con in these matters are stupid, ignorant, enraging, intolerable and straight-out illegal.</p>
<p>Well, I hereby express my deep despise against the practice and entire company of Sys-Con Media and I as well wish the company to die (would that be a Dihad, as I am Danish?) and furthermore extend my best hopes for Aral Balkan and my support for his fight against a well-funded but ill-minded corporation.</p>


<p>Related posts:<ol><li><a href='http://www.barklund.org/blog/2010/02/12/vimeo-vulnerable-csrf/' rel='bookmark' title='Permanent Link: Vimeo highly vulnerable to CSRF attacks &#8211; now fixed'>Vimeo highly vulnerable to CSRF attacks &#8211; now fixed</a></li>
<li><a href='http://www.barklund.org/blog/2009/11/23/iphone-developer-boycott-in-the-works/' rel='bookmark' title='Permanent Link: The iPhone developer boycott in the works'>The iPhone developer boycott in the works</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.barklund.org/blog/2009/07/15/sys-con-aral-balkan-stupidity-ignorance/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
