<?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>nightdrops.com &#187; classes</title>
	<atom:link href="http://www.nightdrops.com/tag/classes/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nightdrops.com</link>
	<description>like the color blue</description>
	<lastBuildDate>Thu, 01 Jul 2010 13:19:03 +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>Sealed and dynamic  classes</title>
		<link>http://www.nightdrops.com/2009/sealed-and-dynamic-classes/</link>
		<comments>http://www.nightdrops.com/2009/sealed-and-dynamic-classes/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 11:07:48 +0000</pubDate>
		<dc:creator>kajyr</dc:creator>
				<category><![CDATA[Blog posts]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.nightdrops.com/?p=284</guid>
		<description><![CDATA[Back in the days of actionscript 2, you could add any property to pretty much any object, just calling it and setting a value, like this: &#160;myMovieClip.thePropertyILikeWithAStrangeName = &#34;some string&#34; Actionscript 3.0 instead, being a more serious language, defines the basic class as sealed. That means that you can&#8217;t add any property on a object. [...]]]></description>
			<content:encoded><![CDATA[<p>Back in the days of actionscript 2, you could add any property to pretty much any object, just calling it and setting a value, like this:</p>
<p><code class="codecolorer actionscript default"><span class="actionscript">&nbsp;myMovieClip.<span style="color: #006600;">thePropertyILikeWithAStrangeName</span> = <span style="color: #ff0000;">&quot;some string&quot;</span></span></code></p>
<p>Actionscript 3.0 instead, being a more serious language, defines the basic class as sealed. That means that you can&#8217;t add any property on a object. You have to extends that class, and adding public properties.</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyClass <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span> <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #0066CC;">public</span> thePropertyILikeWithAStrangeName:<span style="color: #0066CC;">String</span><br />
<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><br />
<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>That class is sealed. You can&#8217;t</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> foo:MyClass = <span style="color: #000000; font-weight: bold;">new</span> MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
foo.<span style="color: #006600;">anotherProperty</span> = <span style="color: #cc66cc;">42</span>;</div></div>
<p>The <code class="codecolorer actionscript default"><span class="actionscript"><span style="color: #0066CC;">dynamic</span></span></code> keyword, permits to &#8216;unseal&#8217; a class, giving back the possibility to add any property on runtime.</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">public</span> <span style="color: #0066CC;">dynamic</span> <span style="color: #000000; font-weight: bold;">class</span> MyClass <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span> <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #0066CC;">public</span> thePropertyILikeWithAStrangeName:<span style="color: #0066CC;">String</span><br />
<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><br />
<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>Now you can:</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> foo:MyClass = <span style="color: #000000; font-weight: bold;">new</span> MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
foo.<span style="color: #006600;">anotherProperty</span> = <span style="color: #cc66cc;">42</span>;</div></div>
<p>There are speed and cleaness drawbacks on using dynamic classes. The rule is that if you use it, you should be able to seriously motivate it.</p>
<p>Note that there are few dynamic classes in the default Actionscript framework; the most known is of course, <code class="codecolorer actionscript default"><span class="actionscript"><span style="color: #0066CC;">Object</span></span></code> .</p>
<p>Read more:<br />
<a href="http://livedocs.adobe.com/flash/9.0_it/ActionScriptLangRefV3/statements.html#dynamic" target="_blank">livedocs</a><br />
<a href="http://flexmusings.wordpress.com/2008/06/23/actionscript-3-dynamic-classes/" target="_blank">ActionScript 3: Dynamic Classes</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nightdrops.com/2009/sealed-and-dynamic-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
