<?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>DanDev.com &#187; getType()</title> <atom:link href="http://www.dandev.com/tag/gettype/feed/" rel="self" type="application/rss+xml" /><link>http://www.dandev.com</link> <description>Daniel&#039;s Dev Blog..ish</description> <lastBuildDate>Sat, 28 Jan 2012 18:06:25 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" /> <item><title>Flex: getType() schmettype</title><link>http://www.dandev.com/flex/flex-gettype-schmettype/</link> <comments>http://www.dandev.com/flex/flex-gettype-schmettype/#comments</comments> <pubDate>Sun, 08 Mar 2009 00:31:54 +0000</pubDate> <dc:creator>Daniel</dc:creator> <category><![CDATA[Development]]></category> <category><![CDATA[Flex]]></category> <category><![CDATA[actionscript]]></category> <category><![CDATA[Alert]]></category> <category><![CDATA[as3]]></category> <category><![CDATA[describeType()]]></category> <category><![CDATA[flash]]></category> <category><![CDATA[getType()]]></category> <guid
isPermaLink="false">http://www.dandev.com/?p=112</guid> <description><![CDATA[I&#8217;ve started dabbling in Flex recently, and something that was apparent(and annoying at times) to me  early on was it&#8217;s strongly-typed nature. Not type as in a keyboard, but variable types. Flex cares very much whether your variable is an Array, or ArrayCollection as it&#8217;s knowledge of types is key to it&#8217;s processing. This is [...]]]></description> <content:encoded><![CDATA[<p>I&#8217;ve started dabbling in Flex recently, and something that was apparent(and annoying at times) to me  early on was it&#8217;s strongly-typed nature. Not type as in a keyboard, but variable types. Flex cares very much whether your variable is an Array, or ArrayCollection as it&#8217;s knowledge of types is key to it&#8217;s processing. This is quite the converse to a language like PHP, which is loosely-typed to say the least.</p><p>Anyway, I came upon a case where I needed to know the type a variable was so I could cast it properly(and for debugging), and I found that Flex doesn&#8217;t have a function to simply return a variable&#8217;s type. There is describeType(), but this returns an XML object with all of the information about the variable &#8212; not just the type. Plus you have to import the proper class to use it. So, I threw together this function quickly that will perform the import, and return/alert the type as needed:</p><div
style="background-color: #222"><div
class="wp_syntax"><div
class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> getType<span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">:*,</span> alert<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.utils</span><span style="color: #000066; font-weight: bold;">.*;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">description</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">XML</span> = <span style="color: #004993;">describeType</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>alert<span style="color: #000000;">&#41;</span>
		Alert<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">show</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">description</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>@<span style="color: #004993;">name</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #004993;">description</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>@<span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div></div><p>I hope someone else can find it useful. <img
src='http://www.dandev.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p> ]]></content:encoded> <wfw:commentRss>http://www.dandev.com/flex/flex-gettype-schmettype/feed/</wfw:commentRss> <slash:comments>9</slash:comments> </item> </channel> </rss>
