<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc = "http://purl.org/dc/elements/1.1/" xmlns="http://purl.org/rss/1.0/">
	<channel rdf:about="http://livedocs.adobe.com/">
	<title>LiveDocs Comments - flash - 9.0 - ActionScriptLangRefV3 - operators.html</title>	
		<link>http://livedocs.adobe.com/</link>
		<description>Macromedia LiveDocs - online documentation with user feedback.</description>
		<copyright>Copyright 2009, Macromedia, Inc.</copyright>
		<dc:date>2009-11-26T02:46:48</dc:date>
		<dc:language>en-us</dc:language>
		<items>
			<rdf:Seq>
				<rdf:li rdf:resource="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/operators.html#83744" />
				<rdf:li rdf:resource="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/operators.html#83699" />
				<rdf:li rdf:resource="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/operators.html#75295" />
			</rdf:Seq>
		</items>
	</channel>
	
	<item rdf:about="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/operators.html#83744">
		<title>flash/9.0/ActionScriptLangRefV3/operators.html</title>
		<link>http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/operators.html#83744</link>
		<description>@No nickname: &lt;br&gt;The reason the second and third versions both give true is because the object that's being tested is indeed a Sprite.&lt;br&gt;&lt;br&gt;Obviously it's being cast (using two different techniques) as a DisplayObject instance -- which is just fine, because every Sprite is also a DisplayObject -- but Flash Player still knows that the actual object it's storing in its memory is a Sprite.&lt;br&gt;&lt;br&gt;To carry the point to an extreme case, consider this code:&lt;br&gt;&lt;br&gt;var s:Sprite = new Sprite();&lt;br&gt;var a:Array = [s];&lt;br&gt;trace(&quot;a[0] is Sprite&quot;, a[0] is Sprite); // true&lt;br&gt;&lt;br&gt;In this case, the third line will also trace &quot;true&quot;, even though a[0] could theoretically be any type of object (the &quot;return type&quot; of the square bracket operator is Object). So in that line of code the player reads a[0], which at compile time it only knows is an Object. (Basically the add-to-array remove-from-array dance is a fancy way to cast s as an Object.) At run time the player looks at the actual object in memory to find out if it's a Sprite instance.&lt;br&gt;&lt;br&gt;I guess the point I'm trying to make is that type casting is in some sense a compile time mechanism only (especially in your third line -- in that case it is literally a compile time mechanism only). In those examples, there's really no point to doing the type cast in the second and third lines. It doesn't fundamentally change the nature of the object. Upcasting to a superclass (as you're doing here) doesn't make the subclass functionality somehow disappear. The only reason for casting is when you're retrieving something in a context where you can't guarantee the data type of an object at compile time (such as when you're retrieving the object from an array). So you cast to make the compiler happy. The reason my example works even without casting is because Object is a dynamic class -- so the compiler doesn't do *any* compile-time type checking of Object instances, and leaves all the type checking to run time.&lt;br&gt;&lt;br&gt;This aspect of type checking is one of the things that makes ActionScript flexible and more &quot;scripting&quot; language-like. A while ago I wrote an article that goes into more detail about data types in ActionScript at compile time and runtime. Maybe you'll find it useful: &lt;br&gt;&lt;a href=&quot;http://probertson.com/articles/2005/11/08/actionscript-3-unit-testing-recommended/&quot;&gt;http://probertson.com/articles/2005/11/08/actionscript-3-unit-testing-recommended/&lt;/a&gt;</description>
		<dc:creator>adbe_paul</dc:creator>
		<dc:type>1 0</dc:type>
		<dc:date>2008-05-06T13:35:54</dc:date>
	</item>
	<item rdf:about="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/operators.html#83699">
		<title>flash/9.0/ActionScriptLangRefV3/operators.html</title>
		<link>http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/operators.html#83699</link>
		<description>Hi. Why does the following lines return true, all three of them?&lt;br /&gt;&lt;br /&gt;var a:Sprite = new Sprite();&lt;br /&gt;trace(a is Sprite, &quot; = a is Sprite&quot;);&lt;br /&gt;trace((a as DisplayObject) is Sprite, &quot; = (a as DisplayObject) is Sprite&quot;);&lt;br /&gt;trace(DisplayObject(a) is Sprite, &quot; = DisplayObject(a) is Sprite&quot;);&lt;br /&gt;&lt;br /&gt;I understand the first returning true, I could even understand the second (strictly from the documentation it's ok to return true, but I think the &quot;as&quot; word is misleading), but I definitely don't understand why the third one is true.&lt;br /&gt;&lt;br /&gt;Could some one explain me the exact semantics of those thing?&lt;br /&gt;&lt;br /&gt;Thanks,&lt;br /&gt;FaQ</description>
		<dc:creator></dc:creator>
		<dc:type>0 0</dc:type>
		<dc:date>2008-05-05T06:08:36</dc:date>
	</item>
	<item rdf:about="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/operators.html#75295">
		<title>flash/9.0/ActionScriptLangRefV3/operators.html</title>
		<link>http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/operators.html#75295</link>
		<description>You are correct. The description should emphasize the affect of the conversion a bit more strongly. Note that you can convert the result back to 16bit by bitwise ANDing (&amp;) the NOR result with 0x0000ffff.</description>
		<dc:creator>Joe ... Ward</dc:creator>
		<dc:type>1 0</dc:type>
		<dc:date>2007-10-19T12:46:03</dc:date>
	</item>
	</rdf:RDF>

