<?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: Hitchhiker’s Guide to ActionScript 3.0: The Dragon Factory—Part 2</title>
	<atom:link href="http://www.as3dp.com/2009/09/13/hitchhiker%e2%80%99s-guide-to-actionscript-30-the-dragon-factory%e2%80%94part-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.as3dp.com/2009/09/13/hitchhiker%e2%80%99s-guide-to-actionscript-30-the-dragon-factory%e2%80%94part-2/</link>
	<description>OOP Techniques for Flash and Flex Developers</description>
	<lastBuildDate>Mon, 26 Jul 2010 13:40:37 -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/09/13/hitchhiker%e2%80%99s-guide-to-actionscript-30-the-dragon-factory%e2%80%94part-2/comment-page-1/#comment-3150</link>
		<dc:creator>William B. Sanders</dc:creator>
		<pubDate>Tue, 13 Oct 2009 10:00:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=1518#comment-3150</guid>
		<description>Hi Andreas,

Thanks for your patience in my getting back to you. Your query about a better way to drag objects is perfectly reasonable, but probably outside of the realm of design patterns in this sense—it concerns comparative algorithms with different syntaxes. Design patterns in computing are really about larger issues, and the level of abstraction is one that asks questions about re-usability and maintenance of programs with multiple classes.

However, your question about the Factory Method is pertinent to the issues we&#039;re pondering on this blog. The Factory Method is one of the essential design patterns (see Chapter 2 in our book) and &lt;a href=&quot;http://www.as3dp.com/category/design-patterns/factory-method/&quot; rel=&quot;nofollow&quot;&gt; in several places on this blog&lt;/a&gt;. It is important because it helps to loosen up a program. By separating the creation of an object (in a &#039;factory&#039; class identified as a creation participant) from its use by a Client class, you are able to loosen the relationship between creation and use. In this way, it&#039;s a lot easier to change and update a program because you don&#039;t have to worry about making changes that will slither through your program and disrupt one part with the added materials.

As for a list of popular design patterns with examples in AS3--that&#039;s what our book and this blog is all about. It&#039;s full of examples. Enjoy!

Kindest regards,
Bill</description>
		<content:encoded><![CDATA[<p>Hi Andreas,</p>
<p>Thanks for your patience in my getting back to you. Your query about a better way to drag objects is perfectly reasonable, but probably outside of the realm of design patterns in this sense—it concerns comparative algorithms with different syntaxes. Design patterns in computing are really about larger issues, and the level of abstraction is one that asks questions about re-usability and maintenance of programs with multiple classes.</p>
<p>However, your question about the Factory Method is pertinent to the issues we&#8217;re pondering on this blog. The Factory Method is one of the essential design patterns (see Chapter 2 in our book) and <a href="http://www.as3dp.com/category/design-patterns/factory-method/" rel="nofollow"> in several places on this blog</a>. It is important because it helps to loosen up a program. By separating the creation of an object (in a &#8216;factory&#8217; class identified as a creation participant) from its use by a Client class, you are able to loosen the relationship between creation and use. In this way, it&#8217;s a lot easier to change and update a program because you don&#8217;t have to worry about making changes that will slither through your program and disrupt one part with the added materials.</p>
<p>As for a list of popular design patterns with examples in AS3&#8211;that&#8217;s what our book and this blog is all about. It&#8217;s full of examples. Enjoy!</p>
<p>Kindest regards,<br />
Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andreas Renberg</title>
		<link>http://www.as3dp.com/2009/09/13/hitchhiker%e2%80%99s-guide-to-actionscript-30-the-dragon-factory%e2%80%94part-2/comment-page-1/#comment-3147</link>
		<dc:creator>Andreas Renberg</dc:creator>
		<pubDate>Mon, 12 Oct 2009 11:03:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=1518#comment-3147</guid>
		<description>Interesting article. I&#039;m completely self taught in several programming languages and have picked up my knowledge here and there from numerous places. Therefore, I haven&#039;t learned a lot about common industrial standards such as design patters etc. (I&#039;m going through a book on some right now, but it&#039;s rather slow reading :(

The funny thing is, I have an intense love for logic, and often I get gut feelings about what is a good idea or bad idea, even though I can give no clear reason, (such as the &quot;prototype&quot; property, just seems like a really bad idea, still not sure why) and often I find that I have been following certain design patterns without knowing.

I still don&#039;t understand exactly why you used the Factory Method. I have an idea, but I&#039;m not sure if it is an existing design pattern or just some unstructured code, or the advantages and disadvantages to using my idea compared to the Factory Method.

I was considering taking a different approach, creating your own dragging system. Since all DisplayObjects, weather Sprites or not, can listen for mouse events, it would be a lot easier to pick up on that.

Clients would create new &quot;DragListener&quot; instances. A DragListener listens for MOUSE_DOWN and MOUSE_UP parameters from one passed in object, and if the bounds are within a passed set area (likely a reference to a Rectangle, or can even be references to a Shape object or bitmap, with individual pixels tested using hitTest, or a custom hitArea object), the DragListener instance will dispatch &quot;DragEvents&quot;.
&lt;pre lang=&quot;actionscript&quot;&gt;
class DragListener extends EventDispatcher
{
   public function DragListener(mouseEventDispatcher:IEventDispatcher, hitArea:HitArea)
   {
      mouseEventDispatcher.addEventListener(MouseEvent.MOUSE_DOWN, startDragDetection);
   }

   public property mouseEventDispatcher:IEventDispatcher;
   public property hitArea:HitArea;

   private var startX:Number;
   private var startY:Number;

   function startDragDetection(mouseEv:MouseEvent)
   {
      if (hitArea.testPoint(mouseEv.location))
      {
         mouseEventDispatcher.addEventListener(MouseEvent.MOUSE_MOVE, moveDetection);
         mouseEventDispatcher.addEventListener(MouseEvent.MOUSE_UP, stopDragDetection);
         mouseEventDispatcher.removeEventListener(MouseEvent.MOUSE_DOW, startDragDetection);

         startX = mouseEv.localX;
         startY = mouseEv.localY;

         this.dispatchEvent(new DragEvent(DragEvent.START, startX, startY, 0, 0));
      }
   }

   function moveDetection(mouseEv:MouseEvent)
   {
      this.dispatchEvent(new DragEvent(DragEvent.MOVE, startX, startY, mouseEv.localX, mouseEv.localY));
   }

   function stopDragDetection(mouseEv:MouseEvent)
   {
      mouseEventDispatcher.removeEventListener(MouseEvent.MOUSE_MOVE,
moveDetection);
      mouseEventDispatcher.removeEventListener(MouseEvent.MOUSE_UP, stopDragDetection);
      mouseEventDispatcher.addEventListener(MouseEvent.MOUSE_DOWN, startDragDetection);

      this.dispatchEvent(new DragEvent(DragEvent.STOP, startX, startY, mouseEv.localX, mouseEv.localY));
   }

}
&lt;/pre&gt;

Here is pseudo code for how the DragEvent could look, ignoring non-essential or irrelevant properties and code:

&lt;pre lang=&quot;actionscript&quot;&gt;

class DragEvent extends Event
{
   public static const START;
   public static const MOVE;
   public static const STOP;

   public function DragEvent(eventString:String, startX, startY, currentX,
currentY)

   public readonly property currentTarget;
   public readonly property eventString;

   public readonly property startX;
   public readonly property startY;
   public readonly property currentX;
   public readonly property currentY;

   //The x and y values last dispatched - for simplicity
   public readonly property lastX;
   public readonly property lastY;

   //Yes, a long name, I know. Yet, descriptive
   public readonly property offsetSinceLastX;
   public readonly prpperty offsetSinceLastY;

   public readonly property offsetX
      {  return currentX - startX; }
   public readonly property offsetY;
      {  return currentY - startY; }

} // END DragEvent -----------------------------------------
-----
&lt;/pre&gt;

Finally, here is some sample code:

&lt;pre lang=&quot;actionscript&quot;&gt;


   //None of the below are really display objects or can listen for mouse
events
   var line1:Line;
   var circle1:Circle;
   var rectangle1:Rectangle; //Real AS3 class, but not a display object
   var movie1:Video; //This is a display object, but has no &quot;startDrag&quot; function
   var sprite1:Sprite //This has a startDrag function, but we won&#039;t be using
it

   //For the line, we have told it to only move once the mouse
   //has come to a complete stop in the dragging
   var lineDragger:DragListener = new DragListener(stage, line.hitArea);
   lineDragger.addEventListener(DragEvent.STOP, onStop);
   function onStop(dragEv:DragEvent)
   {
      line1.x += dragEv.offsetX;
      line1.y += dragEv.offsetY;

      //Redraw the line now
      this.graphics.clear();
      this.graphics.drawLine(line1);
   }

   //Listen on the entire stage, and drag the circle and
   //rectangle at the same time and just as much
   //updating each frame
   var shapeDragger = new DragListener(stage, stage);
   var rectStartX, rectStartY;
   var circStartX, circStartY;

   shapeDragger.addEventListener(DragEvent.START, onStart);
   function onStart(dragEv:DragEvent)
   { //Set the start X and Y values for the circle and rectangle  }
   shapeDragger.addEventListener(DragEvent.MOVE, moveShapes);
   function moveShapes(dragEv:DragEvent)
   {
      circle.x = circStartX + dragEv.offsetX;
      //etc...
   }

   //You get the point...

}

&lt;/pre&gt;

These events are more of suggestions for the target object to move to a certain area, and don&#039;t really need to be followed. Objects can choose weather or not to do anything in the listener functions.
 
This will allow even objects that are not DisplayObjects (such as lines drawn with the Graphics class) to be dragged as well. In addition, only one display object can be dragged with startDrag at a time, while many objects can be dragged with either several instances, or one instance dragging several objects.
 
I&#039;m not sure if my thinking is way off the road from Design Patterns...
 

There would be a bit of a difference for different coordinate spaces, and not all objects may have a &quot;mouseX&quot; and &quot;mouseY&quot; property, but a third parameter or a separate property could easily contain a simple system which points to which property names to look for these coordinates.
 
Also, do you have any compiled list of popular design patters with perhaps some AS3 example? It would be really handy if you extended the &quot;variation table&quot; with a feature that allows you to double click on an item for examples and more information.
 
Looking forward to reading the rest of your posts,
Andreas
</description>
		<content:encoded><![CDATA[<p>Interesting article. I&#8217;m completely self taught in several programming languages and have picked up my knowledge here and there from numerous places. Therefore, I haven&#8217;t learned a lot about common industrial standards such as design patters etc. (I&#8217;m going through a book on some right now, but it&#8217;s rather slow reading :(</p>
<p>The funny thing is, I have an intense love for logic, and often I get gut feelings about what is a good idea or bad idea, even though I can give no clear reason, (such as the &#8220;prototype&#8221; property, just seems like a really bad idea, still not sure why) and often I find that I have been following certain design patterns without knowing.</p>
<p>I still don&#8217;t understand exactly why you used the Factory Method. I have an idea, but I&#8217;m not sure if it is an existing design pattern or just some unstructured code, or the advantages and disadvantages to using my idea compared to the Factory Method.</p>
<p>I was considering taking a different approach, creating your own dragging system. Since all DisplayObjects, weather Sprites or not, can listen for mouse events, it would be a lot easier to pick up on that.</p>
<p>Clients would create new &#8220;DragListener&#8221; instances. A DragListener listens for MOUSE_DOWN and MOUSE_UP parameters from one passed in object, and if the bounds are within a passed set area (likely a reference to a Rectangle, or can even be references to a Shape object or bitmap, with individual pixels tested using hitTest, or a custom hitArea object), the DragListener instance will dispatch &#8220;DragEvents&#8221;.</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('p1518code1'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p15181"><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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
</pre></td><td class="code" id="p1518code1"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> DragListener <span style="color: #0066CC;">extends</span> EventDispatcher
<span style="color: #66cc66;">&#123;</span>
   <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> DragListener<span style="color: #66cc66;">&#40;</span>mouseEventDispatcher:IEventDispatcher, <span style="color: #0066CC;">hitArea</span>:<span style="color: #0066CC;">HitArea</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#123;</span>
      mouseEventDispatcher.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, startDragDetection<span style="color: #66cc66;">&#41;</span>;
   <span style="color: #66cc66;">&#125;</span>
&nbsp;
   <span style="color: #0066CC;">public</span> property mouseEventDispatcher:IEventDispatcher;
   <span style="color: #0066CC;">public</span> property <span style="color: #0066CC;">hitArea</span>:<span style="color: #0066CC;">HitArea</span>;
&nbsp;
   <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> startX:<span style="color: #0066CC;">Number</span>;
   <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> startY:<span style="color: #0066CC;">Number</span>;
&nbsp;
   <span style="color: #000000; font-weight: bold;">function</span> startDragDetection<span style="color: #66cc66;">&#40;</span>mouseEv:MouseEvent<span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#123;</span>
      <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">hitArea</span>.<span style="color: #006600;">testPoint</span><span style="color: #66cc66;">&#40;</span>mouseEv.<span style="color: #006600;">location</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#123;</span>
         mouseEventDispatcher.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_MOVE</span>, moveDetection<span style="color: #66cc66;">&#41;</span>;
         mouseEventDispatcher.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, stopDragDetection<span style="color: #66cc66;">&#41;</span>;
         mouseEventDispatcher.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOW</span>, startDragDetection<span style="color: #66cc66;">&#41;</span>;
&nbsp;
         startX = mouseEv.<span style="color: #006600;">localX</span>;
         startY = mouseEv.<span style="color: #006600;">localY</span>;
&nbsp;
         <span style="color: #0066CC;">this</span>.<span style="color: #006600;">dispatchEvent</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> DragEvent<span style="color: #66cc66;">&#40;</span>DragEvent.<span style="color: #0066CC;">START</span>, startX, startY, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #66cc66;">&#125;</span>
   <span style="color: #66cc66;">&#125;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">function</span> moveDetection<span style="color: #66cc66;">&#40;</span>mouseEv:MouseEvent<span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#123;</span>
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">dispatchEvent</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> DragEvent<span style="color: #66cc66;">&#40;</span>DragEvent.<span style="color: #006600;">MOVE</span>, startX, startY, mouseEv.<span style="color: #006600;">localX</span>, mouseEv.<span style="color: #006600;">localY</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
   <span style="color: #66cc66;">&#125;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">function</span> stopDragDetection<span style="color: #66cc66;">&#40;</span>mouseEv:MouseEvent<span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#123;</span>
      mouseEventDispatcher.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_MOVE</span>,
moveDetection<span style="color: #66cc66;">&#41;</span>;
      mouseEventDispatcher.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, stopDragDetection<span style="color: #66cc66;">&#41;</span>;
      mouseEventDispatcher.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, startDragDetection<span style="color: #66cc66;">&#41;</span>;
&nbsp;
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">dispatchEvent</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> DragEvent<span style="color: #66cc66;">&#40;</span>DragEvent.<span style="color: #0066CC;">STOP</span>, startX, startY, mouseEv.<span style="color: #006600;">localX</span>, mouseEv.<span style="color: #006600;">localY</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
   <span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Here is pseudo code for how the DragEvent could look, ignoring non-essential or irrelevant properties and code:</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('p1518code2'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p15182"><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
29
30
31
32
33
</pre></td><td class="code" id="p1518code2"><pre class="actionscript" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> DragEvent <span style="color: #0066CC;">extends</span> Event
<span style="color: #66cc66;">&#123;</span>
   <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const <span style="color: #0066CC;">START</span>;
   <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const MOVE;
   <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const <span style="color: #0066CC;">STOP</span>;
&nbsp;
   <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> DragEvent<span style="color: #66cc66;">&#40;</span>eventString:<span style="color: #0066CC;">String</span>, startX, startY, currentX,
currentY<span style="color: #66cc66;">&#41;</span>
&nbsp;
   <span style="color: #0066CC;">public</span> readonly property currentTarget;
   <span style="color: #0066CC;">public</span> readonly property eventString;
&nbsp;
   <span style="color: #0066CC;">public</span> readonly property startX;
   <span style="color: #0066CC;">public</span> readonly property startY;
   <span style="color: #0066CC;">public</span> readonly property currentX;
   <span style="color: #0066CC;">public</span> readonly property currentY;
&nbsp;
   <span style="color: #808080; font-style: italic;">//The x and y values last dispatched - for simplicity</span>
   <span style="color: #0066CC;">public</span> readonly property lastX;
   <span style="color: #0066CC;">public</span> readonly property lastY;
&nbsp;
   <span style="color: #808080; font-style: italic;">//Yes, a long name, I know. Yet, descriptive</span>
   <span style="color: #0066CC;">public</span> readonly property offsetSinceLastX;
   <span style="color: #0066CC;">public</span> readonly prpperty offsetSinceLastY;
&nbsp;
   <span style="color: #0066CC;">public</span> readonly property offsetX
      <span style="color: #66cc66;">&#123;</span>  <span style="color: #b1b100;">return</span> currentX - startX; <span style="color: #66cc66;">&#125;</span>
   <span style="color: #0066CC;">public</span> readonly property offsetY;
      <span style="color: #66cc66;">&#123;</span>  <span style="color: #b1b100;">return</span> currentY - startY; <span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span> <span style="color: #808080; font-style: italic;">// END DragEvent -----------------------------------------</span>
-----</pre></td></tr></table></div>

<p>Finally, here is some sample code:</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('p1518code3'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p15183"><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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
</pre></td><td class="code" id="p1518code3"><pre class="actionscript" style="font-family:monospace;">&nbsp;
&nbsp;
   <span style="color: #808080; font-style: italic;">//None of the below are really display objects or can listen for mouse</span>
events
   <span style="color: #000000; font-weight: bold;">var</span> line1:Line;
   <span style="color: #000000; font-weight: bold;">var</span> circle1:Circle;
   <span style="color: #000000; font-weight: bold;">var</span> rectangle1:Rectangle; <span style="color: #808080; font-style: italic;">//Real AS3 class, but not a display object</span>
   <span style="color: #000000; font-weight: bold;">var</span> movie1:<span style="color: #0066CC;">Video</span>; <span style="color: #808080; font-style: italic;">//This is a display object, but has no &quot;startDrag&quot; function</span>
   <span style="color: #000000; font-weight: bold;">var</span> sprite1:Sprite <span style="color: #808080; font-style: italic;">//This has a startDrag function, but we won't be using</span>
it
&nbsp;
   <span style="color: #808080; font-style: italic;">//For the line, we have told it to only move once the mouse</span>
   <span style="color: #808080; font-style: italic;">//has come to a complete stop in the dragging</span>
   <span style="color: #000000; font-weight: bold;">var</span> lineDragger:DragListener = <span style="color: #000000; font-weight: bold;">new</span> DragListener<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>, line.<span style="color: #0066CC;">hitArea</span><span style="color: #66cc66;">&#41;</span>;
   lineDragger.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>DragEvent.<span style="color: #0066CC;">STOP</span>, onStop<span style="color: #66cc66;">&#41;</span>;
   <span style="color: #000000; font-weight: bold;">function</span> onStop<span style="color: #66cc66;">&#40;</span>dragEv:DragEvent<span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#123;</span>
      line1.<span style="color: #006600;">x</span> += dragEv.<span style="color: #006600;">offsetX</span>;
      line1.<span style="color: #006600;">y</span> += dragEv.<span style="color: #006600;">offsetY</span>;
&nbsp;
      <span style="color: #808080; font-style: italic;">//Redraw the line now</span>
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">clear</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawLine</span><span style="color: #66cc66;">&#40;</span>line1<span style="color: #66cc66;">&#41;</span>;
   <span style="color: #66cc66;">&#125;</span>
&nbsp;
   <span style="color: #808080; font-style: italic;">//Listen on the entire stage, and drag the circle and</span>
   <span style="color: #808080; font-style: italic;">//rectangle at the same time and just as much</span>
   <span style="color: #808080; font-style: italic;">//updating each frame</span>
   <span style="color: #000000; font-weight: bold;">var</span> shapeDragger = <span style="color: #000000; font-weight: bold;">new</span> DragListener<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>, <span style="color: #0066CC;">stage</span><span style="color: #66cc66;">&#41;</span>;
   <span style="color: #000000; font-weight: bold;">var</span> rectStartX, rectStartY;
   <span style="color: #000000; font-weight: bold;">var</span> circStartX, circStartY;
&nbsp;
   shapeDragger.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>DragEvent.<span style="color: #0066CC;">START</span>, onStart<span style="color: #66cc66;">&#41;</span>;
   <span style="color: #000000; font-weight: bold;">function</span> onStart<span style="color: #66cc66;">&#40;</span>dragEv:DragEvent<span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">//Set the start X and Y values for the circle and rectangle  }</span>
   shapeDragger.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>DragEvent.<span style="color: #006600;">MOVE</span>, moveShapes<span style="color: #66cc66;">&#41;</span>;
   <span style="color: #000000; font-weight: bold;">function</span> moveShapes<span style="color: #66cc66;">&#40;</span>dragEv:DragEvent<span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#123;</span>
      circle.<span style="color: #006600;">x</span> = circStartX + dragEv.<span style="color: #006600;">offsetX</span>;
      <span style="color: #808080; font-style: italic;">//etc...</span>
   <span style="color: #66cc66;">&#125;</span>
&nbsp;
   <span style="color: #808080; font-style: italic;">//You get the point...</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>These events are more of suggestions for the target object to move to a certain area, and don&#8217;t really need to be followed. Objects can choose weather or not to do anything in the listener functions.</p>
<p>This will allow even objects that are not DisplayObjects (such as lines drawn with the Graphics class) to be dragged as well. In addition, only one display object can be dragged with startDrag at a time, while many objects can be dragged with either several instances, or one instance dragging several objects.</p>
<p>I&#8217;m not sure if my thinking is way off the road from Design Patterns&#8230;</p>
<p>There would be a bit of a difference for different coordinate spaces, and not all objects may have a &#8220;mouseX&#8221; and &#8220;mouseY&#8221; property, but a third parameter or a separate property could easily contain a simple system which points to which property names to look for these coordinates.</p>
<p>Also, do you have any compiled list of popular design patters with perhaps some AS3 example? It would be really handy if you extended the &#8220;variation table&#8221; with a feature that allows you to double click on an item for examples and more information.</p>
<p>Looking forward to reading the rest of your posts,<br />
Andreas</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William B. Sanders</title>
		<link>http://www.as3dp.com/2009/09/13/hitchhiker%e2%80%99s-guide-to-actionscript-30-the-dragon-factory%e2%80%94part-2/comment-page-1/#comment-2953</link>
		<dc:creator>William B. Sanders</dc:creator>
		<pubDate>Sun, 13 Sep 2009 22:15:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=1518#comment-2953</guid>
		<description>Hi Patrick,

The thing about design patterns that is most important for me is that they help me rid myself of some pretty bad practices. Also, I&#039;ve learned to be patient with both design patterns and myself. When I&#039;ve learned other aspects of coding, the syntax, key statements and structure have come very fast. However, design patterns rarely come fast, and they&#039;re difficult. Okay, so they&#039;ll take a bit longer, but there&#039;s no hurry. Just poke here and poke there, and pretty soon you&#039;ve got a set of better coding practices that follow the principles that have developed over the years in computer science and related fields. As the practices improve, you&#039;ll start seeing your code take a different direction.

Your point about developing small e-learning interactions is probably true with a lot of people using Flash and Flex—it has been with me as well. Actually, the small projects make it a bit easier to try out some different design patterns. Tackling a big project with a complex system of coding may actually take longer, and the only thing you get sooner is the realization that design patterns are handy little critters.

Kindest regards,
Bill</description>
		<content:encoded><![CDATA[<p>Hi Patrick,</p>
<p>The thing about design patterns that is most important for me is that they help me rid myself of some pretty bad practices. Also, I&#8217;ve learned to be patient with both design patterns and myself. When I&#8217;ve learned other aspects of coding, the syntax, key statements and structure have come very fast. However, design patterns rarely come fast, and they&#8217;re difficult. Okay, so they&#8217;ll take a bit longer, but there&#8217;s no hurry. Just poke here and poke there, and pretty soon you&#8217;ve got a set of better coding practices that follow the principles that have developed over the years in computer science and related fields. As the practices improve, you&#8217;ll start seeing your code take a different direction.</p>
<p>Your point about developing small e-learning interactions is probably true with a lot of people using Flash and Flex—it has been with me as well. Actually, the small projects make it a bit easier to try out some different design patterns. Tackling a big project with a complex system of coding may actually take longer, and the only thing you get sooner is the realization that design patterns are handy little critters.</p>
<p>Kindest regards,<br />
Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Patrick Grey</title>
		<link>http://www.as3dp.com/2009/09/13/hitchhiker%e2%80%99s-guide-to-actionscript-30-the-dragon-factory%e2%80%94part-2/comment-page-1/#comment-2952</link>
		<dc:creator>Patrick Grey</dc:creator>
		<pubDate>Sun, 13 Sep 2009 21:16:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=1518#comment-2952</guid>
		<description>Hello Bill,
Thanks for this post. I am trying to learn design patterns but it is a slow process with a brain like porridge.

I tend to develop small e-learning interactions and sometimes struggle to see how DP&#039;s are relevant to my work but this post gave me something to &#039;hook&#039; into and &#039;take to work&#039;.

On the odd occasion I do build something more complex, I seem to have adopted the learning philosophy of make as many mistakes as one coder possibly can, then slowly learn from them.

Switching from AS2 to AS3 has helped to curtail some of my more, er, &#039;unique&#039; coding practices but my gut tells me that design patterns will help me work smarter / have more time for beer.

So, thanks again and I look forward to future posts.

Cheers,
Patrick</description>
		<content:encoded><![CDATA[<p>Hello Bill,<br />
Thanks for this post. I am trying to learn design patterns but it is a slow process with a brain like porridge.</p>
<p>I tend to develop small e-learning interactions and sometimes struggle to see how DP&#8217;s are relevant to my work but this post gave me something to &#8216;hook&#8217; into and &#8216;take to work&#8217;.</p>
<p>On the odd occasion I do build something more complex, I seem to have adopted the learning philosophy of make as many mistakes as one coder possibly can, then slowly learn from them.</p>
<p>Switching from AS2 to AS3 has helped to curtail some of my more, er, &#8216;unique&#8217; coding practices but my gut tells me that design patterns will help me work smarter / have more time for beer.</p>
<p>So, thanks again and I look forward to future posts.</p>
<p>Cheers,<br />
Patrick</p>
]]></content:encoded>
	</item>
</channel>
</rss>
