<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
	>
<channel>
	<title>Comments on: ActionScript 3.0 Easy and Practical Decorator Design Pattern</title>
	<atom:link href="http://www.as3dp.com/2009/04/26/actionscript-30-easy-and-practical-decorator-design-pattern/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.as3dp.com/2009/04/26/actionscript-30-easy-and-practical-decorator-design-pattern/</link>
	<description>OOP Techniques for Flash and Flex Developers</description>
	<lastBuildDate>Sat, 28 Aug 2010 21:46:42 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: William B. Sanders</title>
		<link>http://www.as3dp.com/2009/04/26/actionscript-30-easy-and-practical-decorator-design-pattern/comment-page-1/#comment-4491</link>
		<dc:creator>William B. Sanders</dc:creator>
		<pubDate>Sun, 23 May 2010 19:27:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=886#comment-4491</guid>
		<description>Hi Herman,

One of the key principles of design patterns is loose coupling. The idea behind the Decorator is to vary the responsibilities without subclassing. In that way, you&#039;re able to maintain a loosely coupled relationship that can be used when you need to change or re-use the  classes. The class design for the Decorator is very odd because you have a double inheritance; both to abstract classes! However, you want to separate (and vary) the decoration or the component without interfering with the other.

You might want to take a look at this &lt;a href=&quot;http://www.php5dp.com/php-decorator-design-pattern-accessorizing-your-classes/&quot;  rel=&quot;nofollow&quot;&gt;PHP example of a Decorator&lt;/a&gt; to give you another angle on it. Also,  &lt;a href=&quot;http://oreilly.com/catalog/hfdesignpat/chapter/ch03.pdf&quot;  rel=&quot;nofollow&quot;&gt;see this Decorator chapter&lt;/a&gt; from the Freeman&#039;s book available free.

Kindest regards,
Bill</description>
		<content:encoded><![CDATA[<p>Hi Herman,</p>
<p>One of the key principles of design patterns is loose coupling. The idea behind the Decorator is to vary the responsibilities without subclassing. In that way, you&#8217;re able to maintain a loosely coupled relationship that can be used when you need to change or re-use the  classes. The class design for the Decorator is very odd because you have a double inheritance; both to abstract classes! However, you want to separate (and vary) the decoration or the component without interfering with the other.</p>
<p>You might want to take a look at this <a href="http://www.php5dp.com/php-decorator-design-pattern-accessorizing-your-classes/"  rel="nofollow">PHP example of a Decorator</a> to give you another angle on it. Also,  <a href="http://oreilly.com/catalog/hfdesignpat/chapter/ch03.pdf"  rel="nofollow">see this Decorator chapter</a> from the Freeman&#8217;s book available free.</p>
<p>Kindest regards,<br />
Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Herman Taniwan</title>
		<link>http://www.as3dp.com/2009/04/26/actionscript-30-easy-and-practical-decorator-design-pattern/comment-page-1/#comment-4490</link>
		<dc:creator>Herman Taniwan</dc:creator>
		<pubDate>Sun, 23 May 2010 15:03:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=886#comment-4490</guid>
		<description>Hi, I wanna ask about concreteDecorator A and concreteDecorator B. As we know both of them were inherited from Decorator class, but why can i just inherit them from component class just like this -

&lt;strong&gt;&lt;code&gt;public class ConcreteDecoratorA extends Component&lt;/code&gt;&lt;/strong&gt;

is there any specific reasons for this or it is just the structure convention ?

Thanks in advance :D</description>
		<content:encoded><![CDATA[<p>Hi, I wanna ask about concreteDecorator A and concreteDecorator B. As we know both of them were inherited from Decorator class, but why can i just inherit them from component class just like this -</p>
<p><strong><code>public class ConcreteDecoratorA extends Component</code></strong></p>
<p>is there any specific reasons for this or it is just the structure convention ?</p>
<p>Thanks in advance :D</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William B. Sanders</title>
		<link>http://www.as3dp.com/2009/04/26/actionscript-30-easy-and-practical-decorator-design-pattern/comment-page-1/#comment-4251</link>
		<dc:creator>William B. Sanders</dc:creator>
		<pubDate>Thu, 22 Apr 2010 13:30:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=886#comment-4251</guid>
		<description>Hi William,

The request for a decoration is through the Client. The component is wrapped in your decorator, and so you could put some kind of counter variable in your request for a decoration. Not very elegant, but off the top of my head:
&lt;pre lang=&quot;actionscript&quot;&gt;
&lt;snip&gt;
var componentA:Component = new ConcreteComponent();
var decorate1:Decorator = new ConcreteDecorator(componentA);
counter_cA_d1++;
decorate1 = new ConcreteDecorator(componentA);
counter_cA_d1++;
&lt;/snip&gt;
&lt;/pre&gt;

Quick and dirty for testing, but it&#039;s easy to clean up. If you need the information in your program for it to perform correctly, think of adding a helper class whose job it is to keep track of decorations and components decorated.

Elogios,
Bill</description>
		<content:encoded><![CDATA[<p>Hi William,</p>
<p>The request for a decoration is through the Client. The component is wrapped in your decorator, and so you could put some kind of counter variable in your request for a decoration. Not very elegant, but off the top of my head:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p886code1'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8861"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p886code1"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>snip<span style="color: #66cc66;">&gt;</span>
<span style="color: #000000; font-weight: bold;">var</span> componentA:Component = <span style="color: #000000; font-weight: bold;">new</span> ConcreteComponent<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> decorate1:Decorator = <span style="color: #000000; font-weight: bold;">new</span> ConcreteDecorator<span style="color: #66cc66;">&#40;</span>componentA<span style="color: #66cc66;">&#41;</span>;
counter_cA_d1++;
decorate1 = <span style="color: #000000; font-weight: bold;">new</span> ConcreteDecorator<span style="color: #66cc66;">&#40;</span>componentA<span style="color: #66cc66;">&#41;</span>;
counter_cA_d1++;
<span style="color: #66cc66;">&lt;/</span>snip<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Quick and dirty for testing, but it&#8217;s easy to clean up. If you need the information in your program for it to perform correctly, think of adding a helper class whose job it is to keep track of decorations and components decorated.</p>
<p>Elogios,<br />
Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William R. J. Ribeiro</title>
		<link>http://www.as3dp.com/2009/04/26/actionscript-30-easy-and-practical-decorator-design-pattern/comment-page-1/#comment-4249</link>
		<dc:creator>William R. J. Ribeiro</dc:creator>
		<pubDate>Thu, 22 Apr 2010 09:18:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=886#comment-4249</guid>
		<description>Hi Bill!

I was implementing the Decorator pattern in one of my Flex projects when I bounced in something that I don&#039;t know how to solve in a flexible elegant way.

At some point, I wanted to find out how many and which Decorators where &quot;decorating&quot; my Component. I tried to check the runtime instance of the Decorator (something like &#039;instanceof&#039; operator) but it only returns true for the last instantiated Decorator.

The partial solution I found was something like this:
&lt;pre lang=&quot;actionscript&quot;&gt;
//Decorator
//Abstract class: Do not instantiate
package 
{
	public class Decorator extends Component
	{
		protected var block:Component;
                // we just save a reference to all Decorators
                protected var decoratorsInUse:ArrayCollection = new ArrayCollection();
	}
}

//Concrete Decorator
package 
{
	import flash.display.Shape;
 
	public class ConcreteDecorator1 extends Decorator
	{
 
		public function ConcreteDecorator1(block:Component)
		{
			this.block = block;
                        // Add this in every concrete Decorator
                        this.decoratorsInUse.add(this);
		}
        }
}
&lt;/pre&gt;
Okay, now the problem is, AS3 doesn&#039;t have Generics nor Reflection (Java 1.5 advanced functionalities) so I don&#039;t know how to get a specific Decorator instance from the Decorators list. The solution I found was really bad and not flexible. 

Anyone have any suggestions on how to do it?

Thanks!

Cheers!</description>
		<content:encoded><![CDATA[<p>Hi Bill!</p>
<p>I was implementing the Decorator pattern in one of my Flex projects when I bounced in something that I don&#8217;t know how to solve in a flexible elegant way.</p>
<p>At some point, I wanted to find out how many and which Decorators where &#8220;decorating&#8221; my Component. I tried to check the runtime instance of the Decorator (something like &#8216;instanceof&#8217; operator) but it only returns true for the last instantiated Decorator.</p>
<p>The partial solution I found was something like this:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p886code2'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8862"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code" id="p886code2"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//Decorator</span>
<span style="color: #808080; font-style: italic;">//Abstract class: Do not instantiate</span>
package 
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Decorator <span style="color: #0066CC;">extends</span> Component
	<span style="color: #66cc66;">&#123;</span>
		protected <span style="color: #000000; font-weight: bold;">var</span> block:Component;
                <span style="color: #808080; font-style: italic;">// we just save a reference to all Decorators</span>
                protected <span style="color: #000000; font-weight: bold;">var</span> decoratorsInUse:ArrayCollection = <span style="color: #000000; font-weight: bold;">new</span> ArrayCollection<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">//Concrete Decorator</span>
package 
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Shape</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ConcreteDecorator1 <span style="color: #0066CC;">extends</span> Decorator
	<span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ConcreteDecorator1<span style="color: #66cc66;">&#40;</span>block:Component<span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">block</span> = block;
                        <span style="color: #808080; font-style: italic;">// Add this in every concrete Decorator</span>
                        <span style="color: #0066CC;">this</span>.<span style="color: #006600;">decoratorsInUse</span>.<span style="color: #0066CC;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
        <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Okay, now the problem is, AS3 doesn&#8217;t have Generics nor Reflection (Java 1.5 advanced functionalities) so I don&#8217;t know how to get a specific Decorator instance from the Decorators list. The solution I found was really bad and not flexible. </p>
<p>Anyone have any suggestions on how to do it?</p>
<p>Thanks!</p>
<p>Cheers!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Curro</title>
		<link>http://www.as3dp.com/2009/04/26/actionscript-30-easy-and-practical-decorator-design-pattern/comment-page-1/#comment-3828</link>
		<dc:creator>Curro</dc:creator>
		<pubDate>Wed, 13 Jan 2010 23:03:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=886#comment-3828</guid>
		<description>Hi again,

I&#039;ve seen I posted the DragForm class twice instead of the client class:
Here it goes:



package 
{
	import flash.display.*;
	import flash.net.URLRequest;
	import flash.media.Sound;
	import flash.events.MouseEvent;
	import flash.events.IOErrorEvent;
	public class Client extends Sprite
	{
		private var aTargets:Array = [];
		private var aDrags:Array = [];


		public function Client()
		{
			var tgt1 = new tg();// a movie clip associated with the Target class
			tgt1.x = 100;
			tgt1.y = 150;
			addChild(tgt1)
			aTargets.push(tgt1);
			
			var drag1 = new DragTextQuestion();// DragTextQuestion is a concrete component
			drag1.setUp(&quot;nice&quot;, tgt1, new LooseCheck);// We need a word, a target and a check strategy

			
			/******** This is what makes it function properly ****
			if I place this code after the decorations things go wrong *****/
			drag1.x = drag1.origX = 300;
			drag1.y = drag1.origY =  150;
			/*******/
			
			// preparing for the sound decorator
			
			var sound = new Sound(new URLRequest(&quot;audio/nice.mp3&quot;));
			drag1 = new DrgQSoundDecorator(drag1);
			drag1.setSound(sound);
			
			// second decoration (filters)
			drag1 = new DrgQFilterDecorator(drag1);
			
			// launch question
			drag1.addEventListener(MouseEvent.MOUSE_DOWN, drag1.dragMovie);
			drag1.addEventListener(MouseEvent.MOUSE_UP, drag1.dropMovie);
			
			//get the drag into an array for later adding to stage and checking
			aDrags.push(drag1);



			// Second drag object will have a different checking strategy
			
			var tgt2 = new tg();// a movie clip associated with the Target class
			tgt2.x = 100;
			tgt2.y = 250;
			
			aTargets.push(tgt2);
			
			var drag2 = new DragTextQuestion();// DragTextQuestion is a concrete component
			drag2.setUp(&quot;horrible&quot;, tgt2, new TightCheck);// We need a word, a target and a check strategy
		
			
			drag2.x = drag2.origX = 300;
			drag2.y = drag2.origY = 250;
			
			
			// preparing for the sound decorator
			var sound2 = new Sound(new URLRequest(&quot;audio/horrible.mp3&quot;));
			drag2 = new DrgQSoundDecorator(drag2);
			drag2.setSound(sound2);
			
			// second decoration (filters)
			drag2 = new DrgQFilterDecorator(drag2);
			
			
					
			// launch question
			drag2.addEventListener(MouseEvent.MOUSE_DOWN, drag2.dragMovie);
			drag2.addEventListener(MouseEvent.MOUSE_UP, drag2.dropMovie);
			
			//get the drag into an array for later checking
			aDrags.push(drag2);
			
			// Add targets to stage
			
			
			
			// set up for checking
			checkButton.addEventListener(MouseEvent.CLICK, checkH);
			
			placeTargets();
			placeDrags();
		}
		

		function checkH(e:MouseEvent)
		{
			for (var i = 0; i &lt; aDrags.length; i++)
			{
				if (aDrags[i].correct == false)
				{
					aDrags[i] = new DrgQWrongDecorator(aDrags[i]);
					addChild(aDrags[i]);
				}
				else
				{
					aDrags[i] = new DrgQCorrectDecorator(aDrags[i]);
					addChild(aDrags[i]);
				}

			}
		}
		
		private function placeTargets()
		{
			for (var i = 0; i &lt; aTargets.length; i++)
			{
				addChild(aTargets[i]);
			}
		}
		private function placeDrags()
		{
			for (var i = 0; i &lt; aDrags.length; i++)
			{
				addChild(aDrags[i]);
			}
		}

	}
}
</description>
		<content:encoded><![CDATA[<p>Hi again,</p>
<p>I&#8217;ve seen I posted the DragForm class twice instead of the client class:<br />
Here it goes:</p>
<p>package<br />
{<br />
	import flash.display.*;<br />
	import flash.net.URLRequest;<br />
	import flash.media.Sound;<br />
	import flash.events.MouseEvent;<br />
	import flash.events.IOErrorEvent;<br />
	public class Client extends Sprite<br />
	{<br />
		private var aTargets:Array = [];<br />
		private var aDrags:Array = [];</p>
<p>		public function Client()<br />
		{<br />
			var tgt1 = new tg();// a movie clip associated with the Target class<br />
			tgt1.x = 100;<br />
			tgt1.y = 150;<br />
			addChild(tgt1)<br />
			aTargets.push(tgt1);</p>
<p>			var drag1 = new DragTextQuestion();// DragTextQuestion is a concrete component<br />
			drag1.setUp(&#8221;nice&#8221;, tgt1, new LooseCheck);// We need a word, a target and a check strategy</p>
<p>			/******** This is what makes it function properly ****<br />
			if I place this code after the decorations things go wrong *****/<br />
			drag1.x = drag1.origX = 300;<br />
			drag1.y = drag1.origY =  150;<br />
			/*******/</p>
<p>			// preparing for the sound decorator</p>
<p>			var sound = new Sound(new URLRequest(&#8221;audio/nice.mp3&#8243;));<br />
			drag1 = new DrgQSoundDecorator(drag1);<br />
			drag1.setSound(sound);</p>
<p>			// second decoration (filters)<br />
			drag1 = new DrgQFilterDecorator(drag1);</p>
<p>			// launch question<br />
			drag1.addEventListener(MouseEvent.MOUSE_DOWN, drag1.dragMovie);<br />
			drag1.addEventListener(MouseEvent.MOUSE_UP, drag1.dropMovie);</p>
<p>			//get the drag into an array for later adding to stage and checking<br />
			aDrags.push(drag1);</p>
<p>			// Second drag object will have a different checking strategy</p>
<p>			var tgt2 = new tg();// a movie clip associated with the Target class<br />
			tgt2.x = 100;<br />
			tgt2.y = 250;</p>
<p>			aTargets.push(tgt2);</p>
<p>			var drag2 = new DragTextQuestion();// DragTextQuestion is a concrete component<br />
			drag2.setUp(&#8221;horrible&#8221;, tgt2, new TightCheck);// We need a word, a target and a check strategy</p>
<p>			drag2.x = drag2.origX = 300;<br />
			drag2.y = drag2.origY = 250;</p>
<p>			// preparing for the sound decorator<br />
			var sound2 = new Sound(new URLRequest(&#8221;audio/horrible.mp3&#8243;));<br />
			drag2 = new DrgQSoundDecorator(drag2);<br />
			drag2.setSound(sound2);</p>
<p>			// second decoration (filters)<br />
			drag2 = new DrgQFilterDecorator(drag2);</p>
<p>			// launch question<br />
			drag2.addEventListener(MouseEvent.MOUSE_DOWN, drag2.dragMovie);<br />
			drag2.addEventListener(MouseEvent.MOUSE_UP, drag2.dropMovie);</p>
<p>			//get the drag into an array for later checking<br />
			aDrags.push(drag2);</p>
<p>			// Add targets to stage</p>
<p>			// set up for checking<br />
			checkButton.addEventListener(MouseEvent.CLICK, checkH);</p>
<p>			placeTargets();<br />
			placeDrags();<br />
		}</p>
<p>		function checkH(e:MouseEvent)<br />
		{<br />
			for (var i = 0; i &lt; aDrags.length; i++)<br />
			{<br />
				if (aDrags[i].correct == false)<br />
				{<br />
					aDrags[i] = new DrgQWrongDecorator(aDrags[i]);<br />
					addChild(aDrags[i]);<br />
				}<br />
				else<br />
				{<br />
					aDrags[i] = new DrgQCorrectDecorator(aDrags[i]);<br />
					addChild(aDrags[i]);<br />
				}</p>
<p>			}<br />
		}</p>
<p>		private function placeTargets()<br />
		{<br />
			for (var i = 0; i &lt; aTargets.length; i++)<br />
			{<br />
				addChild(aTargets[i]);<br />
			}<br />
		}<br />
		private function placeDrags()<br />
		{<br />
			for (var i = 0; i &lt; aDrags.length; i++)<br />
			{<br />
				addChild(aDrags[i]);<br />
			}<br />
		}</p>
<p>	}<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Curro</title>
		<link>http://www.as3dp.com/2009/04/26/actionscript-30-easy-and-practical-decorator-design-pattern/comment-page-1/#comment-3827</link>
		<dc:creator>Curro</dc:creator>
		<pubDate>Wed, 13 Jan 2010 22:20:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=886#comment-3827</guid>
		<description>I forgot; you will also need a button named &quot;checkButton&quot; on the fla.</description>
		<content:encoded><![CDATA[<p>I forgot; you will also need a button named &#8220;checkButton&#8221; on the fla.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Curro</title>
		<link>http://www.as3dp.com/2009/04/26/actionscript-30-easy-and-practical-decorator-design-pattern/comment-page-1/#comment-3826</link>
		<dc:creator>Curro</dc:creator>
		<pubDate>Wed, 13 Jan 2010 22:17:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=886#comment-3826</guid>
		<description>Hi again Bill,

here it goes! You will also need two mp3 files named nice.mp3 and horrible.mp3 in a folder named audio. In my app these contain the pronunciation of the words.

You will also need a fla file with a rectanguar movieclip (extending sprite) named &quot;tg&quot; associated with the class Target.

In the real application I have an array of words and one of targets(normally photographs or drawings representing the words).

Thank you for your help and patience

Curro


/*

The component class:

package
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.geom.*;
	import flash.events.Event;
	public class DragQuestion extends Sprite
	{
		protected  var initX;
		protected var initY;
		private var userAnswer:*;
		private var answer:*;
		private var isRight:Boolean;
		private var checkStrategy:CheckStrategy;
		private var base:Sprite = new Sprite();
				
		public function setSprite(sprite:Sprite)
		{
			base = sprite;
			addChild(base);
		}
		public function dragMovie(event:MouseEvent):void
		{
			this.startDrag();
		}
		
		public function dropMovie(event:MouseEvent):void
		{
			this.stopDrag();
			checkTarget();
			
		}
		public function setStrategy(checkStrategy:CheckStrategy)
		{
			this.checkStrategy = checkStrategy;
			this.checkStrategy.setTarget(this);

		}
		public function setTarget(t:*)
		{
			this.answer = t;
		}

		public function getAnswer():*
		{
			return this.answer;
		}
		public function get origX():Number
		{
			return initX;
		}
		public function set origX(n:Number)
		{
			this.initX = n;
		}
		public function get origY():Number
		{
			return initY;
		}
		public function set origY(n:Number)
		{
			this.initY = n;
		}
		
		public function set correct(b:Boolean)
		{
			this.isRight = b;
		}
		public function get correct():Boolean
		{
			return this.isRight;
		}
		protected function checkTarget()
		{
			checkStrategy.checkTarget();
			this.isRight = this.isRight;
		}
		
		
	}
}
		

******************

The  Abstract Decorator class:

package
{
	import flash.events.MouseEvent;
	import flash.media.Sound;
	
	public class DrgQDecorator extends DragQuestion
	{
		public function setSound(s:Sound):void{}
		override public function dragMovie(e:MouseEvent):void{}
		override public function dropMovie(e:MouseEvent):void{}
	}
}


************

The concrete component class:

package
{
	public class DragTextQuestion extends DragQuestion
	{
		private var word:String;
		
		public function setUp(word:String, target:*, checkStrategy:CheckStrategy)
		{
			this.word = word;
			this.buttonMode = true;
			setSprite( new DragForm(word));
			setStrategy(checkStrategy);
			setTarget(target);
		}
		
	}
}



***************

Check strategy interface:

package
{
	public interface CheckStrategy 
	{
		function checkTarget():void;
		function setTarget(target:Object):void;
		
	}
}

**************
Concrete Strategy 1:

package
{
	import flash.geom.*;
	public class LooseCheck implements CheckStrategy
	{
		private var question:DragQuestion;
		
		public function setTarget(target:Object):void
		{
			this.question = target as DragQuestion;
		}
		public function checkTarget():void
		{
			if (question.dropTarget != null)
			{
				if (question.dropTarget.parent.hasOwnProperty(&quot;isTarget&quot;))
				{
					if(question.dropTarget.parent == question.getAnswer())
					{
						question.correct =true;
					}
					else
					{
						question.correct =false;
					}
					question.x = question.dropTarget.parent.x;
					question.y = question.dropTarget.parent.y;
}
				else
				{
					question.x = question.origX;
					question.y = question.origY;
				}
			}
			else
			{
				question.x = question.origX;
				question.y = question.origY;
				question.correct = false;
			}
			trace(&quot;Is Right?: &quot; + question.correct);
		}
		
	}
}


********************

Concrete Check strategy 2:

package
{
	public class TightCheck implements CheckStrategy
	{
		private var question:DragQuestion;
		
		public function setTarget(target:Object):void
		{
			this.question = target as DragQuestion;
		}
		public function checkTarget():void
		{
			
				if (question.hitTestObject(question.getAnswer()))
				{
					question.correct = true;
					question.x = question.dropTarget.parent.x;
					question.y = question.dropTarget.parent.y;
					
				}
				else
				{
					question.correct = false;
					question.x = question.origX;
					question.y = question.origY;
				}
			
			trace(question.correct);
		}
		
	}
}


*********************

Concrete Decorator 1:

package
{
	import flash.events.MouseEvent;
	import flash.media.Sound;
	import flash.net.URLRequest;
	
	public class DrgQSoundDecorator extends DrgQDecorator
	{
		private var dragQ:DragQuestion;
		private var sound:Sound;
		
		public function DrgQSoundDecorator(o:DragQuestion)
		{
			this.dragQ = o;
			addChild(dragQ);

		}
		override public function dragMovie(e:MouseEvent):void
		{
			
			this.dragQ.dragMovie(e);
		}
		override public function dropMovie(e:MouseEvent):void
		{
			sound.play();
			this.dragQ.dropMovie(e);
		}
		override public function get correct():Boolean
		{
			return this.dragQ.correct;
		}
		override public function setSound(s:Sound):void
		{
			this.sound = s;
		}
	}
}


****************

Concrete Decorator 2:

package
{
	import flash.events.MouseEvent;
	import flash.filters.*;
	
	public class DrgQFilterDecorator extends DrgQDecorator
	{
		private var dragQ:DragQuestion;
		var bevelFilter:BevelFilter = new BevelFilter();
		var shadowFilter:DropShadowFilter = new DropShadowFilter();
		var glowFilter:GlowFilter = new GlowFilter();
			
		
		public function DrgQFilterDecorator(o:DragQuestion)
		{
			this.dragQ = o;
			bevelFilter.shadowAlpha =0.5;
			bevelFilter.distance = 2;
			dragQ.filters = [bevelFilter, shadowFilter];
			addChild(dragQ);
		}
		override public function dragMovie(e:MouseEvent):void
		{
			
			glowFilter.color = 0xAA0000;
			glowFilter.blurX = 32;
			glowFilter.blurY = 32;
			glowFilter.strength = .6;
			
			dragQ.filters = [glowFilter];
			this.dragQ.dragMovie(e);
		}
		override public function dropMovie(e:MouseEvent):void
		{
			
			this.dragQ.filters =[bevelFilter, shadowFilter];
			this.dragQ.dropMovie(e);
		}
		override public function get correct():Boolean
		{
			return this.dragQ.correct;
		}
		
	}
}


*****************

Concrete Decorator 3:

package
{
	import flash.events.MouseEvent;
	import flash.media.Sound;
	import flash.net.URLRequest;
	import flash.display.*;
	import flash.geom.Point;
	import flash.events.MouseEvent;
	
	//import flash.filters.DropShadowFilter
	
	public class DrgQCorrectDecorator extends DrgQDecorator
	{
		private var dragQ:DragQuestion;
		private var sound:Sound;
		var figure:Shape = new Shape();
		
		public function DrgQCorrectDecorator(o:DragQuestion)
		{
			this.dragQ = o;
			addChild(dragQ);
			var rect = getBounds(dragQ);
			var pt:Point = new Point(rect.x +rect.width - 10, rect.y  + 10)
			//figure.graphics.beginFill();
			figure.graphics.lineStyle(4,0x33CC33);
			figure.graphics.moveTo(pt.x,pt.y);
			var pt2:Point = new Point(pt.x + 8, pt.y -8);
			figure.graphics.lineTo(pt2.x,pt2.y);
			var pt3 = new Point(pt.x - 5, pt.y -5);
			figure.graphics.moveTo(pt.x, pt.y);
			figure.graphics.lineTo(pt3.x, pt3.y);

			dragQ.addChild(figure);
			trace(&quot;getBounds(dragQ)&quot; + getBounds(dragQ));
			trace(&quot;getBounds(this)&quot; + getBounds(this));
			this.addEventListener(MouseEvent.MOUSE_DOWN, dragMovie);
								
		}
		override public function dragMovie(e:MouseEvent):void
		{
			try{
				dragQ.removeChild(figure);
			}
			catch(e:Error)
			{
			}
			this.dragQ.dragMovie(e);
		}
		override public function dropMovie(e:MouseEvent):void
		{
			this.dragQ.dropMovie(e);

		}
		override public function get correct():Boolean
		{
			if(this.dragQ.correct)
			{
				this.dragQ.removeEventListener(MouseEvent.MOUSE_DOWN, dragMovie);
				this.dragQ.buttonMode = false;
			}
			return this.dragQ.correct;
		}
		
	}
}


************************+

Concrete Decorator 4:

package
{
	import flash.events.MouseEvent;
	import flash.media.Sound;
	import flash.net.URLRequest;
	import flash.display.*;
	import flash.geom.Point;
	import flash.events.MouseEvent;
	
	
	public class DrgQWrongDecorator extends DrgQDecorator
	{
		private var dragQ:DragQuestion;
		private var sound:Sound;
		var figure:Shape = new Shape();
		
		public function DrgQWrongDecorator(o:DragQuestion)
		{
			this.dragQ = o;
			addChild(dragQ);
			
			var rect = getBounds(dragQ);
			var pt:Point = new Point(rect.x +rect.width - 10, rect.y  + 10)
			figure.graphics.lineStyle(4,0xFFBB00);
			figure.graphics.moveTo(pt.x,pt.y);
			var pt2:Point = new Point(pt.x + 8, pt.y -8);
			figure.graphics.lineTo(pt2.x,pt2.y);
			var pt3 = new Point(pt.x , pt.y-8 );
			figure.graphics.moveTo(pt.x+8, pt.y);
			figure.graphics.lineTo(pt3.x, pt3.y);
			
			dragQ.addChild(figure);
			this.addEventListener(MouseEvent.MOUSE_DOWN, dragMovie);
								
		}
		override public function dragMovie(e:MouseEvent):void
		{
			try{
				dragQ.removeChild(figure);
			}
			catch(e:Error)
			{
			}
			this.dragQ.dragMovie(e);
		}
		override public function dropMovie(e:MouseEvent):void
		{
			this.dragQ.dropMovie(e);

		}
		override public function get correct():Boolean
		{
			return this.dragQ.correct;
		}
		
	}
}


*******************

Target Class:

package
{
	import flash.display.Sprite;
	
	public class Target extends Sprite
	{
		public var isTarget:Boolean = true;
	}
}

***************************

Helper class to give form to dragable words:

package
{
	import flash.text.*;
	import flash.display.Shape;
	import flash.display.Sprite;
	
	public class DragForm extends Sprite
	{
		private var word:String;
		private var field:TextField;
		
		public function DragForm(word:String)
		{
			this.word = word;
			display();
		}
		public function setUp()
		{
			
			
		}

		private function display()
		{
			field = new TextField();
			field.multiline = false;
			field.selectable = false;
			
			field.autoSize = TextFieldAutoSize.CENTER;
			field.type = TextFieldType.DYNAMIC;
			field.text = word;
			//field.background = true;
			//field.border = true;


			var format:TextFormat = new TextFormat();
			format.font = &quot;Arial&quot;;
			format.size = 18;
			format.color = 0xFFFFFF;

			format.bold = true;
			field.setTextFormat(format);


			var shape:Shape = new Shape();
			var bgColour:uint = 0xCC3300;
			shape.graphics.beginFill(bgColour);
			shape.graphics.drawRoundRect(- field.width/2 -2, (-field.height/2)-2 ,field.width +4  ,field.height+4 ,30);
			shape.graphics.endFill();
			addChild(shape);
			addChild(field);

			field.x =  -  field.width / 2;
			field.y =  -  field.height / 2;
			var theMask = new Sprite();
			theMask.graphics.beginFill(0x000000, 0.0);
			theMask.graphics.drawRect(-field.width/2,-field.height/2,field.width,field.height);
			theMask.graphics.endFill();
			addChild(theMask);
		}

	}
}


********************

finally the client class. It has only two drag questions with a different check strategy each. One(TightCheck) doesn&#039;t let the dragWord on the target unless it is the right one. The other lets  it stay on and you see if it is correct with visual clues.


package
{
	import flash.text.*;
	import flash.display.Shape;
	import flash.display.Sprite;
	
	public class DragForm extends Sprite
	{
		private var word:String;
		private var field:TextField;
		
		public function DragForm(word:String)
		{
			this.word = word;
			display();
		}
		public function setUp()
		{
			
			
		}

		private function display()
		{
			field = new TextField();
			field.multiline = false;
			field.selectable = false;
			
			field.autoSize = TextFieldAutoSize.CENTER;
			field.type = TextFieldType.DYNAMIC;
			field.text = word;
			//field.background = true;
			//field.border = true;


			var format:TextFormat = new TextFormat();
			format.font = &quot;Arial&quot;;
			format.size = 18;
			format.color = 0xFFFFFF;

			format.bold = true;
			field.setTextFormat(format);


			var shape:Shape = new Shape();
			var bgColour:uint = 0xCC3300;
			shape.graphics.beginFill(bgColour);
			shape.graphics.drawRoundRect(- field.width/2 -2, (-field.height/2)-2 ,field.width +4  ,field.height+4 ,30);
			shape.graphics.endFill();
			addChild(shape);
			addChild(field);

			field.x =  -  field.width / 2;
			field.y =  -  field.height / 2;
			var theMask = new Sprite();
			theMask.graphics.beginFill(0x000000, 0.0);
			theMask.graphics.drawRect(-field.width/2,-field.height/2,field.width,field.height);
			theMask.graphics.endFill();
			addChild(theMask);
		}

	}
}


*/

</description>
		<content:encoded><![CDATA[<p>Hi again Bill,</p>
<p>here it goes! You will also need two mp3 files named nice.mp3 and horrible.mp3 in a folder named audio. In my app these contain the pronunciation of the words.</p>
<p>You will also need a fla file with a rectanguar movieclip (extending sprite) named &#8220;tg&#8221; associated with the class Target.</p>
<p>In the real application I have an array of words and one of targets(normally photographs or drawings representing the words).</p>
<p>Thank you for your help and patience</p>
<p>Curro</p>
<p>/*</p>
<p>The component class:</p>
<p>package<br />
{<br />
	import flash.display.Sprite;<br />
	import flash.events.MouseEvent;<br />
	import flash.geom.*;<br />
	import flash.events.Event;<br />
	public class DragQuestion extends Sprite<br />
	{<br />
		protected  var initX;<br />
		protected var initY;<br />
		private var userAnswer:*;<br />
		private var answer:*;<br />
		private var isRight:Boolean;<br />
		private var checkStrategy:CheckStrategy;<br />
		private var base:Sprite = new Sprite();</p>
<p>		public function setSprite(sprite:Sprite)<br />
		{<br />
			base = sprite;<br />
			addChild(base);<br />
		}<br />
		public function dragMovie(event:MouseEvent):void<br />
		{<br />
			this.startDrag();<br />
		}</p>
<p>		public function dropMovie(event:MouseEvent):void<br />
		{<br />
			this.stopDrag();<br />
			checkTarget();</p>
<p>		}<br />
		public function setStrategy(checkStrategy:CheckStrategy)<br />
		{<br />
			this.checkStrategy = checkStrategy;<br />
			this.checkStrategy.setTarget(this);</p>
<p>		}<br />
		public function setTarget(t:*)<br />
		{<br />
			this.answer = t;<br />
		}</p>
<p>		public function getAnswer():*<br />
		{<br />
			return this.answer;<br />
		}<br />
		public function get origX():Number<br />
		{<br />
			return initX;<br />
		}<br />
		public function set origX(n:Number)<br />
		{<br />
			this.initX = n;<br />
		}<br />
		public function get origY():Number<br />
		{<br />
			return initY;<br />
		}<br />
		public function set origY(n:Number)<br />
		{<br />
			this.initY = n;<br />
		}</p>
<p>		public function set correct(b:Boolean)<br />
		{<br />
			this.isRight = b;<br />
		}<br />
		public function get correct():Boolean<br />
		{<br />
			return this.isRight;<br />
		}<br />
		protected function checkTarget()<br />
		{<br />
			checkStrategy.checkTarget();<br />
			this.isRight = this.isRight;<br />
		}</p>
<p>	}<br />
}</p>
<p>******************</p>
<p>The  Abstract Decorator class:</p>
<p>package<br />
{<br />
	import flash.events.MouseEvent;<br />
	import flash.media.Sound;</p>
<p>	public class DrgQDecorator extends DragQuestion<br />
	{<br />
		public function setSound(s:Sound):void{}<br />
		override public function dragMovie(e:MouseEvent):void{}<br />
		override public function dropMovie(e:MouseEvent):void{}<br />
	}<br />
}</p>
<p>************</p>
<p>The concrete component class:</p>
<p>package<br />
{<br />
	public class DragTextQuestion extends DragQuestion<br />
	{<br />
		private var word:String;</p>
<p>		public function setUp(word:String, target:*, checkStrategy:CheckStrategy)<br />
		{<br />
			this.word = word;<br />
			this.buttonMode = true;<br />
			setSprite( new DragForm(word));<br />
			setStrategy(checkStrategy);<br />
			setTarget(target);<br />
		}</p>
<p>	}<br />
}</p>
<p>***************</p>
<p>Check strategy interface:</p>
<p>package<br />
{<br />
	public interface CheckStrategy<br />
	{<br />
		function checkTarget():void;<br />
		function setTarget(target:Object):void;</p>
<p>	}<br />
}</p>
<p>**************<br />
Concrete Strategy 1:</p>
<p>package<br />
{<br />
	import flash.geom.*;<br />
	public class LooseCheck implements CheckStrategy<br />
	{<br />
		private var question:DragQuestion;</p>
<p>		public function setTarget(target:Object):void<br />
		{<br />
			this.question = target as DragQuestion;<br />
		}<br />
		public function checkTarget():void<br />
		{<br />
			if (question.dropTarget != null)<br />
			{<br />
				if (question.dropTarget.parent.hasOwnProperty(&#8221;isTarget&#8221;))<br />
				{<br />
					if(question.dropTarget.parent == question.getAnswer())<br />
					{<br />
						question.correct =true;<br />
					}<br />
					else<br />
					{<br />
						question.correct =false;<br />
					}<br />
					question.x = question.dropTarget.parent.x;<br />
					question.y = question.dropTarget.parent.y;<br />
}<br />
				else<br />
				{<br />
					question.x = question.origX;<br />
					question.y = question.origY;<br />
				}<br />
			}<br />
			else<br />
			{<br />
				question.x = question.origX;<br />
				question.y = question.origY;<br />
				question.correct = false;<br />
			}<br />
			trace(&#8221;Is Right?: &#8221; + question.correct);<br />
		}</p>
<p>	}<br />
}</p>
<p>********************</p>
<p>Concrete Check strategy 2:</p>
<p>package<br />
{<br />
	public class TightCheck implements CheckStrategy<br />
	{<br />
		private var question:DragQuestion;</p>
<p>		public function setTarget(target:Object):void<br />
		{<br />
			this.question = target as DragQuestion;<br />
		}<br />
		public function checkTarget():void<br />
		{</p>
<p>				if (question.hitTestObject(question.getAnswer()))<br />
				{<br />
					question.correct = true;<br />
					question.x = question.dropTarget.parent.x;<br />
					question.y = question.dropTarget.parent.y;</p>
<p>				}<br />
				else<br />
				{<br />
					question.correct = false;<br />
					question.x = question.origX;<br />
					question.y = question.origY;<br />
				}</p>
<p>			trace(question.correct);<br />
		}</p>
<p>	}<br />
}</p>
<p>*********************</p>
<p>Concrete Decorator 1:</p>
<p>package<br />
{<br />
	import flash.events.MouseEvent;<br />
	import flash.media.Sound;<br />
	import flash.net.URLRequest;</p>
<p>	public class DrgQSoundDecorator extends DrgQDecorator<br />
	{<br />
		private var dragQ:DragQuestion;<br />
		private var sound:Sound;</p>
<p>		public function DrgQSoundDecorator(o:DragQuestion)<br />
		{<br />
			this.dragQ = o;<br />
			addChild(dragQ);</p>
<p>		}<br />
		override public function dragMovie(e:MouseEvent):void<br />
		{</p>
<p>			this.dragQ.dragMovie(e);<br />
		}<br />
		override public function dropMovie(e:MouseEvent):void<br />
		{<br />
			sound.play();<br />
			this.dragQ.dropMovie(e);<br />
		}<br />
		override public function get correct():Boolean<br />
		{<br />
			return this.dragQ.correct;<br />
		}<br />
		override public function setSound(s:Sound):void<br />
		{<br />
			this.sound = s;<br />
		}<br />
	}<br />
}</p>
<p>****************</p>
<p>Concrete Decorator 2:</p>
<p>package<br />
{<br />
	import flash.events.MouseEvent;<br />
	import flash.filters.*;</p>
<p>	public class DrgQFilterDecorator extends DrgQDecorator<br />
	{<br />
		private var dragQ:DragQuestion;<br />
		var bevelFilter:BevelFilter = new BevelFilter();<br />
		var shadowFilter:DropShadowFilter = new DropShadowFilter();<br />
		var glowFilter:GlowFilter = new GlowFilter();</p>
<p>		public function DrgQFilterDecorator(o:DragQuestion)<br />
		{<br />
			this.dragQ = o;<br />
			bevelFilter.shadowAlpha =0.5;<br />
			bevelFilter.distance = 2;<br />
			dragQ.filters = [bevelFilter, shadowFilter];<br />
			addChild(dragQ);<br />
		}<br />
		override public function dragMovie(e:MouseEvent):void<br />
		{</p>
<p>			glowFilter.color = 0xAA0000;<br />
			glowFilter.blurX = 32;<br />
			glowFilter.blurY = 32;<br />
			glowFilter.strength = .6;</p>
<p>			dragQ.filters = [glowFilter];<br />
			this.dragQ.dragMovie(e);<br />
		}<br />
		override public function dropMovie(e:MouseEvent):void<br />
		{</p>
<p>			this.dragQ.filters =[bevelFilter, shadowFilter];<br />
			this.dragQ.dropMovie(e);<br />
		}<br />
		override public function get correct():Boolean<br />
		{<br />
			return this.dragQ.correct;<br />
		}</p>
<p>	}<br />
}</p>
<p>*****************</p>
<p>Concrete Decorator 3:</p>
<p>package<br />
{<br />
	import flash.events.MouseEvent;<br />
	import flash.media.Sound;<br />
	import flash.net.URLRequest;<br />
	import flash.display.*;<br />
	import flash.geom.Point;<br />
	import flash.events.MouseEvent;</p>
<p>	//import flash.filters.DropShadowFilter</p>
<p>	public class DrgQCorrectDecorator extends DrgQDecorator<br />
	{<br />
		private var dragQ:DragQuestion;<br />
		private var sound:Sound;<br />
		var figure:Shape = new Shape();</p>
<p>		public function DrgQCorrectDecorator(o:DragQuestion)<br />
		{<br />
			this.dragQ = o;<br />
			addChild(dragQ);<br />
			var rect = getBounds(dragQ);<br />
			var pt:Point = new Point(rect.x +rect.width &#8211; 10, rect.y  + 10)<br />
			//figure.graphics.beginFill();<br />
			figure.graphics.lineStyle(4,0&#215;33CC33);<br />
			figure.graphics.moveTo(pt.x,pt.y);<br />
			var pt2:Point = new Point(pt.x + 8, pt.y -8);<br />
			figure.graphics.lineTo(pt2.x,pt2.y);<br />
			var pt3 = new Point(pt.x &#8211; 5, pt.y -5);<br />
			figure.graphics.moveTo(pt.x, pt.y);<br />
			figure.graphics.lineTo(pt3.x, pt3.y);</p>
<p>			dragQ.addChild(figure);<br />
			trace(&#8221;getBounds(dragQ)&#8221; + getBounds(dragQ));<br />
			trace(&#8221;getBounds(this)&#8221; + getBounds(this));<br />
			this.addEventListener(MouseEvent.MOUSE_DOWN, dragMovie);</p>
<p>		}<br />
		override public function dragMovie(e:MouseEvent):void<br />
		{<br />
			try{<br />
				dragQ.removeChild(figure);<br />
			}<br />
			catch(e:Error)<br />
			{<br />
			}<br />
			this.dragQ.dragMovie(e);<br />
		}<br />
		override public function dropMovie(e:MouseEvent):void<br />
		{<br />
			this.dragQ.dropMovie(e);</p>
<p>		}<br />
		override public function get correct():Boolean<br />
		{<br />
			if(this.dragQ.correct)<br />
			{<br />
				this.dragQ.removeEventListener(MouseEvent.MOUSE_DOWN, dragMovie);<br />
				this.dragQ.buttonMode = false;<br />
			}<br />
			return this.dragQ.correct;<br />
		}</p>
<p>	}<br />
}</p>
<p>************************+</p>
<p>Concrete Decorator 4:</p>
<p>package<br />
{<br />
	import flash.events.MouseEvent;<br />
	import flash.media.Sound;<br />
	import flash.net.URLRequest;<br />
	import flash.display.*;<br />
	import flash.geom.Point;<br />
	import flash.events.MouseEvent;</p>
<p>	public class DrgQWrongDecorator extends DrgQDecorator<br />
	{<br />
		private var dragQ:DragQuestion;<br />
		private var sound:Sound;<br />
		var figure:Shape = new Shape();</p>
<p>		public function DrgQWrongDecorator(o:DragQuestion)<br />
		{<br />
			this.dragQ = o;<br />
			addChild(dragQ);</p>
<p>			var rect = getBounds(dragQ);<br />
			var pt:Point = new Point(rect.x +rect.width &#8211; 10, rect.y  + 10)<br />
			figure.graphics.lineStyle(4,0xFFBB00);<br />
			figure.graphics.moveTo(pt.x,pt.y);<br />
			var pt2:Point = new Point(pt.x + 8, pt.y -8);<br />
			figure.graphics.lineTo(pt2.x,pt2.y);<br />
			var pt3 = new Point(pt.x , pt.y-8 );<br />
			figure.graphics.moveTo(pt.x+8, pt.y);<br />
			figure.graphics.lineTo(pt3.x, pt3.y);</p>
<p>			dragQ.addChild(figure);<br />
			this.addEventListener(MouseEvent.MOUSE_DOWN, dragMovie);</p>
<p>		}<br />
		override public function dragMovie(e:MouseEvent):void<br />
		{<br />
			try{<br />
				dragQ.removeChild(figure);<br />
			}<br />
			catch(e:Error)<br />
			{<br />
			}<br />
			this.dragQ.dragMovie(e);<br />
		}<br />
		override public function dropMovie(e:MouseEvent):void<br />
		{<br />
			this.dragQ.dropMovie(e);</p>
<p>		}<br />
		override public function get correct():Boolean<br />
		{<br />
			return this.dragQ.correct;<br />
		}</p>
<p>	}<br />
}</p>
<p>*******************</p>
<p>Target Class:</p>
<p>package<br />
{<br />
	import flash.display.Sprite;</p>
<p>	public class Target extends Sprite<br />
	{<br />
		public var isTarget:Boolean = true;<br />
	}<br />
}</p>
<p>***************************</p>
<p>Helper class to give form to dragable words:</p>
<p>package<br />
{<br />
	import flash.text.*;<br />
	import flash.display.Shape;<br />
	import flash.display.Sprite;</p>
<p>	public class DragForm extends Sprite<br />
	{<br />
		private var word:String;<br />
		private var field:TextField;</p>
<p>		public function DragForm(word:String)<br />
		{<br />
			this.word = word;<br />
			display();<br />
		}<br />
		public function setUp()<br />
		{</p>
<p>		}</p>
<p>		private function display()<br />
		{<br />
			field = new TextField();<br />
			field.multiline = false;<br />
			field.selectable = false;</p>
<p>			field.autoSize = TextFieldAutoSize.CENTER;<br />
			field.type = TextFieldType.DYNAMIC;<br />
			field.text = word;<br />
			//field.background = true;<br />
			//field.border = true;</p>
<p>			var format:TextFormat = new TextFormat();<br />
			format.font = &#8220;Arial&#8221;;<br />
			format.size = 18;<br />
			format.color = 0xFFFFFF;</p>
<p>			format.bold = true;<br />
			field.setTextFormat(format);</p>
<p>			var shape:Shape = new Shape();<br />
			var bgColour:uint = 0xCC3300;<br />
			shape.graphics.beginFill(bgColour);<br />
			shape.graphics.drawRoundRect(- field.width/2 -2, (-field.height/2)-2 ,field.width +4  ,field.height+4 ,30);<br />
			shape.graphics.endFill();<br />
			addChild(shape);<br />
			addChild(field);</p>
<p>			field.x =  &#8211;  field.width / 2;<br />
			field.y =  &#8211;  field.height / 2;<br />
			var theMask = new Sprite();<br />
			theMask.graphics.beginFill(0&#215;000000, 0.0);<br />
			theMask.graphics.drawRect(-field.width/2,-field.height/2,field.width,field.height);<br />
			theMask.graphics.endFill();<br />
			addChild(theMask);<br />
		}</p>
<p>	}<br />
}</p>
<p>********************</p>
<p>finally the client class. It has only two drag questions with a different check strategy each. One(TightCheck) doesn&#8217;t let the dragWord on the target unless it is the right one. The other lets  it stay on and you see if it is correct with visual clues.</p>
<p>package<br />
{<br />
	import flash.text.*;<br />
	import flash.display.Shape;<br />
	import flash.display.Sprite;</p>
<p>	public class DragForm extends Sprite<br />
	{<br />
		private var word:String;<br />
		private var field:TextField;</p>
<p>		public function DragForm(word:String)<br />
		{<br />
			this.word = word;<br />
			display();<br />
		}<br />
		public function setUp()<br />
		{</p>
<p>		}</p>
<p>		private function display()<br />
		{<br />
			field = new TextField();<br />
			field.multiline = false;<br />
			field.selectable = false;</p>
<p>			field.autoSize = TextFieldAutoSize.CENTER;<br />
			field.type = TextFieldType.DYNAMIC;<br />
			field.text = word;<br />
			//field.background = true;<br />
			//field.border = true;</p>
<p>			var format:TextFormat = new TextFormat();<br />
			format.font = &#8220;Arial&#8221;;<br />
			format.size = 18;<br />
			format.color = 0xFFFFFF;</p>
<p>			format.bold = true;<br />
			field.setTextFormat(format);</p>
<p>			var shape:Shape = new Shape();<br />
			var bgColour:uint = 0xCC3300;<br />
			shape.graphics.beginFill(bgColour);<br />
			shape.graphics.drawRoundRect(- field.width/2 -2, (-field.height/2)-2 ,field.width +4  ,field.height+4 ,30);<br />
			shape.graphics.endFill();<br />
			addChild(shape);<br />
			addChild(field);</p>
<p>			field.x =  &#8211;  field.width / 2;<br />
			field.y =  &#8211;  field.height / 2;<br />
			var theMask = new Sprite();<br />
			theMask.graphics.beginFill(0&#215;000000, 0.0);<br />
			theMask.graphics.drawRect(-field.width/2,-field.height/2,field.width,field.height);<br />
			theMask.graphics.endFill();<br />
			addChild(theMask);<br />
		}</p>
<p>	}<br />
}</p>
<p>*/</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William B. Sanders</title>
		<link>http://www.as3dp.com/2009/04/26/actionscript-30-easy-and-practical-decorator-design-pattern/comment-page-1/#comment-3825</link>
		<dc:creator>William B. Sanders</dc:creator>
		<pubDate>Wed, 13 Jan 2010 19:34:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=886#comment-3825</guid>
		<description>Hi Curro,

Okay, now that makes it a lot clearer. So the problem is that the x and y properties are acting strangely. Why not send them and we&#039;ll see what&#039;s going on. Just put them in one big comment, and I&#039;ll break them down so that we can look at the code and figure out what&#039;s going on.

Take care,
Bill</description>
		<content:encoded><![CDATA[<p>Hi Curro,</p>
<p>Okay, now that makes it a lot clearer. So the problem is that the x and y properties are acting strangely. Why not send them and we&#8217;ll see what&#8217;s going on. Just put them in one big comment, and I&#8217;ll break them down so that we can look at the code and figure out what&#8217;s going on.</p>
<p>Take care,<br />
Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Curro</title>
		<link>http://www.as3dp.com/2009/04/26/actionscript-30-easy-and-practical-decorator-design-pattern/comment-page-1/#comment-3821</link>
		<dc:creator>Curro</dc:creator>
		<pubDate>Wed, 13 Jan 2010 18:28:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=886#comment-3821</guid>
		<description>Hi Bill,
I do have a common ancestor class for both the concrete component and the abstract decorator. So I don&#039;t think that&#039;s the problem.
Anyway, I didn&#039;t express myself clearly: the strange behaviours happen or not depending on when I set the X and 
Y coordinates of the object(before or after the decoration) not on when I add them to the stage.

I also forgot to mention that I am using a strategy pattern to implement different types of checking.

Shall I send you or post the files? They are 15 although short!

Thank you again for your time and interest.

Curro</description>
		<content:encoded><![CDATA[<p>Hi Bill,<br />
I do have a common ancestor class for both the concrete component and the abstract decorator. So I don&#8217;t think that&#8217;s the problem.<br />
Anyway, I didn&#8217;t express myself clearly: the strange behaviours happen or not depending on when I set the X and<br />
Y coordinates of the object(before or after the decoration) not on when I add them to the stage.</p>
<p>I also forgot to mention that I am using a strategy pattern to implement different types of checking.</p>
<p>Shall I send you or post the files? They are 15 although short!</p>
<p>Thank you again for your time and interest.</p>
<p>Curro</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William B. Sanders</title>
		<link>http://www.as3dp.com/2009/04/26/actionscript-30-easy-and-practical-decorator-design-pattern/comment-page-1/#comment-3819</link>
		<dc:creator>William B. Sanders</dc:creator>
		<pubDate>Wed, 13 Jan 2010 15:15:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=886#comment-3819</guid>
		<description>Hi Curro,

That&#039;s a great question, and &lt;em&gt;no posts are history&lt;/em&gt; on this blog. (That&#039;s because, they&#039;re based on topic; not timeframe.) For me, one of the trickiest problems in using ActionScript 3.0 is using the DisplayObjectContainer effectively. Further, this is not just an issue for the Decorator but for all design patterns for both Flash and Flash Builder (Flex).

In looking at the Client class in the above example, I believe that you can find the answer. What is being added to the DisplayObjectContainer (stage) is the &quot;decorated object&quot; not just the &quot;object&quot; and the &quot;decoration&quot; as separate elements.

The Decorator design pattern is the only one I know &lt;em&gt;that has an abstract class that is a subclass&lt;/em&gt;. So what I believe you&#039;ve attempted to do and why you&#039;re running into trouble is that you&#039;ve separated the decorator from the component and because the decorator is subclassed from the component, it&#039;s causing a problem with the DisplayObjectContainer. Of course, I&#039;d have to look at the code, but that&#039;s what it sounds like from what you say.

Take a look at the documentation for the DisplayObject and DisplayObjectContainer.

Kindest regards,
Bill</description>
		<content:encoded><![CDATA[<p>Hi Curro,</p>
<p>That&#8217;s a great question, and <em>no posts are history</em> on this blog. (That&#8217;s because, they&#8217;re based on topic; not timeframe.) For me, one of the trickiest problems in using ActionScript 3.0 is using the DisplayObjectContainer effectively. Further, this is not just an issue for the Decorator but for all design patterns for both Flash and Flash Builder (Flex).</p>
<p>In looking at the Client class in the above example, I believe that you can find the answer. What is being added to the DisplayObjectContainer (stage) is the &#8220;decorated object&#8221; not just the &#8220;object&#8221; and the &#8220;decoration&#8221; as separate elements.</p>
<p>The Decorator design pattern is the only one I know <em>that has an abstract class that is a subclass</em>. So what I believe you&#8217;ve attempted to do and why you&#8217;re running into trouble is that you&#8217;ve separated the decorator from the component and because the decorator is subclassed from the component, it&#8217;s causing a problem with the DisplayObjectContainer. Of course, I&#8217;d have to look at the code, but that&#8217;s what it sounds like from what you say.</p>
<p>Take a look at the documentation for the DisplayObject and DisplayObjectContainer.</p>
<p>Kindest regards,<br />
Bill</p>
]]></content:encoded>
	</item>
</channel>
</rss>
