<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Type Conversions: Coercion vs. Casting</title>
	<atom:link href="http://knowledge.lapasa.net/2006/07/17/type-conversions-coercion-vs-casting/feed/" rel="self" type="application/rss+xml" />
	<link>http://knowledge.lapasa.net/2006/07/17/type-conversions-coercion-vs-casting/</link>
	<description>Greater Toronto Area Flex 2 and ActionScript 3 Developer Blog</description>
	<pubDate>Wed, 07 Jan 2009 07:49:48 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: mlapasa</title>
		<link>http://knowledge.lapasa.net/2006/07/17/type-conversions-coercion-vs-casting/#comment-5068</link>
		<dc:creator>mlapasa</dc:creator>
		<pubDate>Sun, 04 May 2008 23:16:40 +0000</pubDate>
		<guid isPermaLink="false">http://knowledge.lapasa.net/?p=25#comment-5068</guid>
		<description>Interesting. I think AS3 back in July 2006 was still in Flex 2 Beta. So when I tested back then, it had worked. Thx for the update.</description>
		<content:encoded><![CDATA[<p>Interesting. I think AS3 back in July 2006 was still in Flex 2 Beta. So when I tested back then, it had worked. Thx for the update.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: argo</title>
		<link>http://knowledge.lapasa.net/2006/07/17/type-conversions-coercion-vs-casting/#comment-5063</link>
		<dc:creator>argo</dc:creator>
		<pubDate>Tue, 08 Apr 2008 06:45:03 +0000</pubDate>
		<guid isPermaLink="false">http://knowledge.lapasa.net/?p=25#comment-5063</guid>
		<description>Hi, I know this entry is from 2006, so maybe then the 'as' operator in AS3 acted a bit different. But I wanted to leave this comment, as the 'as' thingie just confused the hell out of me (I'm new at as3 though I know as2 really well).

I was trying to figure out why using 'myVar as Number' always returned 0. I was trying the 'as' operator, as it's something new for as3, and I saw it in a forum, just like you mentioned, that it could be used to cast an expression to another type or class. But it looks like that explanation is wrong. 'as' is used to compare whether an expression is of type 'type' (in your example 'Number'). At least that's what it says in the as3 help files:

[as]
Evaluates whether an expression specified by the first operand is a member of the data type specified by the second operand. If the first operand is a member of the data type, the result is the first operand. Otherwise, the result is the value null. 

--
However, it is interesting to see that even the docs are kind of wrong, as in your example, the trace outputs 0, not null. But if you do the following:  trace(zipCode as Number) it outputs null.

So, it looks like if you assign the whole expression to a var of type Number, the result is 0 instead of null. Kind of interesting, but damn awful.

I guess it does that because var num:Number can't be null. var num:Number=null returns a compiler error.</description>
		<content:encoded><![CDATA[<p>Hi, I know this entry is from 2006, so maybe then the &#8216;as&#8217; operator in AS3 acted a bit different. But I wanted to leave this comment, as the &#8216;as&#8217; thingie just confused the hell out of me (I&#8217;m new at as3 though I know as2 really well).</p>
<p>I was trying to figure out why using &#8216;myVar as Number&#8217; always returned 0. I was trying the &#8216;as&#8217; operator, as it&#8217;s something new for as3, and I saw it in a forum, just like you mentioned, that it could be used to cast an expression to another type or class. But it looks like that explanation is wrong. &#8216;as&#8217; is used to compare whether an expression is of type &#8216;type&#8217; (in your example &#8216;Number&#8217;). At least that&#8217;s what it says in the as3 help files:</p>
<p>[as]<br />
Evaluates whether an expression specified by the first operand is a member of the data type specified by the second operand. If the first operand is a member of the data type, the result is the first operand. Otherwise, the result is the value null. </p>
<p>&#8211;<br />
However, it is interesting to see that even the docs are kind of wrong, as in your example, the trace outputs 0, not null. But if you do the following:  trace(zipCode as Number) it outputs null.</p>
<p>So, it looks like if you assign the whole expression to a var of type Number, the result is 0 instead of null. Kind of interesting, but damn awful.</p>
<p>I guess it does that because var num:Number can&#8217;t be null. var num:Number=null returns a compiler error.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
