<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ActionScript 3.0 Design Patterns &#187; Catalog</title>
	<atom:link href="http://www.as3dp.com/category/catalog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.as3dp.com</link>
	<description>OOP Techniques for Flash and Flex Developers</description>
	<lastBuildDate>Sun, 29 Jan 2012 17:00:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Actionscript 3.0 Design Pattern Catalog: Structural Patterns</title>
		<link>http://www.as3dp.com/2009/12/actionscript-3-0-design-pattern-catalog-structural-patterns/</link>
		<comments>http://www.as3dp.com/2009/12/actionscript-3-0-design-pattern-catalog-structural-patterns/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 10:22:09 +0000</pubDate>
		<dc:creator>William B. Sanders</dc:creator>
				<category><![CDATA[Catalog]]></category>

		<guid isPermaLink="false">http://www.as3dp.com/?p=2237</guid>
		<description><![CDATA[The Fearless ActionScript 3.0 Design Pattern Catalog Soldiers On I was able to get the second installment of the ActionScript 3.0 Design Pattern Catalog finished. For a running start, you can see the Creative/Structural Catalog online. As you will recall, in the First Part of the Catalog project, I used a dual-factory framework for creating [...]]]></description>
			<content:encoded><![CDATA[<p><strong>The Fearless ActionScript 3.0 Design Pattern Catalog Soldiers On</strong></p>
<p>I was able to get the second installment of the ActionScript 3.0 Design Pattern Catalog finished. For a running start, you can see the <a href="http://www.sandlight.net/dpBlog/catalog/">Creative/Structural Catalog</a> online. As you will recall, in the <a href="http://www.as3dp.com/2009/07/15/actionscript-30-design-pattern-catalog-creational-patterns/">First Part</a> of the Catalog project, I used a dual-factory framework for creating the patterns. Other than the work adding new text files and drawing the class diagrams, updating was a piece of cake. I had to make changes to the <strong>CatData.as</strong> file to add the names of the Structural patterns, but otherwise, all I did was fill out text files. It was like magic. Everything else just took care of itself. (It&#8217;s always nice to see design patterns at work!) Figure 1 shows the progress:<br />
<div id="attachment_2240" class="wp-caption alignnone" style="width: 510px"><img src="http://www.as3dp.com/wp-content/uploads/2009/12/layout2.png" alt="&lt;em&gt;&lt;strong&gt;Figure 1: &lt;/strong&gt; The Added Structural Classes&lt;/em&gt;" title="layout2" width="500" height="334" class="size-full wp-image-2240" /><p class="wp-caption-text"><em><strong>Figure 1: </strong> The Added Structural Classes</em></p></div></p>
<p>It doesn&#8217;t look any different than the original other than the fact that it now has more than twice as many design patterns.</p>
<p><strong>AIR Version Available</strong></p>
<p>Ben Beaumont helpfully pointed out that instead of trying to grab 156 individual files, I could just grab the two type folders (Creational and Structural)  in the AIR version and it worked fine. Click the download button to get the AIR Design Pattern Catalog for a very handy reference on your desktop:</p>
<p><a href="http://www.sandlight.net/dpBlog/catalog/DPCatalog.air.zip"><img src="http://www.as3dp.com/wp-content/uploads/2009/11/kilroy.png" alt="kilroy" title="kilroy" width="112" height="56" class="alignleft size-full wp-image-2020" /></a> <img src="http://www.as3dp.com/wp-content/uploads/2009/12/AIR.png" alt="AIR" title="AIR" width="75" height="75" class="alignnone size-full wp-image-2263" /></p>
<p>I put the files online so that you can download them to see how everything works together. You will notice that they&#8217;re the same as the initial set except you now have a lot more patterns.</p>
<p><a href="http://nemo.mwd.hartford.edu/~wsanders/dpcatalog/DPCatalog.zip"><img src="http://www.as3dp.com/wp-content/uploads/2009/11/kilroy.png" alt="kilroy" title="kilroy" width="112" height="56" class="alignleft size-full wp-image-2020" /> </a><img src="http://www.as3dp.com/wp-content/uploads/2009/12/file.png" alt="file" title="file" width="75" height="75" class="alignnone size-full wp-image-2262" /></p>
<p>If you feel creepy for not helping out, you can be a big help by proof-reading the content and see if mistakes were made. (If you find any, send them to me, and I&#8217;ll fix them.) Also, it would be über cool if someone could translate the text files from English into other languages. I&#8217;d like to put up editions in as many languages as could be contributed.</p>
<p>In the meantime, enjoy the updated catalog.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.as3dp.com%2F2009%2F12%2Factionscript-3-0-design-pattern-catalog-structural-patterns%2F&amp;title=Actionscript%203.0%20Design%20Pattern%20Catalog%3A%20Structural%20Patterns" id="wpa2a_2"><img src="http://www.as3dp.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.as3dp.com/2009/12/actionscript-3-0-design-pattern-catalog-structural-patterns/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>ActionScript 3.0 Design Pattern Catalog: Creational Patterns</title>
		<link>http://www.as3dp.com/2009/07/actionscript-30-design-pattern-catalog-creational-patterns/</link>
		<comments>http://www.as3dp.com/2009/07/actionscript-30-design-pattern-catalog-creational-patterns/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 16:14:29 +0000</pubDate>
		<dc:creator>William B. Sanders</dc:creator>
				<category><![CDATA[Catalog]]></category>
		<category><![CDATA[Factory Method]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.as3dp.com/?p=1151</guid>
		<description><![CDATA[A Tale of Two Factories: One New and One Reused This is the first of three posts on the actual AIR ActionScript 3.0 Design Pattern catalog. Previously, I had discussed the thinking that went into the design of the Catalog, and here is the first actual AIR application with the Creational Patterns portion of the [...]]]></description>
			<content:encoded><![CDATA[<p><strong>A Tale of Two Factories: One New and One Reused</strong></p>
<p>This is the first of three posts on the actual AIR ActionScript 3.0 Design Pattern catalog. Previously, <a href=http://www.as3dp.com/2009/07/07/deciding-on-a-design-pattern-a-graphic-and-text-catalog/>I had discussed the thinking that went into the design of the Catalog</a>, and here is the first actual AIR application with the Creational Patterns portion of the catalog all set up and ready to use.  Figure 1 shows what each page looks like: (By the way, the actual image in the catalog is almost twice the size as what you see in Figure 1.)</p>
<p><img src="http://www.as3dp.com/wp-content/uploads/2009/07/catalog1.png" alt="catalog1" title="catalog1" width="500" height="354" class="alignnone size-full wp-image-1152" /><br />
<em><strong>Figure 1: </strong>Design Pattern Catalog Page</em></p>
<p>Before going on, you can download all of the source code and the AIR application by clicking the Download button. Additionally, you may want to access the <a href="http://nemo.mwd.hartford.edu/~wsanders/dpcatalog/">Catalog Online</a>.<br />
<a href="http://nemo.mwd.hartford.edu/~wsanders/dpWork/Catalog1.zip"><br />
<img src="http://www.as3dp.com/wp-content/uploads/2009/07/download.png" alt="download" title="download" width="99" height="47" class="alignnone size-full wp-image-1153" /></a></p>
<p>I changed the color combinations. I concluded that Kuler’s  <em>1944mustang </em> color set was the best for this project because I needed a white background and I liked the orange for highlight. I used red for labeling on the diagrams, but it was used sparsely and provided a consistency.<br />
<span id="more-1151"></span><br />
After several false starts, I finally settled on the Factory Method, and by the time I was finished, I was glad I did. It’s an easy design pattern, keeps the classes loosely connected and is very flexible. In fact I used two Factory Method patterns—one was reused from an earlier application where the factory method was used to send DataProvider data to the Client. (See <a href=http://www.as3dp.com/2009/06/16/friends-with-benefits-refactoring-with-multiple-design-patterns—part-i/>Refactoring with Multiple Design Patterns</a>.)</p>
<p>The new Factory Method created instances of the pages assembled from several text fields and a graphic. Initially, I was going to have a single Product class and a different ConcreteProduct class for each pattern (23 in all), and that was exactly what I started doing. However, I soon discovered that the only thing that I needed to do was to pass a string parameter with  the data name for each pattern, and a single ConcreteProduct class could handle the whole thing. Each of the classes representing a ConcreteProduct class was no smaller than the single <em> general</em> ConcreteProduct; so it did not necessitate bloating a class to cut down on the number of classes.</p>
<p>Finally, all of the data for the page are stored in folders for each individual design pattern. Each folder has a single PNG file and 12 text files. All of the contents of the 23 patterns have identical names and the pattern name is keyed to the folder name. Figure 2 shows an overview of the classes, the data folders and the Client connections to the data.<br />
<img src="http://www.as3dp.com/wp-content/uploads/2009/07/layout.png" alt="layout" title="layout" width="459" height="424" class="alignnone size-full wp-image-1156" /></p>
<p><em><strong>Figure 2: </strong>Files and Data Folders</em><br />
As you can see in Figure 2, using multiple design patterns of the same type is no different than using single design patterns or different design patterns simultaneously. All you need is to have your Client hooked in where it needs to make the request.</p>
<p><strong>Files, Files, Everywhere!</strong></p>
<p>Figure 2 shows only five of the needed 23 folders have been completed. Fortunately, only five design patterns are part of the Creational category; so I get a break between stints of the mind-numbing chore of adding text to text files. Adding the remaining folders is a matter of copying and pasting the current ones and then changing most of the text content and replacing the PNG file with the class diagram. If you’re in a hurry for the rest of the patterns you can do it yourself—most of the summaries are direct quotes from The Gang of Four or paraphrased to save space. The same is true with the rest of the materials, but I added the kinds of things that are specific to ActionScript 3.0, and of course the code snippets are all ActionScript 3.0. Figure 3 shows the contents of each folder:</p>
<p><img src="http://www.as3dp.com/wp-content/uploads/2009/07/files.png" alt="files" title="files" width="512" height="350" class="alignnone size-full wp-image-1158" /><br />
<em><strong>Figure 3: </strong>Text and Graphic files</em></p>
<p>Because all of the headers are the same, none of them have to be changed, and some of the text files are simply single words such as the name of the design pattern or the type of pattern. Using the <em>WhatVaries</em> AIR app, it’s easy to get what varies in each pattern as well. However, getting all of the text for components (participants), code examples and uses can be tricky because there’s only limited space for each.</p>
<p>While it may be tedious to enter all of the data for each and every design pattern, you’ll learn a lot—especially if you are using the Gang of Four’s book or <em>ActionScript 3.0 Design Patterns</em>. Also, there’s a lot of information on this blog you can use to fill out the data.</p>
<p>To add further design patterns here’s all you have to do:</p>
<ul>
<li>Copy and paste one of the current design pattern folders and all of its contents and then rename it using lower case no-space name. For example, the Chain of Responsibility can be named <strong>cor</strong>  </li>
<li>Add the label name and the data name of the design pattern in the CatData class. Use the <em>same</em> lowercase name for the data name as you used to name the folder for the pattern. </li>
<li>Draw a class diagram with a width no greater than 500px and save it as a PNG file using the name, <em>diagram.png</em> in the folder where you have the other files for the pattern.  </li>
<li>Open the text files and change the content to reflect the characteristics of the design pattern. The files with “head” in the filename (e.g., codehead.txt) should be left unchanged but still have to be in the folder </li>
</ul>
<p>That’s it. It also reflects what I like about design patterns. Once you get the basic structure set up; changes and reuse are easy.</p>
<p><strong>The Page-Making Factory</strong></p>
<p>Since we’re reusing a design pattern, you can review it at <a href=http://www.as3dp.com/2009/06/16/friends-with-benefits-refactoring-with-multiple-design-patterns—part-i/>Refactoring with Multiple Design Patterns </a>. However, to understand how the new use of the Factory Method works, each of the classes are reviewed here.</p>
<p>First of all, the Client is remarkably clean, and all requests, other than the initial one to provide data for the List component, relies on user-input in the List menu. <em>Only a single conditional statement</em> is used anywhere in this application, and it can be found in the Client where checking content in the DisplayObject. So you’ll find a very simple Client making requests for data and to see the content of a design pattern.  The following listing shows what little code is required in the Client class:</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('p1151code6'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p11516"><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
46
47
48
49
50
</pre></td><td class="code" id="p1151code6"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> fl.<span style="color: #006600;">controls</span>.<span style="color: #0066CC;">List</span>;
	<span style="color: #0066CC;">import</span> fl.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">DataProvider</span>;
	<span style="color: #0066CC;">import</span> fl.<span style="color: #006600;">events</span>.<span style="color: #006600;">ListEvent</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">//Client Class</span>
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Client <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> factory:Creator = <span style="color: #000000; font-weight: bold;">new</span> ConcreteCreator  ;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> catalog:DataProvider;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">list</span>:<span style="color: #0066CC;">List</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">List</span>  ;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> dp:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> dpDisplay:Sprite;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Client<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			setMenu<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> setMenu<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">//Re-use Factory that provides data for DataProvider</span>
			<span style="color: #000000; font-weight: bold;">var</span> create:DPCreator = <span style="color: #000000; font-weight: bold;">new</span> ConcreteDPCreator  ;
			<span style="color: #000000; font-weight: bold;">var</span> catalog:DataProvider = <span style="color: #000000; font-weight: bold;">new</span> DataProvider  ;
			catalog = create.<span style="color: #006600;">selectData</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #808080; font-style: italic;">//Set up the list</span>
			<span style="color: #0066CC;">list</span>.<span style="color: #006600;">setSize</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">126</span>,<span style="color: #cc66cc;">650</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">list</span>.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">0</span>,<span style="color: #0066CC;">list</span>.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">0</span>;
			<span style="color: #0066CC;">list</span>.<span style="color: #006600;">dataProvider</span> = catalog;
			addChild<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">list</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">list</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>ListEvent.<span style="color: #006600;">ITEM_CLICK</span>,choosePattern<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> choosePattern<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:ListEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			dp = <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">item</span>.<span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #808080; font-style: italic;">//Only conditional in the entire program</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>dpDisplay<span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				removeChild<span style="color: #66cc66;">&#40;</span>dpDisplay<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			dpDisplay = factory.<span style="color: #006600;">makeDP</span><span style="color: #66cc66;">&#40;</span>dp<span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span>dpDisplay<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>As you can see, once the List menu is set up, the choosePattern() method does all the work. Further it is accomplished using very little code.</p>
<p>The next class is the Creator. It supplies the interface for the factory. As an abstract class, it cannot be instantiated, but you can include implemented methods. In this case, one method is implemented and the other is abstract.</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('p1151code7'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p11517"><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
</pre></td><td class="code" id="p1151code7"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//Asbstract class</span>
	<span style="color: #808080; font-style: italic;">//Creator</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">errors</span>.<span style="color: #006600;">IllegalOperationError</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Creator
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> dpNow:Sprite;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> makeDP<span style="color: #66cc66;">&#40;</span>dp:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:Sprite
		<span style="color: #66cc66;">&#123;</span>
			dpNow = chooseDP<span style="color: #66cc66;">&#40;</span>dp<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">return</span> dpNow;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">// ABSTRACT Method (must be overridden in a subclass)</span>
		protected <span style="color: #000000; font-weight: bold;">function</span> chooseDP<span style="color: #66cc66;">&#40;</span>dp:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:Sprite
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> IllegalOperationError<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Abstract method: must be overridden in a subclass&quot;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">null</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>The factory itself is a subclass of the abstract Creator class. It must implement the abstract method, and really nothing else. Originally when I had planned on individual ConcreteProduct classes for each design pattern, I had a big <strong>switch</strong> statement with 23 cases. However, by adding a parameter to the Catalog constructor (the ConcreteProduct class), all that’s passed is a string based on the List selected item’s data value.</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('p1151code8'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p11518"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p1151code8"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">//Factory</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">errors</span>.<span style="color: #006600;">IllegalOperationError</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ConcreteCreator <span style="color: #0066CC;">extends</span> Creator
	<span style="color: #66cc66;">&#123;</span>
		override protected <span style="color: #000000; font-weight: bold;">function</span> chooseDP<span style="color: #66cc66;">&#40;</span>dp:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:Sprite
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Catalog<span style="color: #66cc66;">&#40;</span>dp<span style="color: #66cc66;">&#41;</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><strong>The Product and Concrete Product Classes</strong></p>
<p>The <strong>big</strong> classes in this application are the two that handle the product elements. That should not come as a surprise because the product is pretty big—12 text fields with text and a graphic file. The abstract Product class has both abstract and implemented methods and lots of them.  With 284 lines of code (including spaces and comments), this was the biggest abstract class I’d ever created. Half the methods are abstract and the other half are implemented. Essentially, it works like a giant getter/setter—or loader/placer to be more precise. Once each load is complete, a mirror function (method) “catches” the loaded materials and places it where it belongs on the DisplayObject (<em>aka</em> stage).</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('p1151code9'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p11519"><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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
</pre></td><td class="code" id="p1151code9"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">errors</span>.<span style="color: #006600;">IllegalOperationError</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLLoader</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #0066CC;">TextField</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #006600;">TextFieldType</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #0066CC;">TextFormat</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">//Abstract class</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Product <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> loadCheck:URLLoader;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> txtFld:<span style="color: #0066CC;">TextField</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> typeFld:<span style="color: #0066CC;">TextField</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> sumHeadFld:<span style="color: #0066CC;">TextField</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> sumFld:<span style="color: #0066CC;">TextField</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> varyHeadFld:<span style="color: #0066CC;">TextField</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> varyFld:<span style="color: #0066CC;">TextField</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> usesHeadFld:<span style="color: #0066CC;">TextField</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> usesFld:<span style="color: #0066CC;">TextField</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> codeHeadFld:<span style="color: #0066CC;">TextField</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> codeFld:<span style="color: #0066CC;">TextField</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> comHeadFld:<span style="color: #0066CC;">TextField</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> comFld:<span style="color: #0066CC;">TextField</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">textFormat</span>:<span style="color: #0066CC;">TextFormat</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextFormat</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">private</span> const <span style="color: #0066CC;">TEXTCOLOR</span>:uint = 0x263248;
		<span style="color: #0066CC;">private</span> const TYPECOLOR:uint = 0xFF9800;
		<span style="color: #0066CC;">private</span> const HEADCOLOR:uint = 0x263248;
		<span style="color: #0066CC;">private</span> const BODYCOLOR:uint = 0x000000;
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> loadInfo<span style="color: #66cc66;">&#40;</span>txtInfo:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> IllegalOperationError<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Abstract method: must be overridden in a subclass&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> loadType<span style="color: #66cc66;">&#40;</span>txtInfo:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> IllegalOperationError<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Abstract method: must be overridden in a subclass&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> loadSumHead<span style="color: #66cc66;">&#40;</span>txtInfo:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> IllegalOperationError<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Abstract method: must be overridden in a subclass&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> loadSum<span style="color: #66cc66;">&#40;</span>txtInfo:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> IllegalOperationError<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Abstract method: must be overridden in a subclass&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> loadVaryHead<span style="color: #66cc66;">&#40;</span>txtInfo:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> IllegalOperationError<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Abstract method: must be overridden in a subclass&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> loadVary<span style="color: #66cc66;">&#40;</span>txtInfo:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> IllegalOperationError<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Abstract method: must be overridden in a subclass&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> loadUsesHead<span style="color: #66cc66;">&#40;</span>txtInfo:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> IllegalOperationError<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Abstract method: must be overridden in a subclass&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> loadUses<span style="color: #66cc66;">&#40;</span>txtInfo:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> IllegalOperationError<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Abstract method: must be overridden in a subclass&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> loadCodeHead<span style="color: #66cc66;">&#40;</span>txtInfo:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> IllegalOperationError<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Abstract method: must be overridden in a subclass&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> loadCode<span style="color: #66cc66;">&#40;</span>txtInfo:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> IllegalOperationError<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Abstract method: must be overridden in a subclass&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> loadComHead<span style="color: #66cc66;">&#40;</span>txtInfo:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> IllegalOperationError<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Abstract method: must be overridden in a subclass&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> loadCom<span style="color: #66cc66;">&#40;</span>txtInfo:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> IllegalOperationError<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Abstract method: must be overridden in a subclass&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">//Already Loaded</span>
		protected <span style="color: #000000; font-weight: bold;">function</span> nowLoaded<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			loadCheck = URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">textFormat</span>.<span style="color: #0066CC;">font</span> = <span style="color: #ff0000;">&quot;Arial Black&quot;</span>;
			<span style="color: #0066CC;">textFormat</span>.<span style="color: #0066CC;">size</span> = <span style="color: #cc66cc;">18</span>;
			txtFld.<span style="color: #0066CC;">type</span> = TextFieldType.<span style="color: #0066CC;">DYNAMIC</span>;
			txtFld.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">300</span>;
			txtFld.<span style="color: #0066CC;">wordWrap</span> = <span style="color: #000000; font-weight: bold;">true</span>;
			txtFld.<span style="color: #0066CC;">textColor</span> = <span style="color: #0066CC;">TEXTCOLOR</span>;
			txtFld.<span style="color: #006600;">defaultTextFormat</span> = <span style="color: #0066CC;">textFormat</span>;
			txtFld.<span style="color: #0066CC;">text</span> = loadCheck.<span style="color: #0066CC;">data</span>;
			addChild<span style="color: #66cc66;">&#40;</span>txtFld<span style="color: #66cc66;">&#41;</span>;
			txtFld.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">128</span>,txtFld.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">10</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> nowType<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			loadCheck = URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">textFormat</span>.<span style="color: #0066CC;">font</span> = <span style="color: #ff0000;">&quot;Arial Black&quot;</span>;
			<span style="color: #0066CC;">textFormat</span>.<span style="color: #0066CC;">size</span> = <span style="color: #cc66cc;">14</span>;
			typeFld.<span style="color: #0066CC;">type</span> = TextFieldType.<span style="color: #0066CC;">DYNAMIC</span>;
			typeFld.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">300</span>;
			typeFld.<span style="color: #0066CC;">wordWrap</span> = <span style="color: #000000; font-weight: bold;">true</span>;
			typeFld.<span style="color: #0066CC;">textColor</span> = TYPECOLOR;
			typeFld.<span style="color: #006600;">defaultTextFormat</span> = <span style="color: #0066CC;">textFormat</span>;
			typeFld.<span style="color: #0066CC;">text</span> = loadCheck.<span style="color: #0066CC;">data</span>;
			addChild<span style="color: #66cc66;">&#40;</span>typeFld<span style="color: #66cc66;">&#41;</span>;
			typeFld.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">368</span>,typeFld.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">16</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> nowSumHead<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			loadCheck = URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">textFormat</span>.<span style="color: #0066CC;">font</span> = <span style="color: #ff0000;">&quot;Arial Black&quot;</span>;
			<span style="color: #0066CC;">textFormat</span>.<span style="color: #0066CC;">size</span> = <span style="color: #cc66cc;">14</span>;
			sumHeadFld.<span style="color: #0066CC;">type</span> = TextFieldType.<span style="color: #0066CC;">DYNAMIC</span>;
			sumHeadFld.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">175</span>;
			sumHeadFld.<span style="color: #0066CC;">wordWrap</span> = <span style="color: #000000; font-weight: bold;">true</span>;
			sumHeadFld.<span style="color: #0066CC;">textColor</span> = HEADCOLOR;
			sumHeadFld.<span style="color: #006600;">defaultTextFormat</span> = <span style="color: #0066CC;">textFormat</span>;
			sumHeadFld.<span style="color: #0066CC;">text</span> = loadCheck.<span style="color: #0066CC;">data</span>;
			addChild<span style="color: #66cc66;">&#40;</span>sumHeadFld<span style="color: #66cc66;">&#41;</span>;
			sumHeadFld.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">148</span>,sumHeadFld.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">409</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> nowSum<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			loadCheck = URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">textFormat</span>.<span style="color: #0066CC;">font</span> = <span style="color: #ff0000;">&quot;Arial&quot;</span>;
			<span style="color: #0066CC;">textFormat</span>.<span style="color: #0066CC;">size</span> = <span style="color: #cc66cc;">12</span>;
			sumFld.<span style="color: #0066CC;">type</span> = TextFieldType.<span style="color: #0066CC;">DYNAMIC</span>;
			sumFld.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">200</span>;
			sumFld.<span style="color: #0066CC;">wordWrap</span> = <span style="color: #000000; font-weight: bold;">true</span>;
			sumFld.<span style="color: #0066CC;">textColor</span> = BODYCOLOR;
			sumFld.<span style="color: #006600;">defaultTextFormat</span> = <span style="color: #0066CC;">textFormat</span>;
			sumFld.<span style="color: #0066CC;">text</span> = loadCheck.<span style="color: #0066CC;">data</span>;
			addChild<span style="color: #66cc66;">&#40;</span>sumFld<span style="color: #66cc66;">&#41;</span>;
			sumFld.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">148</span>,sumFld.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">431</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> nowVaryHead<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			loadCheck = URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">textFormat</span>.<span style="color: #0066CC;">font</span> = <span style="color: #ff0000;">&quot;Arial Black&quot;</span>;
			<span style="color: #0066CC;">textFormat</span>.<span style="color: #0066CC;">size</span> = <span style="color: #cc66cc;">14</span>;
			varyHeadFld.<span style="color: #0066CC;">type</span> = TextFieldType.<span style="color: #0066CC;">DYNAMIC</span>;
			varyHeadFld.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">175</span>;
			varyHeadFld.<span style="color: #0066CC;">wordWrap</span> = <span style="color: #000000; font-weight: bold;">true</span>;
			varyHeadFld.<span style="color: #0066CC;">textColor</span> = HEADCOLOR;
			varyHeadFld.<span style="color: #006600;">defaultTextFormat</span> = <span style="color: #0066CC;">textFormat</span>;
			varyHeadFld.<span style="color: #0066CC;">text</span> = loadCheck.<span style="color: #0066CC;">data</span>;
			addChild<span style="color: #66cc66;">&#40;</span>varyHeadFld<span style="color: #66cc66;">&#41;</span>;
			varyHeadFld.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">684</span>,varyHeadFld.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">409</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> nowVary<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			loadCheck = URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">textFormat</span>.<span style="color: #0066CC;">font</span> = <span style="color: #ff0000;">&quot;Arial&quot;</span>;
			<span style="color: #0066CC;">textFormat</span>.<span style="color: #0066CC;">size</span> = <span style="color: #cc66cc;">12</span>;
			varyFld.<span style="color: #0066CC;">type</span> = TextFieldType.<span style="color: #0066CC;">DYNAMIC</span>;
			varyFld.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">175</span>;
			varyFld.<span style="color: #0066CC;">wordWrap</span> = <span style="color: #000000; font-weight: bold;">true</span>;
			varyFld.<span style="color: #0066CC;">textColor</span> = BODYCOLOR;
			varyFld.<span style="color: #006600;">defaultTextFormat</span> = <span style="color: #0066CC;">textFormat</span>;
			varyFld.<span style="color: #0066CC;">text</span> = loadCheck.<span style="color: #0066CC;">data</span>;
			addChild<span style="color: #66cc66;">&#40;</span>varyFld<span style="color: #66cc66;">&#41;</span>;
			varyFld.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">684</span>,varyFld.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">431</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> nowUsesHead<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			loadCheck = URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">textFormat</span>.<span style="color: #0066CC;">font</span> = <span style="color: #ff0000;">&quot;Arial Black&quot;</span>;
			<span style="color: #0066CC;">textFormat</span>.<span style="color: #0066CC;">size</span> = <span style="color: #cc66cc;">14</span>;
			usesHeadFld.<span style="color: #0066CC;">type</span> = TextFieldType.<span style="color: #0066CC;">DYNAMIC</span>;
			usesHeadFld.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">175</span>;
			usesHeadFld.<span style="color: #0066CC;">wordWrap</span> = <span style="color: #000000; font-weight: bold;">true</span>;
			usesHeadFld.<span style="color: #0066CC;">textColor</span> = HEADCOLOR;
			usesHeadFld.<span style="color: #006600;">defaultTextFormat</span> = <span style="color: #0066CC;">textFormat</span>;
			usesHeadFld.<span style="color: #0066CC;">text</span> = loadCheck.<span style="color: #0066CC;">data</span>;
			addChild<span style="color: #66cc66;">&#40;</span>usesHeadFld<span style="color: #66cc66;">&#41;</span>;
			usesHeadFld.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">148</span>,usesHeadFld.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">504</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> nowUses<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			loadCheck = URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">textFormat</span>.<span style="color: #0066CC;">font</span> = <span style="color: #ff0000;">&quot;Arial&quot;</span>;
			<span style="color: #0066CC;">textFormat</span>.<span style="color: #0066CC;">size</span> = <span style="color: #cc66cc;">12</span>;
			usesFld.<span style="color: #0066CC;">type</span> = TextFieldType.<span style="color: #0066CC;">DYNAMIC</span>;
			usesFld.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">175</span>;
			usesFld.<span style="color: #0066CC;">wordWrap</span> = <span style="color: #000000; font-weight: bold;">true</span>;
			usesFld.<span style="color: #0066CC;">textColor</span> = BODYCOLOR;
			usesFld.<span style="color: #006600;">defaultTextFormat</span> = <span style="color: #0066CC;">textFormat</span>;
			usesFld.<span style="color: #0066CC;">text</span> = loadCheck.<span style="color: #0066CC;">data</span>;
			addChild<span style="color: #66cc66;">&#40;</span>usesFld<span style="color: #66cc66;">&#41;</span>;
			usesFld.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">148</span>,usesFld.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">528</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> nowCodeHead<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			loadCheck = URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">textFormat</span>.<span style="color: #0066CC;">font</span> = <span style="color: #ff0000;">&quot;Arial Black&quot;</span>;
			<span style="color: #0066CC;">textFormat</span>.<span style="color: #0066CC;">size</span> = <span style="color: #cc66cc;">14</span>;
			codeHeadFld.<span style="color: #0066CC;">type</span> = TextFieldType.<span style="color: #0066CC;">DYNAMIC</span>;
			codeHeadFld.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">175</span>;
			codeHeadFld.<span style="color: #0066CC;">wordWrap</span> = <span style="color: #000000; font-weight: bold;">true</span>;
			codeHeadFld.<span style="color: #0066CC;">textColor</span> = HEADCOLOR;
			codeHeadFld.<span style="color: #006600;">defaultTextFormat</span> = <span style="color: #0066CC;">textFormat</span>;
			codeHeadFld.<span style="color: #0066CC;">text</span> = loadCheck.<span style="color: #0066CC;">data</span>;
			addChild<span style="color: #66cc66;">&#40;</span>codeHeadFld<span style="color: #66cc66;">&#41;</span>;
			codeHeadFld.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">350</span>,codeHeadFld.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">409</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> nowCode<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			loadCheck = URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">textFormat</span>.<span style="color: #0066CC;">font</span> = <span style="color: #ff0000;">&quot;Courier New&quot;</span>;
			<span style="color: #0066CC;">textFormat</span>.<span style="color: #0066CC;">size</span> = <span style="color: #cc66cc;">12</span>;
			codeFld.<span style="color: #0066CC;">type</span> = TextFieldType.<span style="color: #0066CC;">DYNAMIC</span>;
			codeFld.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">323</span>;
			codeFld.<span style="color: #0066CC;">height</span> = <span style="color: #cc66cc;">215</span>;
			codeFld.<span style="color: #0066CC;">wordWrap</span> = <span style="color: #000000; font-weight: bold;">true</span>;
			codeFld.<span style="color: #0066CC;">textColor</span> = BODYCOLOR;
			codeFld.<span style="color: #006600;">defaultTextFormat</span> = <span style="color: #0066CC;">textFormat</span>;
			codeFld.<span style="color: #0066CC;">text</span> = loadCheck.<span style="color: #0066CC;">data</span>;
			addChild<span style="color: #66cc66;">&#40;</span>codeFld<span style="color: #66cc66;">&#41;</span>;
			codeFld.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">350</span>,codeFld.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">430</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> nowComHead<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			loadCheck = URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">textFormat</span>.<span style="color: #0066CC;">font</span> = <span style="color: #ff0000;">&quot;Arial Black&quot;</span>;
			<span style="color: #0066CC;">textFormat</span>.<span style="color: #0066CC;">size</span> = <span style="color: #cc66cc;">14</span>;
			comHeadFld.<span style="color: #0066CC;">type</span> = TextFieldType.<span style="color: #0066CC;">DYNAMIC</span>;
			comHeadFld.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">175</span>;
			comHeadFld.<span style="color: #0066CC;">wordWrap</span> = <span style="color: #000000; font-weight: bold;">true</span>;
			comHeadFld.<span style="color: #0066CC;">textColor</span> = HEADCOLOR;
			comHeadFld.<span style="color: #006600;">defaultTextFormat</span> = <span style="color: #0066CC;">textFormat</span>;
			comHeadFld.<span style="color: #0066CC;">text</span> = loadCheck.<span style="color: #0066CC;">data</span>;
			addChild<span style="color: #66cc66;">&#40;</span>comHeadFld<span style="color: #66cc66;">&#41;</span>;
			comHeadFld.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">684</span>,comHeadFld.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">458</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> nowCom<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			loadCheck = URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">textFormat</span>.<span style="color: #0066CC;">font</span> = <span style="color: #ff0000;">&quot;Arial&quot;</span>;
			<span style="color: #0066CC;">textFormat</span>.<span style="color: #0066CC;">size</span> = <span style="color: #cc66cc;">12</span>;
			comFld.<span style="color: #0066CC;">type</span> = TextFieldType.<span style="color: #0066CC;">DYNAMIC</span>;
			comFld.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">242</span>;
			comFld.<span style="color: #0066CC;">height</span> = <span style="color: #cc66cc;">164</span>;
			comFld.<span style="color: #0066CC;">wordWrap</span> = <span style="color: #000000; font-weight: bold;">true</span>;
			comFld.<span style="color: #0066CC;">textColor</span> = BODYCOLOR;
			comFld.<span style="color: #006600;">defaultTextFormat</span> = <span style="color: #0066CC;">textFormat</span>;
			comFld.<span style="color: #0066CC;">text</span> = loadCheck.<span style="color: #0066CC;">data</span>;
			addChild<span style="color: #66cc66;">&#40;</span>comFld<span style="color: #66cc66;">&#41;</span>;
			comFld.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">684</span>,comFld.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">480</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #808080; font-style: italic;">//Load Image</span>
		protected <span style="color: #000000; font-weight: bold;">function</span> loadImg<span style="color: #66cc66;">&#40;</span>img:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> IllegalOperationError<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Abstract method: must be overridden in a subclass&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Each implemented method works the same. It gets the Event instance from the loading sequence (implemented in the Catalog class—a Concrete Product) and then puts it where it belongs and formats it.</p>
<p>Finally, the ConcreteProduct is the Catalog class. It loads all of the materials it needs and then uses the methods it inherited from the Product class to place the text and graphic.</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('p1151code10'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p115110"><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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
</pre></td><td class="code" id="p1151code10"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLRequest</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Loader</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLRequest</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLLoader</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Catalog <span style="color: #0066CC;">extends</span> Product
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> dp:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> nameText:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> typeText:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> sumHead:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> sumText:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> varyHead:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> varyText:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> usesHead:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> usesText:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> codeHead:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> codeText:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> comHead:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> comText:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> dpImage:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">url</span>:URLRequest;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> loader:Loader;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> fileNow:URLRequest;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> txtLoader:URLLoader;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> typeLoader:URLLoader;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> sumHeadLoader:URLLoader;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> sumLoader:URLLoader;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> varyHeadLoader:URLLoader;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> varyLoader:URLLoader;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> usesHeadLoader:URLLoader;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> usesLoader:URLLoader;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> codeHeadLoader:URLLoader;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> codeLoader:URLLoader;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> comHeadLoader:URLLoader;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> comLoader:URLLoader;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> loadCheck:URLLoader;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Catalog<span style="color: #66cc66;">&#40;</span>dp:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">dp</span>=dp;
			dp+=<span style="color: #ff0000;">&quot;/&quot;</span>;
			nameText = dp + <span style="color: #ff0000;">&quot;name.txt&quot;</span>;
			typeText = dp + <span style="color: #ff0000;">&quot;type.txt&quot;</span>;
			sumHead = dp + <span style="color: #ff0000;">&quot;sumhead.txt&quot;</span>;
			sumText = dp + <span style="color: #ff0000;">&quot;summary.txt&quot;</span>;
			varyHead = dp + <span style="color: #ff0000;">&quot;varyhead.txt&quot;</span>;
			varyText = dp + <span style="color: #ff0000;">&quot;vary.txt&quot;</span>;
			usesHead = dp + <span style="color: #ff0000;">&quot;useshead.txt&quot;</span>;
			usesText = dp + <span style="color: #ff0000;">&quot;uses.txt&quot;</span>;
			codeHead = dp + <span style="color: #ff0000;">&quot;codehead.txt&quot;</span>;
			codeText = dp + <span style="color: #ff0000;">&quot;code.txt&quot;</span>;
			comHead = dp + <span style="color: #ff0000;">&quot;comhead.txt&quot;</span>;
			comText = dp + <span style="color: #ff0000;">&quot;com.txt&quot;</span>;
			dpImage = dp + <span style="color: #ff0000;">&quot;diagram.png&quot;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">//All of these function are below</span>
			loadInfo<span style="color: #66cc66;">&#40;</span>nameText<span style="color: #66cc66;">&#41;</span>;
			loadType<span style="color: #66cc66;">&#40;</span>typeText<span style="color: #66cc66;">&#41;</span>;
			loadSumHead<span style="color: #66cc66;">&#40;</span>sumHead<span style="color: #66cc66;">&#41;</span>;
			loadSum<span style="color: #66cc66;">&#40;</span>sumText<span style="color: #66cc66;">&#41;</span>;
			loadVaryHead<span style="color: #66cc66;">&#40;</span>varyHead<span style="color: #66cc66;">&#41;</span>;
			loadVary<span style="color: #66cc66;">&#40;</span>varyText<span style="color: #66cc66;">&#41;</span>;
			loadUsesHead<span style="color: #66cc66;">&#40;</span>usesHead<span style="color: #66cc66;">&#41;</span>;
			loadUses<span style="color: #66cc66;">&#40;</span>usesText<span style="color: #66cc66;">&#41;</span>;
			loadCodeHead<span style="color: #66cc66;">&#40;</span>codeHead<span style="color: #66cc66;">&#41;</span>;
			loadCode<span style="color: #66cc66;">&#40;</span>codeText<span style="color: #66cc66;">&#41;</span>;
			loadComHead<span style="color: #66cc66;">&#40;</span>comHead<span style="color: #66cc66;">&#41;</span>;
			loadCom<span style="color: #66cc66;">&#40;</span>comText<span style="color: #66cc66;">&#41;</span>;
			loadImg<span style="color: #66cc66;">&#40;</span>dpImage<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		override protected <span style="color: #000000; font-weight: bold;">function</span> loadInfo<span style="color: #66cc66;">&#40;</span>txtInfo:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			txtLoader = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			txtLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>,nowLoaded<span style="color: #66cc66;">&#41;</span>;
			fileNow = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span>txtInfo<span style="color: #66cc66;">&#41;</span>;
			txtLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>fileNow<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		override protected <span style="color: #000000; font-weight: bold;">function</span> loadType<span style="color: #66cc66;">&#40;</span>txtInfo:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			typeLoader = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			typeLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>,nowType<span style="color: #66cc66;">&#41;</span>;
			fileNow = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span>txtInfo<span style="color: #66cc66;">&#41;</span>;
			typeLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>fileNow<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		override protected <span style="color: #000000; font-weight: bold;">function</span> loadSumHead<span style="color: #66cc66;">&#40;</span>txtInfo:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			sumHeadLoader = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			sumHeadLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>,nowSumHead<span style="color: #66cc66;">&#41;</span>;
			fileNow = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span>txtInfo<span style="color: #66cc66;">&#41;</span>;
			sumHeadLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>fileNow<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		override protected <span style="color: #000000; font-weight: bold;">function</span> loadSum<span style="color: #66cc66;">&#40;</span>txtInfo:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			sumLoader = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			sumLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>,nowSum<span style="color: #66cc66;">&#41;</span>;
			fileNow = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span>txtInfo<span style="color: #66cc66;">&#41;</span>;
			sumLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>fileNow<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		override protected <span style="color: #000000; font-weight: bold;">function</span> loadVaryHead<span style="color: #66cc66;">&#40;</span>txtInfo:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			varyHeadLoader = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			varyHeadLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>,nowVaryHead<span style="color: #66cc66;">&#41;</span>;
			fileNow = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span>txtInfo<span style="color: #66cc66;">&#41;</span>;
			varyHeadLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>fileNow<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		override protected <span style="color: #000000; font-weight: bold;">function</span> loadVary<span style="color: #66cc66;">&#40;</span>txtInfo:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			varyLoader = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			varyLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>,nowVary<span style="color: #66cc66;">&#41;</span>;
			fileNow = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span>txtInfo<span style="color: #66cc66;">&#41;</span>;
			varyLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>fileNow<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		override protected <span style="color: #000000; font-weight: bold;">function</span> loadUsesHead<span style="color: #66cc66;">&#40;</span>txtInfo:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			usesHeadLoader = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			usesHeadLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>,nowUsesHead<span style="color: #66cc66;">&#41;</span>;
			fileNow = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span>txtInfo<span style="color: #66cc66;">&#41;</span>;
			usesHeadLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>fileNow<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		override protected <span style="color: #000000; font-weight: bold;">function</span> loadUses<span style="color: #66cc66;">&#40;</span>txtInfo:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			usesLoader = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			usesLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>,nowUses<span style="color: #66cc66;">&#41;</span>;
			fileNow = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span>txtInfo<span style="color: #66cc66;">&#41;</span>;
			usesLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>fileNow<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		override protected <span style="color: #000000; font-weight: bold;">function</span> loadCodeHead<span style="color: #66cc66;">&#40;</span>txtInfo:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			codeHeadLoader = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			codeHeadLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>,nowCodeHead<span style="color: #66cc66;">&#41;</span>;
			fileNow = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span>txtInfo<span style="color: #66cc66;">&#41;</span>;
			codeHeadLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>fileNow<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		override protected <span style="color: #000000; font-weight: bold;">function</span> loadCode<span style="color: #66cc66;">&#40;</span>txtInfo:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			codeLoader = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			codeLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>,nowCode<span style="color: #66cc66;">&#41;</span>;
			fileNow = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span>txtInfo<span style="color: #66cc66;">&#41;</span>;
			codeLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>fileNow<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		override protected <span style="color: #000000; font-weight: bold;">function</span> loadComHead<span style="color: #66cc66;">&#40;</span>txtInfo:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			comHeadLoader = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			comHeadLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>,nowComHead<span style="color: #66cc66;">&#41;</span>;
			fileNow = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span>txtInfo<span style="color: #66cc66;">&#41;</span>;
			comHeadLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>fileNow<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		override protected <span style="color: #000000; font-weight: bold;">function</span> loadCom<span style="color: #66cc66;">&#40;</span>txtInfo:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			comLoader = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			comLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>,nowCom<span style="color: #66cc66;">&#41;</span>;
			fileNow = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span>txtInfo<span style="color: #66cc66;">&#41;</span>;
			comLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>fileNow<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">//Load image</span>
		override protected <span style="color: #000000; font-weight: bold;">function</span> loadImg<span style="color: #66cc66;">&#40;</span>dpImage:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">url</span> = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span>dpImage<span style="color: #66cc66;">&#41;</span>;
			loader=<span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			loader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span>loader<span style="color: #66cc66;">&#41;</span>;
			loader.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">128</span>,loader.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">34</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>That’s the whole enchilada, and it is a big one. Both of the product classes are much bigger than I like, but the nature of the application requires it. However, even with all of the methods and instances in two different Factory Method class sets, there’s only a single conditional statement, and it’s in the Client—where it doesn’t count as part of the design pattern. (I could even eliminate it if I put in a dummy display sprite—but why go fanatic?)</p>
<p><strong>Finishing Up</strong></p>
<p>All that’s left are 17 more design patterns and some kind of splash page. I think that the splash page should have the different elements of the UML class diagrams—what the different arrows and symbols mean.  If you can think of anything else, let us know. Also, play around with the AIR version and let me know if you have any additional features that you think would help. Also, if you want to pitch in and help fill in the different design patterns data, contact me and I’ll be glad to recruit you! (Is there such a thing as an online <strong>Hero Medal</strong>?)</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.as3dp.com%2F2009%2F07%2Factionscript-30-design-pattern-catalog-creational-patterns%2F&amp;title=ActionScript%203.0%20Design%20Pattern%20Catalog%3A%20Creational%20Patterns" id="wpa2a_4"><img src="http://www.as3dp.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.as3dp.com/2009/07/actionscript-30-design-pattern-catalog-creational-patterns/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Deciding on a Design Pattern: A Graphic and Text Catalog</title>
		<link>http://www.as3dp.com/2009/07/deciding-on-a-design-pattern-a-graphic-and-text-catalog/</link>
		<comments>http://www.as3dp.com/2009/07/deciding-on-a-design-pattern-a-graphic-and-text-catalog/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 10:10:28 +0000</pubDate>
		<dc:creator>William B. Sanders</dc:creator>
				<category><![CDATA[Catalog]]></category>

		<guid isPermaLink="false">http://www.as3dp.com/?p=1134</guid>
		<description><![CDATA[How to Decide on a Design Pattern I don’t want to beat around the bush here, so I’ll just come right out and say it, Choosing a design pattern can be tricky. For most of you, this is nothing new. Even with the help of the Magic Table that shows what varies for each design [...]]]></description>
			<content:encoded><![CDATA[<p><strong>How to Decide on a Design Pattern</strong></p>
<p>I don’t want to beat around the bush here, so I’ll just come right out and say it,<br />
<blockquote>Choosing a design pattern can be tricky.</p></blockquote>
<p>For most of you, this is nothing new. Even with the help of the <a href="http://www.as3dp.com/2009/06/12/the-developing-an-air-actionscript-30-design-pattern-catalog-and-the-air-magic-table/">Magic Table</a> that shows what varies for each design pattern, I find that while the table is useful for eliminating certain patterns, it’s not as useful for pinning down the exact design pattern that should be used. So here is a case where you, as a reader, can help decide which pattern is best suited for creating the design pattern catalog that will be placed into an AIR application.</p>
<p>First, let’s look at the goal. Based on feedback from this blog, the conventions established by the Gang of Four as well as what I found useful, I came up with what each catalog page will display, as shown in Figure 1:</p>
<p><img src="http://www.as3dp.com/wp-content/uploads/2009/07/catpage.png" alt="catpage" title="catpage" width="500" height="374" class="alignnone size-full wp-image-1135" /><br />
<em><strong>Figure 1: </strong>Mockup of Catalog Page</em></p>
<p>The idea is to have a single page with all of the data externally loaded. The class diagrams are to be a graphic image (including the text in the diagram), and everything else will be text. The text fields will either be for headers or body text, and the body text will have styles for normal text and code text (Arial for the former and Courier New for the latter). The color scheme, “Dusty Petrol” from Kuler, seemed to be a nice combination of colors without any jarring contrasts.<br />
<span id="more-1134"></span><br />
<strong>Key Operations</strong></p>
<p>I like to start with a simple yet clear sketch of what has to be done for accomplish the task at hand. So, I began with the sketch in Figure 2.<br />
<img src="http://www.as3dp.com/wp-content/uploads/2009/07/task.png" alt="task" title="task" width="500" height="390" class="alignnone size-full wp-image-1136" /><br />
<em><strong>Figure 2: </strong>Key Operations</em></p>
<p>As can be seen from Figure 2, the Client needs to make requests to get a graphic and text. The general approach is to load graphics using the Loader class and the text using the URLLoader class. The graphic will be returned as a Sprite object and the loaded text as a string.</p>
<p><strong>A Strategy</strong></p>
<p>As a simple and ever useful design pattern, the Strategy first came to mind. The algorithm could be changed, and new ones added on. In fact, I was thinking of reusing the design I had for the <a href=http://www.as3dp.com/2009/03/08/actionscript-30-easy-and-practical-strategy-design-pattern/>OOP Principles</a> application. However, when I looked at it, I wasn’t so sure. I saw no return elements in the design, but I didn’t need any in creating the application for the principles; so I left it in contention. Figure 3, shows the sketch used in working through the process:<br />
<img src="http://www.as3dp.com/wp-content/uploads/2009/07/strategy.png" alt="strategy" title="strategy" width="500" height="150" class="alignnone size-full wp-image-1138" /><br />
<em><strong>Figure 3: </strong>Strategy pattern</em></p>
<p>The graphics could be loaded simply by using the same structure used for loading SWF files in the Principles app. I’d just have to add a class with algorithms for loading text. Maybe I’d add an algorithm for creating different TextFormat instance for styling the text.</p>
<p><strong>Factory Method</strong></p>
<p>I must have been thinking about the Factory Method when I sketched out the general goal in Figure 2 because I did include returned values. Since I had already built <a href="http://www.as3dp.com/2009/01/15/take-a-design-pattern-to-work-part-iv-establishing-a-design-pattern-foundation/"> an application using the Factory Method</a> maybe I could reuse it. (The implementation of the pattern also included loading both text and graphics.) Figure 4 shows the sketch I came up with to think about using the Factory Method:<br />
<img src="http://www.as3dp.com/wp-content/uploads/2009/07/factory.png" alt="factory" title="factory" width="500" height="255" class="alignnone size-full wp-image-1139" /><br />
<em><strong>Figure 4: </strong>Factory Method pattern</em></p>
<p>After looking at the sketch and going over the Factory Method used previously that generated different products, each using <em>both</em> text and graphics, I realized that I’d either need 23 concrete product classes or I’d have to figure out a way to request 23 of <em>something</em> from the Client. Could the request be made through the creator? Would it be possible for the factory to generate all the strings required and place them in the appropriate text fields and position the graphic? My plan was to make 23 different folders with each item in the folder with the same name (e.g., design.png, name.txt, type.txt, etc.) and then all I’d need to do would be to reference the name of the design pattern make the call like so;</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('p1134code12'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p113412"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p1134code12"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> dp:<span style="color: #0066CC;">String</span>=dpName;
<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">url</span>:<span style="color: #0066CC;">String</span>=dp+ “<span style="color: #66cc66;">/</span>design.<span style="color: #006600;">png</span>”;</pre></td></tr></table></div>

<p>Whether that’s the best idea or not, I’m not sure, but it seems efficient and allows for easy change and loose coupling. Further, if it is a good idea, I still need to determine if the Factory Method is the best approach to the problem.</p>
<p><strong>Chain of Responsibility</strong></p>
<p>In looking at Figure 1, you can see all of the different header and body text loads required, and given the number of chores, I considered the Chain of Responsibility (CoR). I’d just set up concrete handlers for each of the different loads—one for graphics and several for text. Figure 5 shows what I had in mind:<br />
<img src="http://www.as3dp.com/wp-content/uploads/2009/07/cor.png" alt="cor" title="cor" width="500" height="219" class="alignnone size-full wp-image-1140" /><br />
<em><strong>Figure 5: </strong>Chain of Responsibility pattern</em></p>
<p>Initially, I was pretty enthusiastic about the idea, but the more I thought about it, the more I found it inappropriate. The intent of the CoR is to find the best way to handle a request and then have a concrete handler deal with it. I’d have to set up a loop to go through and use <em>all</em> of the concrete handlers for every request. I still like the flexibility of the CoR for this kind of application, and I can easily imagine adding more concrete handlers and changing existing ones.</p>
<p><strong>What About Object Placement?</strong></p>
<p>One of the challenges I seem to face again and again with design patterns using Flash/Flex is displaying objects on the stage. It’s not so much that figuring out the X and Y positions is difficult or the mechanics on plopping an object in a DisplayObject or DisplayObjectContainer, but rather how to take the generated data in the object and then pass it up the line to the point where it is displayed on the stage. On the one hand, I see that UI chores are usually the domain of the Client. The Client only requests the data (text or graphic) but is responsible for the housekeeping task of putting it where it belongs. On the other hand, why should the Client be saddled with a primary task in this kind of application? Further, is object display actually a UI element? Probably not. So, in planning object placement I need to think about passing the container objects (TextField and Sprite objects) from point of origin to the stage.</p>
<p><strong>What About the UI?</strong></p>
<p>As with other applications where the UI is simply a matter setting up some kind of selection object (like a List component), I’m perfectly happy with allowing the Client to instantiate and place it on the stage. However, there’s no reason not to re-use the Factory Method employed in making <a href="http://www.as3dp.com/2009/06/24/friends-with-benefits-state-and-factory-method-together-at-last—part-ii/">a selection UI for a video player</a> to pump information into a DataProvider object. Further, the UI object is the Client’s requesting object; so there’s no need to fret about its instantiation. (That’s about the only easy thing in the whole project.)</p>
<p><strong>Your Ideas, Please</strong></p>
<p>Many readers of this blog have asked,<br />
<blockquote>How do I decide which design pattern to use?</p></blockquote>
<p> Unfortunately, it’s not a nice cut and dry answer. Rather, it’s a process where you look at the programming task and try on different design patterns and think about which one to use. I sketch out the diagrams as you’ve seen. It’s very much a matter of puttering around and trying to figure out what you need to accomplish both immediately and down the road as changes need to be introduced.</p>
<p>Some of you may be wondering why not use the same overall strategy used with the <a herf="http://www.as3dp.com/2009/03/08/actionscript-30-easy-and-practical-strategy-design-pattern"> application that displays the different OOP principles?</a> That application used several different SWF files where the text and graphics were combined in a single object. The main reason is that revising a SWF file every time you want to make a change can be awkward. I’d rather have something more granular where changes are simply a matter of modifying text in a text file than an entire SWF file. The graphic class diagrams could be done in Flash, but usually I just use a drawing program and load the drawing into Flash or Flex; so I’m really not saving a lot on the image production anyway if it is part of an SWF file along with the text.</p>
<p>So, I’d be very interested to hear what you have to say. I am open to just about any suggestion so that prior to building the mechanism for putting the ActionScript 3.0 design pattern catalog together I’ve got the best design pattern(s) at work.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.as3dp.com%2F2009%2F07%2Fdeciding-on-a-design-pattern-a-graphic-and-text-catalog%2F&amp;title=Deciding%20on%20a%20Design%20Pattern%3A%20A%20Graphic%20and%20Text%20Catalog" id="wpa2a_6"><img src="http://www.as3dp.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.as3dp.com/2009/07/deciding-on-a-design-pattern-a-graphic-and-text-catalog/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Developing an AIR ActionScript 3.0 Design Pattern Catalog and the AIR Magic Table</title>
		<link>http://www.as3dp.com/2009/06/the-developing-an-air-actionscript-30-design-pattern-catalog-and-the-air-magic-table/</link>
		<comments>http://www.as3dp.com/2009/06/the-developing-an-air-actionscript-30-design-pattern-catalog-and-the-air-magic-table/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 13:49:05 +0000</pubDate>
		<dc:creator>William B. Sanders</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Catalog]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Design Patterns at Work]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.as3dp.com/?p=1070</guid>
		<description><![CDATA[Gentle Reader, this post includes one completed application and one in the works. The AIR ActionScript 3.0 Design Pattern Catalog is meant to be a developer’s aid, and so your ideas of what to include in the catalog is important. We would really appreciate your comments on what you think would be useful in developing [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.as3dp.com/wp-content/uploads/2009/06/magicapp.png" alt="magicapp" title="magicapp" width="111" height="65" class="alignleft size-full wp-image-1071" /><br />
<em><strong>Gentle Reader,</strong> this post includes one completed application and one in the works. The AIR ActionScript 3.0 Design Pattern Catalog is meant to be a developer’s aid, and so your ideas of what to include in the catalog is important. We would really appreciate your comments on what you think would be useful in developing an information template to be used for all of the design patterns.</em></p>
<p>I recently returned from a trip to Prague in the Czech Republic, and I went to work creating a video player for my HD videos I made using a Flip Mino HD camcorder (http://www.sandlight.net/prague). Rather than pulling out and reusing my trusty State Design Pattern player (see Chapter 10), I decided to start from scratch and create a player not using a design pattern. Then I would take the completed video player and use it as an example to show how to refactor a program to a design pattern. (<em>This will be in an upcoming post.</em>) Since I’ve never had to refactor the original program (tweak, maybe but not refactor), and I hadn’t worked with a State pattern lately, I found myself digging up all of the materials on the State Design Pattern. What I wished I had was a handy desktop app that I could click that would show me the essentials of the different design patterns. It would be an <strong>abbreviated design pattern catalog</strong> that could be used like the little <a href="http://www.as3dp.com/2009/02/26/oop-designs-pattern-principles-ready-for-work/">Design Pattern Principles and Lunch Bucket Rules</a> AIR app. Then when I need a quick reference I could use the desktop app to look up the essentials of the pattern.<br />
<span id="more-1070"></span><br />
<strong>What Does a Design Pattern Catalog Need?</strong></p>
<p>Right off the top of my head I came up with the following elements for a quick look-up:</p>
<ul>
<li>Class diagram</li>
<li>Description of what elements vary</li>
<li>Component roles</li>
<li>Common usage </li>
<li>Chapter/Blog reference</li>
<li>Key Code examples</li>
</ul>
<p>The catalog is meant to be a quick reference for someone who has some idea design patterns and wants to check out some elements of different patterns to see if it&#8217;s appropriate for a project. It is not meant to be a complete reference and certainly not a tutorial. Like the little AIR application that brings up the principles in abbreviated format, this application is meant to be a simple guide that will save time over pouring through Web searches or books and articles for basic design pattern information. Figure 1 shows an idea of what each page of the application would look like (given the above criteria). We’d like your comments on further ideas both in content and design. <em>I’m not a designer</em>.<br />
<img src="http://www.as3dp.com/wp-content/uploads/2009/06/catalog.png" alt="catalog" title="catalog" width="500" height="500" class="alignnone size-full wp-image-1072" /></p>
<p><em><strong>Figure 1:</strong> Proposed Template for ActionScript 3.0 Design Pattern Catalog</em></p>
<p>Take a look at Figure 1 and see if you have any suggestions as to how we could make it more useful without going into a detailed explanation of the pattern. Would it be handy? Should anything be added or deleted? Is there a better design? Send in your comments.</p>
<p><strong>The Magic Table in AIR</strong></p>
<p>A while back we had a post on this blog that included what I called <a href="http://www.as3dp.com/2009/03/10/variation-table/"> The Magic Table</a>.  It is a reference to the Gang of Four’s table where they list all of the design patterns and what can vary for the pattern. Anyway, I’ve always found that table useful, and so I created one using a simple DataGrid component. You can <a href="http://www.sandlight.com/magic/">download it here</a>. You can put the AIR app on your desktop and quickly find what can vary with each design pattern. Figure 2 shows what you’ll see.<br />
<!--more--><br />
<img src="http://www.as3dp.com/wp-content/uploads/2009/06/vary.png" alt="vary" title="vary" width="630" height="522" class="alignnone size-full wp-image-1073" /></p>
<p><em><strong>Figure 2:</strong> Encapsulate what varies—Design Pattern Variation Table in AIR</em></p>
<p>If you can make something with better aesthesis, please do so, and we’ll be glad to make it available to our blog readers if it is sent in an AIR file.  In the meantime, we’d like to get your comments on the utility of such tools and ideas to improve them.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.as3dp.com%2F2009%2F06%2Fthe-developing-an-air-actionscript-30-design-pattern-catalog-and-the-air-magic-table%2F&amp;title=The%20Developing%20an%20AIR%20ActionScript%203.0%20Design%20Pattern%20Catalog%20and%20the%20AIR%20Magic%20Table" id="wpa2a_8"><img src="http://www.as3dp.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.as3dp.com/2009/06/the-developing-an-air-actionscript-30-design-pattern-catalog-and-the-air-magic-table/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

