<?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>Max Blog &#187; AS3 Creative point of view</title>
	<atom:link href="http://maxblog.bomzhi.de/?feed=rss2&#038;cat=4" rel="self" type="application/rss+xml" />
	<link>http://maxblog.bomzhi.de</link>
	<description>My Blog</description>
	<lastBuildDate>Tue, 17 Aug 2010 11:36:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Summary on AS3 Creative point of view</title>
		<link>http://maxblog.bomzhi.de/?p=234</link>
		<comments>http://maxblog.bomzhi.de/?p=234#comments</comments>
		<pubDate>Sun, 25 Jul 2010 13:33:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AS3 Creative point of view]]></category>
		<category><![CDATA[IDE]]></category>

		<guid isPermaLink="false">http://maxblog.bomzhi.de/?p=234</guid>
		<description><![CDATA[I don&#8217;t think I would write something new to this topic because this year I kind of changed my sphere of action. And to summarize the category I would like to post a link to the talk I gave on Adobe User Group Nederland. It&#8217;s kind of embarrassing for me, because this video doesn&#8217;t put [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t think I would write something new to this topic because this year I kind of changed my sphere of action.</p>
<p>And to summarize the category I would like to post a link to the talk I gave on Adobe User Group Nederland.</p>
<p>It&#8217;s kind of embarrassing for me, because this video doesn&#8217;t put my presentation skills at the glance, but the content is quit interesting in my opinion. It is quit long though, it was a strange slot on this conference I got two hours. Too short for a tutorial and pretty long for a talk. But enough with explanations, here it is:</p>
<p><a href="http://www.adobeusergroup.nl/site/list_messages/391">http://www.adobeusergroup.nl/site/list_messages/391</a></p>
]]></content:encoded>
			<wfw:commentRss>http://maxblog.bomzhi.de/?feed=rss2&amp;p=234</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Internal DSL</title>
		<link>http://maxblog.bomzhi.de/?p=185</link>
		<comments>http://maxblog.bomzhi.de/?p=185#comments</comments>
		<pubDate>Fri, 16 Apr 2010 10:23:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AS3 Creative point of view]]></category>

		<guid isPermaLink="false">http://maxblog.bomzhi.de/?p=185</guid>
		<description><![CDATA[After watching this talk : http://www.infoq.com/presentations/Design-Your-Own-DSL-with-Groovy I remembered that I wanted to write about internal DSL in ActionScript. So first of all what is DSL (for those who are to lazy to follow the wikipedia link) DSL (Domain Specific Language) is a language that you use for some specific type of problems. For example you [...]]]></description>
			<content:encoded><![CDATA[<p>After watching this talk :<br />
<a href="http://www.infoq.com/presentations/Design-Your-Own-DSL-with-Groovy">http://www.infoq.com/presentations/Design-Your-Own-DSL-with-Groovy</a></p>
<p>I remembered that I wanted to write about internal <a href="http://en.wikipedia.org/wiki/Domain_Specific_Language">DSL</a> in ActionScript.</p>
<p>So first of all what is DSL (for those who are to lazy to follow the wikipedia link)</p>
<p>DSL (Domain Specific Language) is a language that you use for some specific type of problems.<br />
For example you want to draw stuff. You know that if you want to draw something you have to declare a shape that is described by points. The language you create for this one and only problem, should be very specific and clear, so that it is fun to read and write.</p>
<p>There are two ways of creating a Domain Specific Language and also two types of DSLs.</p>
<p><strong>External DSL</strong> is a language with natural language syntax that you have to parse by RegEx or a parser.</p>
<p><strong>Internal DSL</strong> created by appliance of the language you write this DSL with.</p>
<p>In the talk I have mentioned above, the speaker describes what are the possibilities to create an internal DSL with Groovy, and it is pretty cool <img src='http://maxblog.bomzhi.de/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<p>In my opinion ActionScript provides you with three posibilities of creating a DSL:</p>
<p><strong>First: XML</strong><br />
If you think about it, MXML is also an internal DSL written in XML and read by MXMLC compiler. You could write a framework that could read XML and process something out of this. For example painted something on the stage.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p185code3'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1853"><td class="code" id="p185code3"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;shape<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;point</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">'10'</span>, <span style="color: #000066;">y</span>= <span style="color: #ff0000;">'20'</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;point</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">'30'</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">'40'</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;point</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">'25 y='</span>25<span style="color: #ff0000;">'/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/shape<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p><strong>Second: Plane Text</strong><br />
Write your domain specific  stuff in plain text and parse it with RegEx. Natural language is alway easier to read and write if you describe some simple rules or state.</p>
<p><strong>Third: Object initializer</strong><br />
In my opinion it is the powerful one, because you can add behavior to your DSL</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p185code4'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1854"><td class="code" id="p185code4"><pre class="actionscript" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">var</span> shape = <span style="color: #66cc66;">&#123;</span>
     points: <span style="color: #66cc66;">&#91;</span>
        <span style="color: #66cc66;">&#123;</span>x:<span style="color: #cc66cc;">10</span>, y:<span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#125;</span>,
        <span style="color: #66cc66;">&#123;</span>x:<span style="color: #cc66cc;">30</span>, y:<span style="color: #cc66cc;">40</span><span style="color: #66cc66;">&#125;</span>,
        <span style="color: #66cc66;">&#123;</span>x:<span style="color: #cc66cc;">25</span>, y:<span style="color: #cc66cc;">25</span><span style="color: #66cc66;">&#125;</span>
     <span style="color: #66cc66;">&#93;</span>,
     onClick: <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
          <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">points</span><span style="color: #66cc66;">&#41;</span>
     <span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>As you can see you could create a framework as powerful as Flex that works on DSL created with object intializer syntax, that would look JavaFx like <img src='http://maxblog.bomzhi.de/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
]]></content:encoded>
			<wfw:commentRss>http://maxblog.bomzhi.de/?feed=rss2&amp;p=185</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaFx vs. MXML syntax and language design</title>
		<link>http://maxblog.bomzhi.de/?p=15</link>
		<comments>http://maxblog.bomzhi.de/?p=15#comments</comments>
		<pubDate>Mon, 08 Feb 2010 05:36:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AS3 Creative point of view]]></category>

		<guid isPermaLink="false">http://maxblog.bomzhi.de/?p=15</guid>
		<description><![CDATA[Both languages are designed for UI declaration. MXML is XML based representation of UI tree. Each XML tags represent UI components implemented in AS3 and you have many possibilities to embed AS3 code in MXML. Under the hoods the compiler will generate a number of AS files from one MXML file and compile them to [...]]]></description>
			<content:encoded><![CDATA[<p>Both languages are designed for UI declaration.</p>
<p>MXML is XML based representation of UI tree. Each XML tags represent UI components implemented in AS3 and you have many possibilities to embed AS3 code in MXML. Under the hoods the compiler will generate a number of AS files from one MXML file and compile them to a Flash Application (SWF file).</p>
<p>JavaFx is a complete new script language with AS3 like syntax. The representation of  UI tree is JSON like, so it&#8217;s not as verbose as XML. I am not familiar with the internal processing of &#8220;fx&#8221; scripts but after compilation you get a few &#8220;.class&#8221; files that represent the elements you declared in the script.</p>
<p>JavaFx is just a script language for JVM, like for example Groovy, that has some special tools for UI creation.</p>
<p>In my opinion those are the key benefits compared to ActionScript 3:<br />
- Function signatures are strong typed</p>
<div class="syhi_block"><code>function(:Number):Boolean</code></div>
<p>- Static is banned in favor of Script Variable / Function<br />
- Ranges are provided</p>
<div class="syhi_block"><code>for (x in [1..5]) {<br />
&nbsp; &nbsp;[x, x*x]<br />
}</code></div>
<p>- first citizen value changed observer</p>
<div class="syhi_block"><code>var x = 0 on replace { println(&quot;x is now: {x}&quot;) }</code></div>
<p>- first citizen value binding</p>
<div class="syhi_block"><code>var y = 3; <br />
function ten() : Integer { <br />
&nbsp; &nbsp;println(&quot;Called ten&quot;);<br />
&nbsp; &nbsp;10 <br />
} <br />
def sum = bind ten() + y; <br />
println(sum); <br />
y = 7; <br />
println(sum);</code></div>
<p>-immutable objects and elements<br />
-Bidirectional Binding</p>
<p>If you are interested in details have a look at this URL:<br />
<a href="http://openjfx.java.sun.com/current-build/doc/reference/JavaFXReference.html">http://openjfx.java.sun.com/current-build/doc/reference/JavaFXReference.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://maxblog.bomzhi.de/?feed=rss2&amp;p=15</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Duck type</title>
		<link>http://maxblog.bomzhi.de/?p=133</link>
		<comments>http://maxblog.bomzhi.de/?p=133#comments</comments>
		<pubDate>Sat, 16 Jan 2010 16:28:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AS3 Creative point of view]]></category>
		<category><![CDATA[BehaveAS]]></category>

		<guid isPermaLink="false">http://maxblog.bomzhi.de/?p=133</guid>
		<description><![CDATA[A few weeks ago I was watching this talk. The speaker persuaded everybody to check out Erlang. I already heard about this language because of it&#8217;s concurrency paradigms, so I thought to give it a try. After browsing thru the specs I found an interesting construct: Pattern and Guard. It reminded me a little of [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago I was watching this <a href="http://www.infoq.com/presentations/vinoski-rpc-convenient-but-flawed">talk</a>. The speaker persuaded everybody to check out <a href="http://erlang.org/">Erlang</a>.  I already heard about this language because of it&#8217;s concurrency paradigms, so I thought to give it a try.</p>
<p>After browsing thru the specs I found an interesting construct: Pattern and Guard.</p>
<p>It reminded me a little of my <a href="http://code.google.com/p/behaveas/source/browse/trunk/BehaveAS/src/mz/behaveas/model/ducktype/Duck.as">Duck</a> class that I wrote for BehaveAS. Th idea behind Duck was to define expectation return value in a simple internal DSL manner.<br />
So for example I am expecting that an array will have three entries and I am only interested in second item. Or a better example when I expect an exception with a certain error id. It&#8217;s quite complicated to do this stuff without Duck <img src='http://maxblog.bomzhi.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>Here is an example of use:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p133code7'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1337"><td class="code" id="p133code7"><pre class="actionscript" style="font-family:monospace;">package <span style="color: #66cc66;">&#123;</span>
  <span style="color: #0066CC;">import</span> mz.<span style="color: #006600;">behaveas</span>.<span style="color: #006600;">model</span>.<span style="color: #006600;">ducktype</span>.<span style="color: #006600;">Duck</span>;
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
&nbsp;
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DuckTypeTest <span style="color: #0066CC;">extends</span> Sprite <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> DuckTypeTest<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">var</span> a : <span style="color: #66cc66;">*</span> = <span style="color: #cc66cc;">23</span>;
      <span style="color: #000000; font-weight: bold;">var</span> duck : Duck = Duck.<span style="color: #0066CC;">type</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>_type_:<span style="color: #0066CC;">String</span>, <span style="color: #0066CC;">toString</span>:<span style="color: #ff0000;">&quot;23&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>duck.<span style="color: #006600;">equals</span><span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
      	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>duck.<span style="color: #006600;">getReport</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #66cc66;">&#125;</span>
      <span style="color: #000000; font-weight: bold;">var</span> a1 : <span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">2</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #ff0000;">&quot;asd&quot;</span><span style="color: #66cc66;">&#93;</span>;
      <span style="color: #000000; font-weight: bold;">var</span> duck1 : Duck = Duck.<span style="color: #0066CC;">type</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span><span style="color: #cc66cc;">1</span>:<span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">3</span>:Duck.<span style="color: #0066CC;">type</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>_type_:<span style="color: #0066CC;">String</span>,<span style="color: #0066CC;">toUpperCase</span>:<span style="color: #ff0000;">&quot;ASD&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>duck1.<span style="color: #006600;">equals</span><span style="color: #66cc66;">&#40;</span>a1<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
      	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>duck1.<span style="color: #006600;">getReport</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>As you can see you can also check methods for those return values (but only if those methods doesn&#8217;t need parameters <img src='http://maxblog.bomzhi.de/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ).</p>
<p>So back to Erlang, Pattern and Guards. I thought it would be a great idea to use Duck as a Guard for input parameters in a function.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p133code8'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1338"><td class="code" id="p133code8"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> foo<span style="color: #66cc66;">&#40;</span>a: <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">var</span> matcher : Duck = Duck.<span style="color: #0066CC;">type</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">length</span>:<span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>matcher.<span style="color: #006600;">equals</span><span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
    <span style="color: #b1b100;">return</span>;
  <span style="color: #66cc66;">&#125;</span>
  <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>But I am not sure about performance!</p>
]]></content:encoded>
			<wfw:commentRss>http://maxblog.bomzhi.de/?feed=rss2&amp;p=133</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>To type, or not to type</title>
		<link>http://maxblog.bomzhi.de/?p=123</link>
		<comments>http://maxblog.bomzhi.de/?p=123#comments</comments>
		<pubDate>Thu, 24 Dec 2009 15:05:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AS3 Creative point of view]]></category>

		<guid isPermaLink="false">http://maxblog.bomzhi.de/?p=123</guid>
		<description><![CDATA[Static typing is a great thing. It makes a really good IDE support possible. It&#8217;s encourage you by developing, because your code is validated by compiler and you can write intuitive API&#8217;s. But some times it is also cool to have dynamic typing. AS3 is a very creative language also from this point of view. [...]]]></description>
			<content:encoded><![CDATA[<p>Static typing is a great thing. It makes a really good IDE support possible. It&#8217;s encourage you by developing, because your code is validated by compiler and you can write intuitive API&#8217;s.</p>
<p>But some times it is also cool to have dynamic typing.</p>
<p>AS3 is a very creative language also from this point of view. It let&#8217;s you extend code in many ways.<br />
First and most convenient way is class inheritance. So you have a class A and it is extended by class B. Nothing special it is a rudimentary feature of an OO language.</p>
<p>Second and not convenient way of extending an instance of a class is to declare the class as dynamic (have a look at Object class).</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p123code11'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12311"><td class="code" id="p123code11"><pre class="actionscript" style="font-family:monospace;">package <span style="color: #66cc66;">&#123;</span>
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyClass <span style="color: #0066CC;">extends</span> Sprite <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">var</span> a : <span style="color: #0066CC;">Object</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
      a.<span style="color: #006600;">element</span> = <span style="color: #cc66cc;">30</span>;
      <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'a.element: '</span> + <span style="color: #66cc66;">&#40;</span>a.<span style="color: #006600;">element</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>But you can also extend a class that is final or not dynamic in AS3, because AS3 is not only Class based OO language but also Prototype based. That&#8217;s how we can implement so called <a href="http://en.wikipedia.org/wiki/Monkey_patch">monkey patching</a>.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p123code12'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12312"><td class="code" id="p123code12"><pre class="actionscript" style="font-family:monospace;">package <span style="color: #66cc66;">&#123;</span>
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MonkeyPatch <span style="color: #0066CC;">extends</span> Sprite <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MonkeyPatch<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      <span style="color: #0066CC;">Object</span>.<span style="color: #0066CC;">prototype</span>.<span style="color: #006600;">sayHello</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;hello from &quot;</span> + <span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #66cc66;">&#125;</span>;
      <span style="color: #000000; font-weight: bold;">var</span> myThis : <span style="color: #66cc66;">*</span> = <span style="color: #0066CC;">this</span>;
      myThis.<span style="color: #006600;">sayHello</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #000000; font-weight: bold;">var</span> s : Sprite = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
      addChild<span style="color: #66cc66;">&#40;</span>s<span style="color: #66cc66;">&#41;</span>;
      <span style="color: #000000; font-weight: bold;">var</span> myS : <span style="color: #66cc66;">*</span> = s;
      myS.<span style="color: #006600;">sayHello</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://maxblog.bomzhi.de/?feed=rss2&amp;p=123</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Those funny declarations</title>
		<link>http://maxblog.bomzhi.de/?p=119</link>
		<comments>http://maxblog.bomzhi.de/?p=119#comments</comments>
		<pubDate>Tue, 22 Dec 2009 14:18:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AS3 Creative point of view]]></category>

		<guid isPermaLink="false">http://maxblog.bomzhi.de/?p=119</guid>
		<description><![CDATA[When you declare a local variable in AS3 it turns out that it is visible for the hole scope it was declared in. So for example you can declare a variable after its usage in code: ?View Code ACTIONSCRIPTpackage &#123; import flash.display.Sprite; public class Decl extends Sprite &#123; public function Decl&#40;&#41; &#123; trace&#40;a&#41;; var a [...]]]></description>
			<content:encoded><![CDATA[<p>When you declare a local variable in AS3 it turns out that it is visible for the hole scope it was declared in.<br />
So for example you can declare a variable after its usage in code:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p119code17'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p11917"><td class="code" id="p119code17"><pre class="actionscript" style="font-family:monospace;">package <span style="color: #66cc66;">&#123;</span>
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Decl <span style="color: #0066CC;">extends</span> Sprite <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Decl<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	  <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#41;</span>;
	  <span style="color: #000000; font-weight: bold;">var</span> a : <span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;hello&quot;</span>;
	<span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>But the assignment will be executed as &#8220;expected&#8221; after the trace and that&#8217;s why you see &#8220;null&#8221; traced in the console.</p>
<p>You can also make a duplicate declaration of a local variable, if it keeps the same type.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p119code18'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p11918"><td class="code" id="p119code18"><pre class="actionscript" style="font-family:monospace;">package <span style="color: #66cc66;">&#123;</span>
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Decl <span style="color: #0066CC;">extends</span> Sprite <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Decl<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  	  <span style="color: #000000; font-weight: bold;">var</span> a : <span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;hello&quot;</span>;
	  <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#41;</span>;
	  <span style="color: #000000; font-weight: bold;">var</span> a : <span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;hello2&quot;</span>;
	  <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#41;</span>;
	  <span style="color: #808080; font-style: italic;">// var a : int = 2; That would be bad!</span>
	<span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Another interesting declaration behavior is the declaration of error variable in catch block:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p119code19'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p11919"><td class="code" id="p119code19"><pre class="actionscript" style="font-family:monospace;">package <span style="color: #66cc66;">&#123;</span>
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Decl <span style="color: #0066CC;">extends</span> Sprite <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Decl<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	  <span style="color: #0066CC;">try</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#41;</span>;
		a.<span style="color: #0066CC;">length</span>;
		<span style="color: #808080; font-style: italic;">// trace('error: ' + (error)); Invisible			</span>
	  <span style="color: #66cc66;">&#125;</span><span style="color: #0066CC;">catch</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">error</span>:<span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">var</span> a : <span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;error&quot;</span>;
		<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'a: '</span> + <span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'error: '</span> + <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">error</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	  <span style="color: #66cc66;">&#125;</span>
	  <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#41;</span>;
	  <span style="color: #808080; font-style: italic;">// trace('error: ' + (error)); Invisible</span>
	<span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>So error is only visible in the catch scope but the catch scope is not really a scope because if we declare variable &#8220;a&#8221; in the scope itself it is visible in the whole method.</p>
<p>Last funny example is about for-loop and static initializer.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p119code20'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p11920"><td class="code" id="p119code20"><pre class="actionscript" style="font-family:monospace;">package <span style="color: #66cc66;">&#123;</span>
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Decl <span style="color: #0066CC;">extends</span> Sprite <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span>;
    <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i : <span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>;i <span style="color: #66cc66;">&lt;</span> <span style="color: #0066CC;">array</span>.<span style="color: #0066CC;">length</span>;i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">array</span><span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Decl<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>The problem with this code is that variable &#8220;i&#8221; is declared inside of class declaration and that means that it is a field. It also not declared with static modifier and that&#8217;s why you can&#8217;t use it in  your static initializer code.</p>
]]></content:encoded>
			<wfw:commentRss>http://maxblog.bomzhi.de/?feed=rss2&amp;p=119</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>If you can&#8217;t overload them, namespace them</title>
		<link>http://maxblog.bomzhi.de/?p=98</link>
		<comments>http://maxblog.bomzhi.de/?p=98#comments</comments>
		<pubDate>Mon, 14 Dec 2009 12:55:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AS3 Creative point of view]]></category>

		<guid isPermaLink="false">http://maxblog.bomzhi.de/?p=98</guid>
		<description><![CDATA[ActionScript3 does not support method overloading, but why do you want to overload methods? In my opinion there are two answers: You want to pass the same method different amount of parameters You want to have methods with same name but different behavior In first case AS3 provides you the feature of default parameter values: ?View [...]]]></description>
			<content:encoded><![CDATA[<p>ActionScript3 does not support method <a href="http://en.wikipedia.org/wiki/Method_overloading">overloading</a>, but why do you want to overload methods?</p>
<p>In my opinion there are two answers:</p>
<ol>
<li>You want to pass the same method different amount of parameters</li>
<li>You want to have methods with same name but different behavior</li>
</ol>
<p>In first case AS3 provides you the feature of default parameter values:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p98code25'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p9825"><td class="code" id="p98code25"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> foo<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> a : <span style="color: #0066CC;">String</span>, <span style="color: #000000; font-weight: bold;">var</span> i : <span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>: <span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
  <span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span>;i<span style="color: #66cc66;">&amp;</span>lt;=<span style="color: #cc66cc;">0</span> ; i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>So you can call method foo with one parameter &#8220;foo(&#8216;hello&#8217;)&#8221; or with two &#8220;foo(&#8216;hello&#8217;, 2)&#8221;</p>
<p>Let&#8217;s talk about the second case: same name different behavior.</p>
<p>In this case you can use namespaces.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p98code26'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p9826"><td class="code" id="p98code26"><pre class="actionscript" style="font-family:monospace;">package my <span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> NamespaceExamp <span style="color: #66cc66;">&#123;</span>
&nbsp;
		namespace NS1;
		namespace NS2;
&nbsp;
		NS1 <span style="color: #000000; font-weight: bold;">function</span> foo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #66cc66;">&#125;</span>
		NS2 <span style="color: #000000; font-weight: bold;">function</span> foo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>The interesting part of namespaces is also that those are not declaration but URI based (like in XML). </p>
<p>Have a look at this example:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p98code27'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p9827"><td class="code" id="p98code27"><pre class="actionscript" style="font-family:monospace;">package my <span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> NamespaceExamp <span style="color: #66cc66;">&#123;</span>
&nbsp;
		namespace NS1 = <span style="color: #ff0000;">&quot;myNS&quot;</span>;
		namespace NS2 = <span style="color: #ff0000;">&quot;myNS&quot;</span>;
&nbsp;
		NS1 <span style="color: #000000; font-weight: bold;">function</span> foo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #66cc66;">&#125;</span>
		NS2 <span style="color: #000000; font-weight: bold;">function</span> foo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>In this case foo is a duplicate method and it doesn&#8217;t matter that we declared two namespaces, their URIs are same so both foo declarations are in the same namespace. BTW if you don&#8217;t declare URI explicitly as in the first namespace example than the runtime will generate a namespace by the location of declaration (complicated stuff).</p>
<p>Another interesting fact is that the keyword &#8220;public&#8221; is also a namespace, but with empty URI. </p>
<p>So this is also a duplicate declaration:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p98code28'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p9828"><td class="code" id="p98code28"><pre class="actionscript" style="font-family:monospace;">package my <span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> NamespaceExamp <span style="color: #66cc66;">&#123;</span>
&nbsp;
		namespace NS1 = <span style="color: #ff0000;">&quot;&quot;</span>;
&nbsp;
		NS1 <span style="color: #000000; font-weight: bold;">function</span> foo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> foo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://maxblog.bomzhi.de/?feed=rss2&amp;p=98</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>The uselessness of static</title>
		<link>http://maxblog.bomzhi.de/?p=87</link>
		<comments>http://maxblog.bomzhi.de/?p=87#comments</comments>
		<pubDate>Sun, 13 Dec 2009 14:32:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AS3 Creative point of view]]></category>

		<guid isPermaLink="false">http://maxblog.bomzhi.de/?p=87</guid>
		<description><![CDATA[ActionScript 3 has a keyword static that turns methods, fields, getter and setter into class members (not instance members). It is a useful feature in languages as Java, where you have no top level functions and variables (btw. in JavaFX static is deprecated). AS3 has both &#8211; static members and top level functions/variables (as JavaFX), [...]]]></description>
			<content:encoded><![CDATA[<p>ActionScript 3 has a keyword static that turns methods, fields, getter and setter into class members (not instance members).</p>
<p>It is a useful feature in languages as Java, where you have no top level functions and variables (btw. in JavaFX static is deprecated).</p>
<p>AS3 has both &#8211; static members and top level functions/variables (as JavaFX), so it is kind of an overkill in my opinion.</p>
<p>If you want to have a structural aggregation you can put all top level functions/variables in a special package.</p>
<p>For example there is a convention in CoreLibrary for constant carriers (have a look at the &#8220;StageAlign&#8221; class in &#8220;flash.display&#8221; package).</p>
<p>These carriers represent the possible input values for a property of a class. In the case of &#8220;StageAlign&#8221; it is the property &#8220;align&#8221; of the class &#8220;Stage&#8221;. (btw. <a href="http://fdt.powerflasher.de">FDT</a> has a special <a href="http://www.fdt.powerflasher.com/developer-tools/fdt-3/whats-new/auto-completion-for-constant-conventrion/">auto completion</a> for this conventional constant carriers)</p>
<p>It is possible to place all these constants in a package &#8220;flash.display.Stage&#8221; so you don&#8217;t have to write :</p>
<p>&#8220;StageAlign.LEFT&#8221; but just &#8220;ALIGN_LEFT&#8221; for example.</p>
]]></content:encoded>
			<wfw:commentRss>http://maxblog.bomzhi.de/?feed=rss2&amp;p=87</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>You can run and you can hide</title>
		<link>http://maxblog.bomzhi.de/?p=81</link>
		<comments>http://maxblog.bomzhi.de/?p=81#comments</comments>
		<pubDate>Sat, 21 Nov 2009 08:37:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AS3 Creative point of view]]></category>

		<guid isPermaLink="false">http://maxblog.bomzhi.de/?p=81</guid>
		<description><![CDATA[First of all let me introduce you the &#8220;Compilation Unit&#8221;. Compilation unit is the smallest code entity that can be compiled properly (to SWF file). In ActionScript3 those entities are &#8220;as&#8221; or &#8220;mxml&#8221; files. (I skip &#8220;mxml&#8221; because it&#8217;s own topic ) The &#8220;as&#8221; files must be structured as following to become a compilation unit: [...]]]></description>
			<content:encoded><![CDATA[<p>First of all let me introduce you the &#8220;Compilation Unit&#8221;. Compilation unit is the smallest code entity that can be compiled properly (to SWF file).</p>
<p>In ActionScript3 those entities are &#8220;as&#8221; or &#8220;mxml&#8221; files. (I skip &#8220;mxml&#8221; because it&#8217;s own topic )</p>
<p>The &#8220;as&#8221; files must be structured as following to become a compilation unit:</p>
<p style="text-align: left;">&#8211;Package declaration<br />
&#8212; Class | Interface | Function | Variable | Constant | Namespace declaration<br />
&#8212;- (if Interface) Method | Getter | Setter declaration<br />
&#8212;- (if Class) Method | Getter | Setter | Constructor | Field | Constant | Namespace declaration<br />
-Local Class | Interface | Function | Variable | Constant | Namespace declarations</p>
<p>So you need a package declaration with an element inside to make it a compilable entity</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p81code33'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8133"><td class="code" id="p81code33"><pre class="actionscript" style="font-family:monospace;">package <span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">var</span> a;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>And you can hide declarations from anybody when you put them outside of package declaration</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p81code34'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8134"><td class="code" id="p81code34"><pre class="actionscript" style="font-family:monospace;">package <span style="color: #66cc66;">&#123;</span>
  <span style="color: #0066CC;">public</span> const KingOfPop : Michael = <span style="color: #000000; font-weight: bold;">new</span> Michael<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">class</span> Michael<span style="color: #66cc66;">&#123;</span>
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> dance<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #ff0000;">&quot;Moon Walk&quot;</span>;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>By the way this is the one and only good implementation of <a href="http://en.wikipedia.org/wiki/Singleton_pattern">Singleton Pattern</a> in AS3.</p>
<p>But it&#8217;s not what I want to show here. What I want to show is that my first definition of compilation unit was wrong because you can write statements between listed declaration and those will be executed as <a href="http://en.wikipedia.org/wiki/Java_syntax#Static_initializers">static initializer</a> code.</p>
<p>So check this out:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p81code35'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8135"><td class="code" id="p81code35"><pre class="actionscript" style="font-family:monospace;">package<span style="color: #66cc66;">&#123;</span>
  <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;A&quot;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
  <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;B&quot;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #000000; font-weight: bold;">class</span> Test <span style="color: #0066CC;">extends</span> Sprite<span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;C&quot;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Test<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
       <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;D&quot;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;E&quot;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
  <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;F&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;G&quot;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>Can you tell what will be traced? <img src='http://maxblog.bomzhi.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Last but not least conclusion &#8211; with this info in mind you can use AS3 as a &#8220;real&#8221; script language:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p81code36'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8136"><td class="code" id="p81code36"><pre class="actionscript" style="font-family:monospace;">package<span style="color: #66cc66;">&#123;</span> <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>; <span style="color: #000000; font-weight: bold;">class</span> A <span style="color: #0066CC;">extends</span> Sprite<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">var</span> a = <span style="color: #cc66cc;">10</span>;
<span style="color: #000000; font-weight: bold;">var</span> b = <span style="color: #cc66cc;">20</span>;
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;a+b=&quot;</span>+<span style="color: #66cc66;">&#40;</span>a+b<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://maxblog.bomzhi.de/?feed=rss2&amp;p=81</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Share your property</title>
		<link>http://maxblog.bomzhi.de/?p=75</link>
		<comments>http://maxblog.bomzhi.de/?p=75#comments</comments>
		<pubDate>Sat, 14 Nov 2009 14:52:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[AS3 Creative point of view]]></category>

		<guid isPermaLink="false">http://maxblog.bomzhi.de/?p=75</guid>
		<description><![CDATA[Classes in AS3 do have Properties but with some limitations. This code will compile fine: ?View Code ACTIONSCRIPTpackage &#123; public class ClassA &#123; &#160; var _max : String; &#160; public function get max&#40;&#41; : String &#123; return _max; &#125; &#160; private function set max&#40;max : String&#41; : void &#123; _max = max; &#125; &#125; &#125; [...]]]></description>
			<content:encoded><![CDATA[<p>Classes in AS3 do have <a href="http://en.wikipedia.org/wiki/Property_(programming)">Properties</a> but with some limitations. This code will compile fine:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p75code39'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7539"><td class="code" id="p75code39"><pre class="actionscript" style="font-family:monospace;">package <span style="color: #66cc66;">&#123;</span>
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ClassA <span style="color: #66cc66;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">var</span> _max : <span style="color: #0066CC;">String</span>;
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> <span style="color: #0066CC;">max</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#123;</span>
      <span style="color: #b1b100;">return</span> _max;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> <span style="color: #0066CC;">max</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">max</span> : <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
      _max = <span style="color: #0066CC;">max</span>;
    <span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>But this won&#8217;t:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p75code40'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7540"><td class="code" id="p75code40"><pre class="actionscript" style="font-family:monospace;">package <span style="color: #66cc66;">&#123;</span>
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ClassA <span style="color: #66cc66;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">var</span> _max : <span style="color: #0066CC;">String</span>;
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ClassA<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'max: '</span> + <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">max</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> <span style="color: #0066CC;">max</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#123;</span>
      <span style="color: #b1b100;">return</span> _max;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> <span style="color: #0066CC;">max</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">max</span> : <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
      _max = <span style="color: #0066CC;">max</span>;
    <span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Looks like if you mix property visibilities you can&#8217;t refer to it any more.</p>
]]></content:encoded>
			<wfw:commentRss>http://maxblog.bomzhi.de/?feed=rss2&amp;p=75</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
