<?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>Valentin Simonov&#039;s Flash Blog &#187; to think</title>
	<atom:link href="http://va.lent.in/blog/category/tothink/feed/" rel="self" type="application/rss+xml" />
	<link>http://va.lent.in/blog</link>
	<description>Making things move since 1999</description>
	<lastBuildDate>Mon, 19 Jul 2010 08:09:34 +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>How to fix Flash Builder broken workspace.</title>
		<link>http://va.lent.in/blog/2010/07/12/how-to-fix-flash-builder-broken-workspace/</link>
		<comments>http://va.lent.in/blog/2010/07/12/how-to-fix-flash-builder-broken-workspace/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 12:30:55 +0000</pubDate>
		<dc:creator>Valentin</dc:creator>
				<category><![CDATA[to think]]></category>
		<category><![CDATA[.snap]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Freeze]]></category>
		<category><![CDATA[Workspace]]></category>

		<guid isPermaLink="false">http://va.lent.in/blog/?p=363</guid>
		<description><![CDATA[From time to time I get weird Flash Builder/OS X crashes which lead to Flash Builder (Eclipse) freeze or hang up during startup. You think you have to recreate your workspace every time after a crash, but no, if that happens there&#8217;s a solution. So, if Flash Builder freezes trying to load your workspace what [...]]]></description>
			<content:encoded><![CDATA[<p>From time to time I get weird Flash Builder/OS X crashes which lead to Flash Builder (Eclipse) freeze or hang up during startup. You think you have to recreate your workspace every time after a crash, but no, if that happens there&#8217;s a solution.</p>
<p>So, if Flash Builder freezes trying to load your workspace what you need to do to fix it is to navigate to <strong>.metadata/.plugins/org.eclipse.core.resources</strong> and delete the file named <strong>.snap</strong>. That&#8217;s it. No more rearranging views and reimporting projects!</p>
]]></content:encoded>
			<wfw:commentRss>http://va.lent.in/blog/2010/07/12/how-to-fix-flash-builder-broken-workspace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tired of people using stage in constructor?</title>
		<link>http://va.lent.in/blog/2010/06/29/tired-of-people-using-stage-in-constructor/</link>
		<comments>http://va.lent.in/blog/2010/06/29/tired-of-people-using-stage-in-constructor/#comments</comments>
		<pubDate>Mon, 28 Jun 2010 22:16:46 +0000</pubDate>
		<dc:creator>Valentin</dc:creator>
				<category><![CDATA[to think]]></category>
		<category><![CDATA[apparat]]></category>
		<category><![CDATA[Error]]></category>
		<category><![CDATA[InitInjector]]></category>
		<category><![CDATA[null]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[Stage]]></category>

		<guid isPermaLink="false">http://va.lent.in/blog/?p=352</guid>
		<description><![CDATA[Recently someone in ruFlash user group asked if it&#8217;s possible to get rid of errors when loading a SWF which thinks it is the only SWF in the world and there totally must be stage available in its constructor. As you already understood such SWFs fail with Null Access errors. TypeError: Error #1009: Cannot access [...]]]></description>
			<content:encoded><![CDATA[<p>Recently someone in ruFlash user group asked if it&#8217;s possible to get rid of errors when loading a SWF which thinks it is the only SWF in the world and there totally must be stage available in its constructor. As you already understood such SWFs fail with Null Access errors.</p>
<blockquote><p><em>TypeError: Error #1009: Cannot access a property or method of a null  object reference.</em></p></blockquote>
<p>This task looks like a great exercise for my epic Scala skills I got trying to understand famous <a href="http://www.joa-ebert.com/">Joa</a>&#8216;s code.</p>
<p>Thanks to <a href="http://code.google.com/p/apparat/">apparat</a> and Scala I managed to code a small app which rewrites SWF files and moves all constructor code to a private method which is later subscribed to ADDED_TO_STAGE event.</p>
<blockquote><p><em><strong>usage</strong>: java -jar initInjector.jar [-c] &lt;from.swf&gt; [to.swf]&#8220;)<br />
-c — check for references to stage in constructor<br />
If [to.swf] is not specified resulting SWF is saved to &lt;from.swf&gt;</em></p></blockquote>
<p>The 0.1 version fails to move exceptions though. Trying to grasp that bytecode exceptions magic atm.</p>
<p>Here&#8217;s the application: <a href="http://va.lent.in/projects/swf/initInjector/initInjector.0.1.zip">initInjector.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://va.lent.in/blog/2010/06/29/tired-of-people-using-stage-in-constructor/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>AVM2Overview lies</title>
		<link>http://va.lent.in/blog/2010/06/18/avm2overview-lies/</link>
		<comments>http://va.lent.in/blog/2010/06/18/avm2overview-lies/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 09:34:04 +0000</pubDate>
		<dc:creator>Valentin</dc:creator>
				<category><![CDATA[to code]]></category>
		<category><![CDATA[to think]]></category>

		<guid isPermaLink="false">http://va.lent.in/blog/?p=341</guid>
		<description><![CDATA[It says: One of the entries in the ABC file is an array of script_info entries (see the next chapter). Each of these entries contains a reference to an initialization method for the script and a set of traits to be defined in the script’s environment. The last entry in that array is the entry [...]]]></description>
			<content:encoded><![CDATA[<p>It says:</p>
<blockquote><p>One of the entries in the ABC file is an array of script_info entries (see the next chapter). Each of these entries contains a reference to an initialization method for the script and a set of traits to be defined in the script’s environment. The last entry in that array is the entry point for the ABC file; that is, <strong>the last entry’s initialization method contains the first bytecode that’s run when the ABC file is executed</strong>.</p></blockquote>
<p>That&#8217;s apparently is not true. I keep getting different classes in the last entry except the main document class which I need. Thanks to <a href="http://twitter.com/joa">@joa</a> for pointing me to SymbolClass tag which contains an array to map Classes to Library Symbols in SWF files. And the very first class there seems to be the Document class I need.</p>
]]></content:encoded>
			<wfw:commentRss>http://va.lent.in/blog/2010/06/18/avm2overview-lies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash on Microsoft&#8217;s site</title>
		<link>http://va.lent.in/blog/2010/04/12/flash-on-microsofts-site/</link>
		<comments>http://va.lent.in/blog/2010/04/12/flash-on-microsofts-site/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 08:59:51 +0000</pubDate>
		<dc:creator>Valentin</dc:creator>
				<category><![CDATA[to think]]></category>
		<category><![CDATA[to view]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://va.lent.in/blog/?p=330</guid>
		<description><![CDATA[Well, the site for Russian launch of Visual Studio 2010 is a piece of crap. A piece of silverlight crap. Just check the sources. IT IS AN ABOMINATION!!! What&#8217;s more, the actual game is not in Silverlight, it is in Flash. And it fails with errors on some timer event which don&#8217;t go away. Microsoft [...]]]></description>
			<content:encoded><![CDATA[<p>Well, <a href="http://www.microsoft.com/visualstudio/ru-ru/contest/">the site</a> for Russian launch of Visual Studio 2010 is a piece of crap. A piece of silverlight crap. Just check the sources. IT IS AN ABOMINATION!!!</p>
<p>What&#8217;s more, the actual game is not in Silverlight, it is in Flash. And it fails with errors on some timer event which don&#8217;t go away.</p>
<p>Microsoft &#8220;can&#8221; make Flash. OLOLOLOLOLOL!!!!</p>
<p><a href="http://va.lent.in/blog/wp-content/uploads/2010/04/ms-lol.jpg"><img class="alignnone size-medium wp-image-331" title="ms-lol" src="http://va.lent.in/blog/wp-content/uploads/2010/04/ms-lol-500x324.jpg" alt="ms-lol" width="500" height="324" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://va.lent.in/blog/2010/04/12/flash-on-microsofts-site/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>R.I.P CS5 iPhone publishing</title>
		<link>http://va.lent.in/blog/2010/04/09/r-i-p-cs5-iphone-publishing/</link>
		<comments>http://va.lent.in/blog/2010/04/09/r-i-p-cs5-iphone-publishing/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 20:38:44 +0000</pubDate>
		<dc:creator>Valentin</dc:creator>
				<category><![CDATA[to think]]></category>
		<category><![CDATA[to view]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[CS5]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://va.lent.in/blog/?p=322</guid>
		<description><![CDATA[The new iPhone Developer Program License Agreement states&#8230; 3.3.1 Applications may only use Documented APIs in the manner prescribed by Apple and must not use or call any private APIs. Applications must be originally written in Objective-C, C, C++, or JavaScript as executed by the iPhone OS WebKit engine, and only code written in C, [...]]]></description>
			<content:encoded><![CDATA[<p>The new iPhone Developer Program License Agreement <a href="http://news.ycombinator.com/item?id=1250595">states</a>&#8230;</p>
<blockquote><p>3.3.1 Applications may only use Documented APIs in the manner prescribed by Apple and must not use or call any private APIs. Applications must be originally written in Objective-C, C, C++, or JavaScript as executed by the iPhone OS WebKit engine, and only code written in C, C++, and Objective-C may compile and directly link against the Documented APIs (e.g., <strong>Applications that link to Documented APIs through an intermediary translation or compatibility layer or tool are prohibited</strong>).</p></blockquote>
<blockquote><p><span><span style="color: #000000;">I&#8217;m sorta surprised they didn&#8217;t wait until Tuesday (after CS5 drops) to drop this bomb after everyone bought flash CS5. But then again, that&#8217;s likely why they did this show and tell today, to make sure people didn&#8217;t buy flash.</span></span></p></blockquote>
<p><span><span style="color: #000000;">Looks like Apple totally doesn&#8217;t want Flash on their devices. In any form.</span></span></p>
<p><span><span style="color: #000000;">R.I.P CS5 iPhone publishing.<br />
<span style="text-decoration: line-through;">It was good while it lasted.</span> Hell, it&#8217;s not even available yet.</span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://va.lent.in/blog/2010/04/09/r-i-p-cs5-iphone-publishing/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Git</title>
		<link>http://va.lent.in/blog/2010/03/16/git/</link>
		<comments>http://va.lent.in/blog/2010/03/16/git/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 09:11:26 +0000</pubDate>
		<dc:creator>Valentin</dc:creator>
				<category><![CDATA[to think]]></category>
		<category><![CDATA[Git]]></category>

		<guid isPermaLink="false">http://va.lent.in/blog/?p=309</guid>
		<description><![CDATA[This is how I want to use git.]]></description>
			<content:encoded><![CDATA[<p><a href="http://nvie.com/git-model">This is how</a> I want to use <a href="http://git-scm.com/">git</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://va.lent.in/blog/2010/03/16/git/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vote for me at FWA</title>
		<link>http://va.lent.in/blog/2010/03/15/vote-for-me-at-fwa/</link>
		<comments>http://va.lent.in/blog/2010/03/15/vote-for-me-at-fwa/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 00:09:27 +0000</pubDate>
		<dc:creator>Valentin</dc:creator>
				<category><![CDATA[to think]]></category>

		<guid isPermaLink="false">http://va.lent.in/blog/?p=307</guid>
		<description><![CDATA[I need your votes!]]></description>
			<content:encoded><![CDATA[<p><a href="http://thefwa.com/submissions/va-lent-in">I need your votes</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://va.lent.in/blog/2010/03/15/vote-for-me-at-fwa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash CS4</title>
		<link>http://va.lent.in/blog/2010/03/14/flash-cs4/</link>
		<comments>http://va.lent.in/blog/2010/03/14/flash-cs4/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 11:49:29 +0000</pubDate>
		<dc:creator>Valentin</dc:creator>
				<category><![CDATA[to think]]></category>
		<category><![CDATA[CS4]]></category>
		<category><![CDATA[Lags]]></category>

		<guid isPermaLink="false">http://va.lent.in/blog/?p=304</guid>
		<description><![CDATA[So, why Flash CS4 eats 69% of my CPU doing absolutely nothing in background? Yes I know I have 20 documents open, but anyway.]]></description>
			<content:encoded><![CDATA[<p>So, why Flash CS4 eats 69% of my CPU doing absolutely nothing in background? Yes I know I have 20 documents open, but anyway.</p>
<p><a href="http://va.lent.in/blog/wp-content/uploads/2010/03/cpu.jpg"><img class="alignnone size-full wp-image-305" title="cpu" src="http://va.lent.in/blog/wp-content/uploads/2010/03/cpu.jpg" alt="cpu" width="165" height="242" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://va.lent.in/blog/2010/03/14/flash-cs4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stupid code bits</title>
		<link>http://va.lent.in/blog/2010/03/14/stupid-code-bits/</link>
		<comments>http://va.lent.in/blog/2010/03/14/stupid-code-bits/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 21:57:00 +0000</pubDate>
		<dc:creator>Valentin</dc:creator>
				<category><![CDATA[to think]]></category>
		<category><![CDATA[CDATA]]></category>
		<category><![CDATA[Embed]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Snippet]]></category>

		<guid isPermaLink="false">http://va.lent.in/blog/?p=299</guid>
		<description><![CDATA[Every time I need to embed an image, text or binary file in ActionScript I have to go google &#8220;actionscript embed text file&#8221; because I simply don&#8217;t know this code snippet by heart: [Embed(source=&#34;text.txt&#34;,mimeType=&#34;application/octet-stream&#34;)] private var TextClass:Class; I bet this site gets a ton of visits from people like me. I just don&#8217;t know why [...]]]></description>
			<content:encoded><![CDATA[<p>Every time I need to embed an image, text or binary file in ActionScript I have to go google &#8220;actionscript embed text file&#8221; because I simply don&#8217;t know this code snippet by heart:</p>
<pre class="brush: as3;">[Embed(source=&quot;text.txt&quot;,mimeType=&quot;application/octet-stream&quot;)]
private var TextClass:Class;</pre>
<p></span></p>
<p><span>I bet <a href="http://techrays.wordpress.com/2007/09/19/embedding-text-files-in-a-flex-application/">this site</a> gets a ton of visits from people like me.</span></p>
<p><span>I just don&#8217;t know why but I can&#8217;t remember this [Embed] construct. I even have several snippets app helpers installed on my mac but all the time it&#8217;s faster to google </span>&#8220;actionscript embed text file&#8221;<span> instead of launching some app.</span></p>
<p><span>Same thing is with HTML CDATA syntax. I just can&#8217;t remember it. Every time I google &#8220;CDATA&#8221; just to get this:</span></p>
<pre class="brush: xml;">&lt;![CDATA[
 ...
 ]]&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://va.lent.in/blog/2010/03/14/stupid-code-bits/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>AS3 is weird. True story!</title>
		<link>http://va.lent.in/blog/2010/03/08/as3-is-weird-true-story/</link>
		<comments>http://va.lent.in/blog/2010/03/08/as3-is-weird-true-story/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 17:55:38 +0000</pubDate>
		<dc:creator>Valentin</dc:creator>
				<category><![CDATA[to code]]></category>
		<category><![CDATA[to think]]></category>
		<category><![CDATA[addedToStage]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Blooddy]]></category>
		<category><![CDATA[Compiler]]></category>
		<category><![CDATA[FileReference]]></category>
		<category><![CDATA[Hack]]></category>
		<category><![CDATA[IO Error]]></category>
		<category><![CDATA[load]]></category>
		<category><![CDATA[Loader]]></category>
		<category><![CDATA[Object]]></category>
		<category><![CDATA[removeChild]]></category>
		<category><![CDATA[Security Error]]></category>
		<category><![CDATA[Sound]]></category>
		<category><![CDATA[Super]]></category>
		<category><![CDATA[TextField]]></category>
		<category><![CDATA[Trick]]></category>
		<category><![CDATA[URLLoader]]></category>
		<category><![CDATA[URLStream]]></category>
		<category><![CDATA[Vector]]></category>
		<category><![CDATA[VerifyError]]></category>
		<category><![CDATA[Weird]]></category>

		<guid isPermaLink="false">http://va.lent.in/blog/?p=294</guid>
		<description><![CDATA[Well, every experienced AS3 developer once in a while faces weird things in our beloved ActionScript 3. Sometimes it&#8217;s funny but usually it isn&#8217;t, because results in hours of wasted time. Blooddy, my Belorussian friend, compiled some of the obstacles he faced in the past into the series of short microblog posts. In this post [...]]]></description>
			<content:encoded><![CDATA[<p>Well, every experienced AS3 developer once in a while faces weird things in our beloved ActionScript 3. Sometimes it&#8217;s funny but usually it isn&#8217;t, because results in hours of wasted time. Blooddy, my Belorussian friend, compiled some of the obstacles he faced in the past into <a href="http://juick.com/blooddy/?tag=%D0%B8%D0%B4%D0%B8%D0%BE%D1%82%D0%B8%D0%B7%D0%BC">the series of short microblog posts</a>. In this post I&#8217;ll try to translate those posts in English adding my own experience.</p>
<p>OK, I don&#8217;t know where to start, so the order here means nothing. Let&#8217;s start.</p>
<p><strong>1. LOL! ME BROKED TEH FLASH VERIFEIRZ!!!</strong></p>
<pre class="brush: as3;">for ( 	var i:uint = reversed ? array.length-1 : 0;
    reversed ? i &gt;= 0 : i &lt; array.length;
    reversed ? i-- : i++ ) {
}</pre>
<p>This code compiles perfectly but results in a huge bytecode dump and a weird error — <em>VerifyError: Error #1030: Stack depth is unbalanced. 1 != 0.</em></p>
<p>Don&#8217;t ask me how I got to this code.</p>
<p><strong>2. Object vs. Object</strong></p>
<pre class="brush: as3;">var a:Object = {};
a[&quot;a&quot;] = 1;
a[&quot;b&quot;] = 2;
a[&quot;c&quot;] = 3;
for ( var v:String in a ) {
    a[&quot;a&quot;] = 2;
    trace(v, a[v]);
}</pre>
<p>How do you think what this code will result into? You would guess something like</p>
<blockquote><p>a 2<br />
b 2<br />
c 3</p></blockquote>
<p>But it&#8217;s actually</p>
<blockquote><p>a 2<br />
a 2<br />
c 3</p></blockquote>
<p>for me.</p>
<p>If you change the first line to</p>
<pre class="brush: as3;">var a:Object = new Object();</pre>
<p>you&#8217;ll get</p>
<blockquote><p>b 2<br />
a 2<br />
c 3</p></blockquote>
<p>Of course Adobe didn&#8217;t promise order in collections which Objects are. Also, modifying a collection while working with it looks wrong anyway. But how come <em>new Object()</em> and <em>{}</em> differ so much, as far as I remember everyone says that both these constructs create an object, the later one just can handler properties to set. Apparently it&#8217;s not right.</p>
<p>Actually <em>{}</em> results into just one opcode <em>NewObject</em> while <em>new Object()</em> results in 2 opcodes: <em>look for class, create class</em> (sorry, will change for actual opcode names later). Anyway, you should be aware of this fact.</p>
<p><strong>3. Where did this <strong>Security Error</strong> came from?</strong></p>
<p>Imagine that we have a Socket object. We want to connect to some server but it&#8217;s down. We got <em>IO Error</em> and want to remove all listeners from Socket events and BOOOOM! we get a <em>Security Error</em> because Flash couldn&#8217;t get socket policy file (undoubtedly).</p>
<p>Who knew that right after <em>IO Error</em> we&#8217;ll get a <em>Security Error</em>?</p>
<p><strong>4. Who called this .load() ?</strong></p>
<p>Imagine we have a class extending Sound.</p>
<pre class="brush: as3;">public class S extends Sound {
  public function S() {
    super();
  }
  public override function load(stream:URLRequest, context:SoundLoaderContext=null):void {
    throw new Error( 'ZOMG PEW PEW!!!1' );
  }
}</pre>
<p>How do you think, what will we get after executing <em>var s:S = new S();</em> ?</p>
<p>Right, we&#8217;ll get <strong>ZOMG PEW PEW!!!1</strong> because despite of Flash help saying <em>&#8220;If you pass a valid URLRequest object to the Sound constructor, the constructor automatically calls the load() function for the Sound object.&#8221;</em>, constructor actually calls .load() anyway.</p>
<p><strong>5. Super()? What super()?</strong></p>
<p>Continuing #4, what if we could block parent constructor of being executed&#8230; But we can&#8217;t, if you don&#8217;t specify super() call compiler will add it automatically. Well, we could add it somewhere where it won&#8217;t be executed.</p>
<pre class="brush: as3;">if ( false ) {
  super();
}</pre>
<p>But damn, compiler is smart. But not so smart to overcome this:</p>
<pre class="brush: as3;">if ( !true ) {
  super();
}</pre>
<p>Or it knows something we don&#8217;t! Apparently !true isn&#8217;t always false. But we can skip executing super constructor until Adobe fixes it.</p>
<p><strong>6. GET MY CHILD BACK YOU BIATCH!!!</strong></p>
<p>Imagine that we have a <em>Container extends DisplayObjectContainer</em> which overrides <em>removeChild</em>() method to throw exception so bad people couldn&#8217;t remove children from it.</p>
<p>Let <em>child:DisplayObject</em> be a child of <em>container:Container</em>, now look at the code</p>
<pre class="brush: as3;">var s:Sprite = new Sprite();
s.addChild( child );
s.removeChild( child );</pre>
<p>Apparently, it bypasses our overridden method and STEALS OUR CHILD!!!!1</p>
<p><strong>7. Wait, so many loaders&#8230; I&#8217;m confused&#8230;</strong></p>
<p>All the time we use loaders of different kinds: Loader, Sound, URLLoader, URLStream, FileReference. So why are they so different?</p>
<p><em>1. Loader.</em></p>
<ul>
<li>First of all it extends DisplayObject, maybe that&#8217;s why everything loading related is in contentLoaderInfo (this is what makes me mad every time).</li>
<li>load(request:URLRequest, context:LoaderContext = null):void</li>
<li>bytesLoaded:uint (read-only)</li>
<li>bytesTotal:uint (read-only)</li>
<li>url:String (read-only)</li>
</ul>
<p><em>2. Sound.</em></p>
<ul>
<li>load(stream:URLRequest, context:SoundLoaderContext = null):void</li>
<li>bytesLoaded:uint (read-only)</li>
<li>bytesTotal:<strong>int</strong> (read-only)</li>
<li>url:String (read-only)</li>
<li>Doesn&#8217;t have <em>httpStatus</em> event</li>
</ul>
<p><em>3. URLLoader.</em></p>
<ul>
<li>load(request:URLRequest):void</li>
<li>bytesLoaded:uint (read-write)</li>
<li>bytesTotal:uint (read-write)</li>
<li>Also, why all URLLoader&#8217;s properties are public variables not accessors?</li>
</ul>
<p><em>4. URLStream.</em></p>
<ul>
<li>load(request:URLRequest):void</li>
<li>No bytesLoaded or bytesTotal, but at least we get a progress event</li>
</ul>
<p><em>5. FileReference.</em></p>
<ul>
<li>We get 3 methods to load data: load, download, upload</li>
<li>No bytesLoaded or bytesTotal, but at least we get a progress event</li>
</ul>
<p>And last, ProgressEvent has properties bytesLoaded (read-write) and bytesTotal (read-write). Both of type <strong>NUMBER</strong>.</p>
<p>So if you want to implement your own universal loader you must know all these differences.</p>
<p><strong>8. Missing TextField.</strong></p>
<p>Flash says that inheritance chain for TextField is the following: TextField -> InteraftiveObject -> DisplayObject -> EventDispatcher -> Object. Apparently there&#8217;s DisplayObjectContainer missing because we can do the following:</p>
<pre class="brush: as3;">public function test() {
  var t:TextField = new TextField();
  t.addEventListener( Event.ADDED, this.handler_addedToStage )
  t.width = 400;
  t.height = 200;
  t.htmlText = ' &lt;img src=&quot;http://www.google.ru/logos/olympics10-hockey-hp.png&quot; /&gt;';
  super.addChild( t );
}
private function handler_addedToStage(event:Event):void {
  if ( event.target == event.currentTarget ) return;
  trace( event.target );
}</pre>
<p>The code results in </p>
<blockquote><p>[object Loader]<br />
[object Sprite]</p></blockquote>
<p>It means that we can grab Loaders for HTML images and preload them. Also we can reparent them using the trick above (8</p>
<p><strong>9. Hi, I am addedToStage! Hi, I am addedToStage!</strong></p>
<p>Here&#8217;s the code:</p>
<pre class="brush: as3;">public function test() {
  var s1:Sprite = new Sprite();
  s1.addEventListener( Event.ADDED_TO_STAGE, handler );
  super.addChild( s1 );
}

private function handler(event:Event):void {
  var s2:Sprite = new Sprite();
  s2.addEventListener( Event.ADDED_TO_STAGE, trace );
  ( event.target as Sprite ).addChild( s2 );
}</pre>
<p>Do you expect to see only one trace? Nope, you&#8217;ll get TWO!</p>
<p>And here&#8217;s why. We know that <em>addedToStage</em> event is dispatched in the <em>addChild</em>() method. After executing it must tell all children that they were added to stage too. So, when we add a new object to display list in <em>handler</em>() it first gets its own event and after that execution flow returns back to <em>super.addChild</em>() where it tells all its children about them being added to stage. And there&#8217;s where the second event comes from.</p>
<p>Of course if we add more children objects we&#8217;ll get more misleading events.</p>
<p><strong>10. __AS3__.vec</strong></p>
<p>The Vector class is kind of mysterious. Flash help says that it is top level class but actually it relies in virtual package <em>__AS3__.vec</em> which doesn&#8217;t actually exists but is made by compiler.</p>
<p>Looks like a patch which is there since some early beta of Flash Player 10.</p>
<p><strong>HOORAY!</strong></p>
<p>That&#8217;s all for now. If you have something to add to the list feel free to mail me or leave a comment here.</p>
]]></content:encoded>
			<wfw:commentRss>http://va.lent.in/blog/2010/03/08/as3-is-weird-true-story/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
