<?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>nothing yet &#124; jason madsen &#187; Flash Components</title>
	<atom:link href="http://knomedia.com/blog/tag/flash-components/feed/" rel="self" type="application/rss+xml" />
	<link>http://knomedia.com/blog</link>
	<description>Web &#124; Mobile &#124; Desktop Development</description>
	<lastBuildDate>Thu, 22 Dec 2011 16:02:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>UIMovieClip Custom Events</title>
		<link>http://knomedia.com/blog/2008/07/25/uimovieclip-custom-events/</link>
		<comments>http://knomedia.com/blog/2008/07/25/uimovieclip-custom-events/#comments</comments>
		<pubDate>Fri, 25 Jul 2008 18:32:10 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash Components]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://knomedia.com/blog/?p=14</guid>
		<description><![CDATA[I&#8217;ve been using the Flex Integration Kit to create my own custom components in Flash for use in Flex lately. Coming from an all ActionScript (not necessarily MXML) background there are a few things to watch for. One of them being Custom Events in your newly created component. In order for Flex to recognize your [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using the <a href="http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&amp;loc=en_us&amp;extid=1273018">Flex Integration Kit</a> to create my own custom components in Flash for use in Flex lately.  Coming from an all ActionScript (not necessarily MXML) background there are a few things to watch for.  One of them being Custom Events in your newly created component.</p>
<p>In order for Flex to recognize your Custom Event you need to include the event meta data in your AS Class file.  For example, in an AS setting your class could fire off an event like so:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> updateHandler<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">var</span> evt:MyEvent = <span style="color: #000000; font-weight: bold;">new</span> MyEvent<span style="color: #66cc66;">&#40;</span>MyEvent.<span style="color: #006600;">VOLUME</span><span style="color: #66cc66;">&#41;</span>;
    evt.<span style="color: #006600;">volume</span> =<span style="color: #808080; font-style: italic;">//some volume value;</span>
    <span style="color: #0066CC;">this</span>.<span style="color: #006600;">dispatchEvent</span><span style="color: #66cc66;">&#40;</span>evt<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>In an all ActionScript setting this works fine.  However when you compile this UIMovieClip into a swc file and use it in a Flex Project, Flex has no way to recognize the MyEvent.VOLUME.  In the Flex Editor it won&#8217;t appear as a code hint.  If you manually force it into the MXML, you&#8217;ll get an error.  In order to allow Flex to know of the event you will need to include some Event meta data at the top of your ActionScript Class.   For example:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&#91;</span>Event <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;volume&quot;</span>, <span style="color: #0066CC;">type</span>=<span style="color: #ff0000;">&quot;com.knomedia.events.MyEvent&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> VolumeControl <span style="color: #0066CC;">extends</span> UIMovieClip
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #808080; font-style: italic;">//Class members here</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>
The meta data needs the &#8216;name&#8217; of the Event.  This is the string literal that the event constant holds.  In this case MyEvent.VOLUME holds the value &#8220;volume&#8221;.  The type attribute is the fully qualified name of your Custom Event Class.  The placement of the meta data is important, it needs to be on the line above your class declaration.  Once you have that in place you can compile your swc.</p>
<p>My only beef with the technique is that you need to use the actual string literal.  I understand the need (for ease of use in MXML), but I am more comfortable using class constants of the Event Class&#8230; Anyway.</p>
<p>In MXML you can now set the volume attribute to listen for the event to fire:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;swc:VolumeControl</span> id=<span style="color: #ff0000;">&quot;vol&quot;</span> volume=<span style="color: #ff0000;">&quot;{volumeHandler(event);}&quot;</span> <span style="color: #7400FF;">/&gt;</span></span></pre></div></div>

<p>The switch from all ActionScript to MXML is pretty painless.  Occasionally a small issue like this will make you feel stupid, but overall it isn&#8217;t a big jump.</p>
<p>Jason</p>
]]></content:encoded>
			<wfw:commentRss>http://knomedia.com/blog/2008/07/25/uimovieclip-custom-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

