<?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>Flassari.is &#187; casting</title>
	<atom:link href="http://flassari.is/tag/casting/feed/" rel="self" type="application/rss+xml" />
	<link>http://flassari.is</link>
	<description></description>
	<lastBuildDate>Fri, 13 Apr 2012 11:51:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>AS3 &#8220;with&#8221; keyword and casting</title>
		<link>http://flassari.is/2010/07/as3-with-keyword-and-casting/</link>
		<comments>http://flassari.is/2010/07/as3-with-keyword-and-casting/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 13:40:40 +0000</pubDate>
		<dc:creator>Flassari</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[as]]></category>
		<category><![CDATA[cast]]></category>
		<category><![CDATA[casting]]></category>
		<category><![CDATA[keyword]]></category>
		<category><![CDATA[with]]></category>

		<guid isPermaLink="false">http://flassari.is/?p=321</guid>
		<description><![CDATA[I&#8217;ve rarely (if ever) used the &#8220;with&#8221; keyword in as3, but I recently found a neat trick to use it with. When I quickly need to cast an object to access a few methods/properties I don&#8217;t always want to create a new casted variable: var child:DisplayObject = getChildThatMightBeMovieClip(); if (child is MovieClip) { var childAsMc:MovieClip [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve rarely (if ever) used the <a href="http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/statements.html#with">&#8220;with&#8221; keyword</a> in as3, but I recently found a neat trick to use it with.</p>
<p>When I quickly need to cast an object to access a few methods/properties I don&#8217;t always want to<br />
create a new casted variable:</p>
<pre class="brush: as3">var child:DisplayObject = getChildThatMightBeMovieClip();

if (child is MovieClip) {
	var childAsMc:MovieClip = child as MovieClip;
	trace(childAsMc.numChildren);
	trace(childAsMc.currentFrame);
}</pre>
<p>or cast it every single time:</p>
<pre class="brush: as3">var child:DisplayObject = getChildThatMightBeMovieClip();

if (child is MovieClip) {
	trace((child as MovieClip).numChildren);
	trace((child as MovieClip).currentFrame);
}</pre>
<p>Using the &#8220;with&#8221; keyword, we can temporarily cast it without creating a temporary casted variable or casting it again and again:</p>
<pre class="brush: as3">var child:DisplayObject = getChildThatMightBeMovieClip();

if (child is MovieClip) {
	with (child as MovieClip) {
		trace(numChildren);
		trace(currentFrame);
	}
}</pre>
<p>Elegant =)</p>
]]></content:encoded>
			<wfw:commentRss>http://flassari.is/2010/07/as3-with-keyword-and-casting/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

