<?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>Jeff dePascale &#187; events</title>
	<atom:link href="http://www.jeffdepascale.com/index.php/tags/events/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jeffdepascale.com</link>
	<description>Blogging on and developing web and mobile technologies</description>
	<lastBuildDate>Mon, 12 Apr 2010 18:09:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Dispatching custom events between child SWFs in AS3</title>
		<link>http://www.jeffdepascale.com/index.php/flash/dispatching-custom-events-between-child-swfs-in-as3/</link>
		<comments>http://www.jeffdepascale.com/index.php/flash/dispatching-custom-events-between-child-swfs-in-as3/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 19:05:58 +0000</pubDate>
		<dc:creator>Jeff dePascale</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[LoaderContext]]></category>

		<guid isPermaLink="false">http://www.jeffdepascale.com/?p=147</guid>
		<description><![CDATA[I've written about this before, but this time around I have an answer to this one. The issue goes a little something like this: a parent SWF a child SWF, dispatches a custom event another child swf, nested in either the parent or the other child, listens for that custom event. The error you'll receive [...]]]></description>
			<content:encoded><![CDATA[<p>I've written about this before, but this time around I have an answer to this one. The issue goes a little something like this:</p>
<p>a parent SWF</p>
<p>a child SWF, dispatches a custom event</p>
<p>another child swf, nested in either the parent or the other child, listens for that custom event. </p>
<p>The error you'll receive is a type coercion error that looks like a mistake - can't convert [custom event name] to [custom event name]. So what gives? They're the same class, both SWF files have imported the event class correctly, yet they are colliding through the event dispatch. Well, it turns out it is a security violation due to the way in which the SWF was loaded. Change your loader context to new LoaderContext(false, ApplicationDomain.currentDomain) when loading in those child SWFs and suddenly they can talk to each other more openly than before and type checking  correctly returns that all important 'true' - in other words, no coercion error. All of those imported classes match up - <em>and </em>you can even instantiate objects of a type defined in the other child SWF without importing it into your class. To get Flash to export it without referencing it though requires a SWC file for the SWF to reference the classes from (CS4 modified this process a bit with the ability to specify external libs, and Flex has had the same functionality for a while i believe). Colin Moock's Essential Actionscript has a chapter on doing just that, right at the end of the book. If you're interested in that process, he says it better than i ever could.</p>
<p>FYI - the fix mentioned in <a href="http://www.jeffdepascale.com/?p=17">my previous post on the subject</a> is still valid if you can't/don't want to change the application domain for the loader. Adding the reference to the document class of the top level parent SWF still rectifies the issue.</p>



		<!-- Added by WP-DragToShare-eXtended Plugin -->
		<script type="text/javascript">
			dtsv.dtse_post_147_permalink = 'http://www.jeffdepascale.com/index.php/flash/dispatching-custom-events-between-child-swfs-in-as3/';
			dtsv.dtse_post_147_title = 'Dispatching custom events between child SWFs in AS3';
		</script>
		<!-- End of WP-DragToShare-eXtended Plugin -->]]></content:encoded>
			<wfw:commentRss>http://www.jeffdepascale.com/index.php/flash/dispatching-custom-events-between-child-swfs-in-as3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Events in loaded SWF files</title>
		<link>http://www.jeffdepascale.com/index.php/flash/custom-events-in-loaded-swf-files/</link>
		<comments>http://www.jeffdepascale.com/index.php/flash/custom-events-in-loaded-swf-files/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 00:01:33 +0000</pubDate>
		<dc:creator>Jeff dePascale</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[events]]></category>

		<guid isPermaLink="false">http://jeffdepascale.com/news/?p=17</guid>
		<description><![CDATA[Custom events that override the clone method of Event implemented in a loaded SWF file that has listeners in the parent or above will fail with a 1034 coercion error, even though the error seemingly says that the type it is coercing to is the same class type. After much searching I found the answer [...]]]></description>
			<content:encoded><![CDATA[<p>Custom events that override the clone method of Event implemented in a loaded SWF file that has listeners in the parent or above will fail with a 1034 coercion error, even though the error seemingly says that the type it is coercing to is the same class type. After much searching I found the answer i needed - something i've come across before when building fosfr. I'm not entirely clear on why this only affects custom events with clone overriden and not others, but the solution is to import the custom event in the root document class and reference an instance of it, thereby forcing the root displayObject to include the event class in its compile. From that point forward it is accessible throughout the SWF hierarchy. You don't need to create an actual instance of the event, just reference it by name. Example:</p>
<p>package {<br />
import my.custom.CustomEvent;</p>
<p>public class Main extends MovieClip {</p>
<p>CustomEvent;</p>
<p>pubic function Main(){<br />
}<br />
}<br />
}</p>
<p>This is definitely required in Fosfr projects given the aformentioned use case. Note that it doesnt appear to cause issues when not listening down in the display list, like this case specifies. Listening up is fine, dispatching up is not.</p>
<p>Hopefully that'll save some of you the hour it took me to find that answer!</p>



		<!-- Added by WP-DragToShare-eXtended Plugin -->
		<script type="text/javascript">
			dtsv.dtse_post_17_permalink = 'http://www.jeffdepascale.com/index.php/flash/custom-events-in-loaded-swf-files/';
			dtsv.dtse_post_17_title = 'Custom Events in loaded SWF files';
		</script>
		<!-- End of WP-DragToShare-eXtended Plugin -->]]></content:encoded>
			<wfw:commentRss>http://www.jeffdepascale.com/index.php/flash/custom-events-in-loaded-swf-files/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
