<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
	>
<channel>
	<title>Comments on: ActionScript 3.0 Easy and Practical Strategy Design Pattern</title>
	<atom:link href="http://www.as3dp.com/2009/03/08/actionscript-30-easy-and-practical-strategy-design-pattern/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.as3dp.com/2009/03/08/actionscript-30-easy-and-practical-strategy-design-pattern/</link>
	<description>OOP Techniques for Flash and Flex Developers</description>
	<lastBuildDate>Wed, 10 Mar 2010 17:32:01 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: William B. Sanders</title>
		<link>http://www.as3dp.com/2009/03/08/actionscript-30-easy-and-practical-strategy-design-pattern/comment-page-1/#comment-4051</link>
		<dc:creator>William B. Sanders</dc:creator>
		<pubDate>Fri, 19 Feb 2010 20:39:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=749#comment-4051</guid>
		<description>Hi Tyler,

Polymorphism can be found in the Strategy classes themselves—they are written so that depending on the context of their use, they will have different meanings. I believe that we did type to the interface and not the implementation.

Kindest regards,
Bill</description>
		<content:encoded><![CDATA[<p>Hi Tyler,</p>
<p>Polymorphism can be found in the Strategy classes themselves—they are written so that depending on the context of their use, they will have different meanings. I believe that we did type to the interface and not the implementation.</p>
<p>Kindest regards,<br />
Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tyler</title>
		<link>http://www.as3dp.com/2009/03/08/actionscript-30-easy-and-practical-strategy-design-pattern/comment-page-1/#comment-4050</link>
		<dc:creator>tyler</dc:creator>
		<pubDate>Fri, 19 Feb 2010 19:43:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=749#comment-4050</guid>
		<description>Would it be appropriate to write a context interface, so that clients could also utilize polymorphism instead of typing to the concrete implementation of that context? 

For example in the client...

protected var _context:IContext;

protected function init():void{
     _context = new ConcreteContext(&quot;someUrl.swf&quot;);
}</description>
		<content:encoded><![CDATA[<p>Would it be appropriate to write a context interface, so that clients could also utilize polymorphism instead of typing to the concrete implementation of that context? </p>
<p>For example in the client&#8230;</p>
<p>protected var _context:IContext;</p>
<p>protected function init():void{<br />
     _context = new ConcreteContext(&#8221;someUrl.swf&#8221;);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William B. Sanders</title>
		<link>http://www.as3dp.com/2009/03/08/actionscript-30-easy-and-practical-strategy-design-pattern/comment-page-1/#comment-1823</link>
		<dc:creator>William B. Sanders</dc:creator>
		<pubDate>Wed, 18 Mar 2009 09:48:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=749#comment-1823</guid>
		<description>Hi Jiri,

Wow! You sure can pick the topics! Object pooling in design patterns is fairly controversial, but I agree it would be a good topic--just to see what the pros and cons are.

In some respects, we all want more speed, but with the speed of current memory and CPUs, it&#039;s not the issue it once was with the old 8-bit processors and severely limited memory. Instead, the issue of speed has shifted to design and re-design. However, I&#039;m a sucker for squeezing more speed from a program (as the Flyweight patterns does) and it is something that I think is worth a post. However, here&#039;s a list of what I have to cover first:

Deal with my client&#039;s project
Finish re-writing a video player
Posts on the following topics:
&#160;&#160;&#160;&#160;Open/Closed Principle
&#160;&#160;&#160;&#160;Dependency Inversion Principle
&#160;&#160;&#160;&#160;Least Knowledge Principle
&#160;&#160;&#160;&#160;Hollywood Principle
&#160;&#160;&#160;&#160;One reason to change principle
&#160;&#160;&#160;&#160;Part II of Builder Pattern

Possibly Chandima might be interested and we could have something sooner, but until I get these other projects off my desk, I can&#039;t put anything new there. However, it is a perfect topic for this blog. (Maybe you&#039;d like to write a post on it?)

Thanks for the great idea,
Bill</description>
		<content:encoded><![CDATA[<p>Hi Jiri,</p>
<p>Wow! You sure can pick the topics! Object pooling in design patterns is fairly controversial, but I agree it would be a good topic&#8211;just to see what the pros and cons are.</p>
<p>In some respects, we all want more speed, but with the speed of current memory and CPUs, it&#8217;s not the issue it once was with the old 8-bit processors and severely limited memory. Instead, the issue of speed has shifted to design and re-design. However, I&#8217;m a sucker for squeezing more speed from a program (as the Flyweight patterns does) and it is something that I think is worth a post. However, here&#8217;s a list of what I have to cover first:</p>
<p>Deal with my client&#8217;s project<br />
Finish re-writing a video player<br />
Posts on the following topics:<br />
&nbsp;&nbsp;&nbsp;&nbsp;Open/Closed Principle<br />
&nbsp;&nbsp;&nbsp;&nbsp;Dependency Inversion Principle<br />
&nbsp;&nbsp;&nbsp;&nbsp;Least Knowledge Principle<br />
&nbsp;&nbsp;&nbsp;&nbsp;Hollywood Principle<br />
&nbsp;&nbsp;&nbsp;&nbsp;One reason to change principle<br />
&nbsp;&nbsp;&nbsp;&nbsp;Part II of Builder Pattern</p>
<p>Possibly Chandima might be interested and we could have something sooner, but until I get these other projects off my desk, I can&#8217;t put anything new there. However, it is a perfect topic for this blog. (Maybe you&#8217;d like to write a post on it?)</p>
<p>Thanks for the great idea,<br />
Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jiri</title>
		<link>http://www.as3dp.com/2009/03/08/actionscript-30-easy-and-practical-strategy-design-pattern/comment-page-1/#comment-1822</link>
		<dc:creator>Jiri</dc:creator>
		<pubDate>Wed, 18 Mar 2009 09:26:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=749#comment-1822</guid>
		<description>Bill, one more question. I think it would be a very interesting topic to write about object pooling. There are allready some nice classes out there. I recently developed in interest in it, because using them can mean a huge speed performance.</description>
		<content:encoded><![CDATA[<p>Bill, one more question. I think it would be a very interesting topic to write about object pooling. There are allready some nice classes out there. I recently developed in interest in it, because using them can mean a huge speed performance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jiri</title>
		<link>http://www.as3dp.com/2009/03/08/actionscript-30-easy-and-practical-strategy-design-pattern/comment-page-1/#comment-1821</link>
		<dc:creator>Jiri</dc:creator>
		<pubDate>Wed, 18 Mar 2009 09:23:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=749#comment-1821</guid>
		<description>@Curro You are right with the wildcard as a return type. I was thinking about it myself, but was thinking you would always have to case the return type.
Thinking about the question &quot;what will happen if I make changes&quot; I would go for the solution of Curro, becuase it is the most flexible one.
It would be nice to encapuslate the creation of the Context to and get rid of the  switch/case, but I guess that would become a over designed thing :)

Jiri</description>
		<content:encoded><![CDATA[<p>@Curro You are right with the wildcard as a return type. I was thinking about it myself, but was thinking you would always have to case the return type.<br />
Thinking about the question &#8220;what will happen if I make changes&#8221; I would go for the solution of Curro, becuase it is the most flexible one.<br />
It would be nice to encapuslate the creation of the Context to and get rid of the  switch/case, but I guess that would become a over designed thing :)</p>
<p>Jiri</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William B. Sanders</title>
		<link>http://www.as3dp.com/2009/03/08/actionscript-30-easy-and-practical-strategy-design-pattern/comment-page-1/#comment-1818</link>
		<dc:creator>William B. Sanders</dc:creator>
		<pubDate>Wed, 18 Mar 2009 01:24:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=749#comment-1818</guid>
		<description>Hi Curro,

In your code just type in the symbols as you always do. Your code was fine. I just added the &lt;pre&gt; tags to format it--never use the UTF-8 code in your programs.

A lot of developers (myself included) have used multiple Context classes--an abstract base class and multiple concrete implementations. However, I&#039;ve been going the other way--towards a single concrete Context class.

I suppose either way works. Anyway, the question to ask with design patterns is, &lt;em&gt;what will happen if I make changes&lt;/em&gt;? As long as you can keep the relations loose and functional, you will find many variations that you can work with.

Thanks for all your interest and very nice work.

Kindest regards,
Bill</description>
		<content:encoded><![CDATA[<p>Hi Curro,</p>
<p>In your code just type in the symbols as you always do. Your code was fine. I just added the &#60;pre&#62; tags to format it&#8211;never use the UTF-8 code in your programs.</p>
<p>A lot of developers (myself included) have used multiple Context classes&#8211;an abstract base class and multiple concrete implementations. However, I&#8217;ve been going the other way&#8211;towards a single concrete Context class.</p>
<p>I suppose either way works. Anyway, the question to ask with design patterns is, <em>what will happen if I make changes</em>? As long as you can keep the relations loose and functional, you will find many variations that you can work with.</p>
<p>Thanks for all your interest and very nice work.</p>
<p>Kindest regards,<br />
Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Curro</title>
		<link>http://www.as3dp.com/2009/03/08/actionscript-30-easy-and-practical-strategy-design-pattern/comment-page-1/#comment-1816</link>
		<dc:creator>Curro</dc:creator>
		<pubDate>Tue, 17 Mar 2009 23:58:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=749#comment-1816</guid>
		<description>Hi Bill,
sorry about the formatting do I have to use the utf-8 codes for the pre tags? are they &lt; and &gt; ?

Thank you

Curro</description>
		<content:encoded><![CDATA[<p>Hi Bill,<br />
sorry about the formatting do I have to use the utf-8 codes for the pre tags? are they &#60; and &#62; ?</p>
<p>Thank you</p>
<p>Curro</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Curro</title>
		<link>http://www.as3dp.com/2009/03/08/actionscript-30-easy-and-practical-strategy-design-pattern/comment-page-1/#comment-1815</link>
		<dc:creator>Curro</dc:creator>
		<pubDate>Tue, 17 Mar 2009 23:53:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=749#comment-1815</guid>
		<description>Hi Bill and Jiri,

I have re-written the interface and added a getContent():* function.
Here is the new ILoadMaster class:

&lt;pre lang=&quot;actionscript&quot;&gt;
package 
{
	import flash.display.Sprite;
	import flash.errors.IllegalOperationError;

	//Abstract class: Strategy Interface

	public class ILoadMaster extends Sprite
	{
		public function loadStuff(url:String):void
		{
			throw new IllegalOperationError(&quot;Abstract method: must be overridden in a subclass&quot;);
		}
		public function getContent():*
		{
			throw new IllegalOperationError(&quot;Abstract method: must be overridden in a subclass&quot;);
		}
	}
}
&lt;/pre&gt;

I have also modified the Context class:
&lt;pre lang=&quot;actionscript&quot;&gt;
package 
{
	import flash.display.Sprite;
	import flash.errors.IllegalOperationError;

	public class Context extends Sprite
	{
		protected var lm:ILoadMaster;

		public function Context(lm:ILoadMaster):void
		{
			this.lm = lm;
		}

		public function doLoad(url:String):void
		{
			throw new IllegalOperationError(&quot;Abstract method: must be overridden in a subclass&quot;);
		}
	}
}
&lt;/pre&gt;

I had to add two new Context subclasses: PixContext and TextContext
PixContext is just a copy of the old Context class:

&lt;pre lang=&quot;actionscript&quot;&gt;
package 
{
	import flash.display.Sprite;

	public class PixContext extends Context
	{
		public function PixContext(lm:ILoadMaster):void
		{
			super(lm);
		}

		override public function doLoad(url:String):void
		{
			lm.loadStuff(url);
			addChild(lm);
		}
	}
}
&lt;/pre&gt;

For TextContext I have found a not very elegant solution but it works:

&lt;pre lang=&quot;actionscript&quot;&gt;
package 
{
	import flash.display.Sprite;
	import flash.text.TextFormat;
	import fl.controls.TextArea;
	import flash.events.Event;
	import flash.net.URLLoader;

	public class TextContext extends Context
	{
		var textA:TextArea;
		var loaderRef:URLLoader;

		public function TextContext(lm:ILoadMaster):void
		{
			super(lm);
		}

		override public function doLoad(url:String):void
		{
			
			var theFormat:TextFormat = new TextFormat();
			theFormat.size = 16;
			
			textA = new TextArea();
			textA.editable = false;
			textA.focusEnabled = false;
			textA.width = 500;
			textA.height = 300;
			textA.x = 100;
			
			lm.loadStuff(url);
			loaderRef = lm.getContent();
			loaderRef.addEventListener(Event.COMPLETE,textLoaded);
			textA.setStyle(&quot;textFormat&quot;, theFormat);
			addChild(textA);
		}
		
		private function textLoaded(event:Event)
		{
			textA.text  = loaderRef.data;
		}
		
	}
}
&lt;/pre&gt;

Then of course I had to modify the TextLoader class:

&lt;pre lang=&quot;actionscript&quot;&gt;
package 
{
	import flash.net.URLRequest;
	import flash.net.URLLoader;
	import flash.events.Event;
	
	public class TextLoader extends ILoadMaster
	{
		private var urlReq:URLRequest;
		private var loader:URLLoader;

		override public function loadStuff(url:String):void
		{
			urlReq = new URLRequest(url);
			loader=new URLLoader();
			loader.load(urlReq);
		}
		
		override public function getContent():*
		{
			return loader;
		}		
	}
}
&lt;/pre&gt;

PixLoader stays just the same. It doesn&#039;t even need to use the getContent method:

&lt;pre lang=&quot;actionscript&quot;&gt;
package 
{
	import flash.net.URLRequest;
	import flash.display.Loader;

	class PixLoader extends ILoadMaster
	{
		private var urlReq:URLRequest;
		private var loader:Loader;

		override public function loadStuff(url:String):void
		{
			urlReq = new URLRequest(url);
			loader=new Loader();
			loader.load(urlReq);
			addChild(loader);
		}
	}
}
&lt;/pre&gt;

Finally I changed the method seeNow in the Client class:

&lt;pre lang=&quot;actionscript&quot;&gt;
		private function seeNow(e:ListEvent):void
		{
			var toLoad:String = e.item.data.substr(e.item.data.length - 3);
			container.removeChildAt(0);
			switch(toLoad)
			{
				case &quot;txt&quot;:
					contextDy = new TextContext(new TextLoader());
					swf = &quot;../text/&quot; + e.item.data;
				break;
				
				default:
					contextDy = new PixContext(new PixLoader());
					swf=&quot;../swf/&quot;+e.item.data;
			}
			
			contextDy.doLoad(swf);
			container.addChildAt(contextDy,0);
			container.x=180,container.y=70;
			
		}
&lt;/pre&gt;


Of course, the first context var in the Client class has to be changed to :

private var context:Context=new PixContext(new PixLoader());


I am not sure all this is better than the old TextLoader class instantiating a text area. What do you think? For me it is, at least, more complicated.

Regards
Curro</description>
		<content:encoded><![CDATA[<p>Hi Bill and Jiri,</p>
<p>I have re-written the interface and added a getContent():* function.<br />
Here is the new ILoadMaster 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('p749code1'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7491"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p749code1"><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> flash.<span style="color: #006600;">errors</span>.<span style="color: #006600;">IllegalOperationError</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">//Abstract class: Strategy Interface</span>
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ILoadMaster <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> loadStuff<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span>:<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>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getContent<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #66cc66;">*</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>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>I have also modified the Context 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('p749code2'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7492"><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
</pre></td><td class="code" id="p749code2"><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> 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> Context <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
		protected <span style="color: #000000; font-weight: bold;">var</span> lm:ILoadMaster;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Context<span style="color: #66cc66;">&#40;</span>lm:ILoadMaster<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">lm</span> = lm;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> doLoad<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span>:<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>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>I had to add two new Context subclasses: PixContext and TextContext<br />
PixContext is just a copy of the old Context 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('p749code3'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7493"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code" id="p749code3"><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>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PixContext <span style="color: #0066CC;">extends</span> Context
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> PixContext<span style="color: #66cc66;">&#40;</span>lm:ILoadMaster<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span>lm<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> doLoad<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span>:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			lm.<span style="color: #006600;">loadStuff</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>lm<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>For TextContext I have found a not very elegant solution but it works:</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('p749code4'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7494"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
</pre></td><td class="code" id="p749code4"><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> flash.<span style="color: #0066CC;">text</span>.<span style="color: #0066CC;">TextFormat</span>;
	<span style="color: #0066CC;">import</span> fl.<span style="color: #006600;">controls</span>.<span style="color: #006600;">TextArea</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: #006600;">net</span>.<span style="color: #006600;">URLLoader</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TextContext <span style="color: #0066CC;">extends</span> Context
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">var</span> textA:TextArea;
		<span style="color: #000000; font-weight: bold;">var</span> loaderRef:URLLoader;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> TextContext<span style="color: #66cc66;">&#40;</span>lm:ILoadMaster<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span>lm<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> doLoad<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span>:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> theFormat:<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>;
			theFormat.<span style="color: #0066CC;">size</span> = <span style="color: #cc66cc;">16</span>;
&nbsp;
			textA = <span style="color: #000000; font-weight: bold;">new</span> TextArea<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			textA.<span style="color: #006600;">editable</span> = <span style="color: #000000; font-weight: bold;">false</span>;
			textA.<span style="color: #0066CC;">focusEnabled</span> = <span style="color: #000000; font-weight: bold;">false</span>;
			textA.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">500</span>;
			textA.<span style="color: #0066CC;">height</span> = <span style="color: #cc66cc;">300</span>;
			textA.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">100</span>;
&nbsp;
			lm.<span style="color: #006600;">loadStuff</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#41;</span>;
			loaderRef = lm.<span style="color: #006600;">getContent</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			loaderRef.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>,textLoaded<span style="color: #66cc66;">&#41;</span>;
			textA.<span style="color: #0066CC;">setStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;textFormat&quot;</span>, theFormat<span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span>textA<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> textLoaded<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			textA.<span style="color: #0066CC;">text</span>  = loaderRef.<span style="color: #0066CC;">data</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Then of course I had to modify the TextLoader 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('p749code5'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7495"><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
</pre></td><td class="code" id="p749code5"><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;">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> TextLoader <span style="color: #0066CC;">extends</span> ILoadMaster
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> urlReq:URLRequest;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> loader:URLLoader;
&nbsp;
		override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> loadStuff<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span>:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			urlReq = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#41;</span>;
			loader=<span style="color: #000000; font-weight: bold;">new</span> URLLoader<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>urlReq<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getContent<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #66cc66;">*</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> loader;
		<span style="color: #66cc66;">&#125;</span>		
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>PixLoader stays just the same. It doesn&#8217;t even need to use the getContent method:</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('p749code6'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7496"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p749code6"><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>;
&nbsp;
	<span style="color: #000000; font-weight: bold;">class</span> PixLoader <span style="color: #0066CC;">extends</span> ILoadMaster
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> urlReq:URLRequest;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> loader:Loader;
&nbsp;
		override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> loadStuff<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span>:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			urlReq = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span><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>urlReq<span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span>loader<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>Finally I changed the method seeNow 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('p749code7'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7497"><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
</pre></td><td class="code" id="p749code7"><pre class="actionscript" style="font-family:monospace;">		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> seeNow<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>
			<span style="color: #000000; font-weight: bold;">var</span> toLoad:<span style="color: #0066CC;">String</span> = <span style="color: #0066CC;">e</span>.<span style="color: #006600;">item</span>.<span style="color: #0066CC;">data</span>.<span style="color: #0066CC;">substr</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: #0066CC;">length</span> - <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span>;
			container.<span style="color: #006600;">removeChildAt</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">switch</span><span style="color: #66cc66;">&#40;</span>toLoad<span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;txt&quot;</span>:
					contextDy = <span style="color: #000000; font-weight: bold;">new</span> TextContext<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> TextLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
					swf = <span style="color: #ff0000;">&quot;../text/&quot;</span> + <span style="color: #0066CC;">e</span>.<span style="color: #006600;">item</span>.<span style="color: #0066CC;">data</span>;
				<span style="color: #b1b100;">break</span>;
&nbsp;
				<span style="color: #000000; font-weight: bold;">default</span>:
					contextDy = <span style="color: #000000; font-weight: bold;">new</span> PixContext<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> PixLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
					swf=<span style="color: #ff0000;">&quot;../swf/&quot;</span>+<span style="color: #0066CC;">e</span>.<span style="color: #006600;">item</span>.<span style="color: #0066CC;">data</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			contextDy.<span style="color: #006600;">doLoad</span><span style="color: #66cc66;">&#40;</span>swf<span style="color: #66cc66;">&#41;</span>;
			container.<span style="color: #006600;">addChildAt</span><span style="color: #66cc66;">&#40;</span>contextDy,<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
			container.<span style="color: #006600;">x</span>=<span style="color: #cc66cc;">180</span>,container.<span style="color: #006600;">y</span>=<span style="color: #cc66cc;">70</span>;
&nbsp;
		<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Of course, the first context var in the Client class has to be changed to :</p>
<p>private var context:Context=new PixContext(new PixLoader());</p>
<p>I am not sure all this is better than the old TextLoader class instantiating a text area. What do you think? For me it is, at least, more complicated.</p>
<p>Regards<br />
Curro</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: William B. Sanders</title>
		<link>http://www.as3dp.com/2009/03/08/actionscript-30-easy-and-practical-strategy-design-pattern/comment-page-1/#comment-1810</link>
		<dc:creator>William B. Sanders</dc:creator>
		<pubDate>Tue, 17 Mar 2009 20:22:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=749#comment-1810</guid>
		<description>Hi Curro,

You format text just like HTML. However for listings use:

&lt;pre lang=&quot;actionscript&quot; &gt;
--code here--
&lt;/pre&gt;

Also I have to use UTF-8 character codes for things like &lt; and  &gt;

Take care,
Bill</description>
		<content:encoded><![CDATA[<p>Hi Curro,</p>
<p>You format text just like HTML. However for listings use:</p>
<p>&#60;pre lang=&#8221;actionscript&#8221; &#62;<br />
&#8211;code here&#8211;<br />
&#60;/pre&#62;</p>
<p>Also I have to use UTF-8 character codes for things like &#60; and  &#62;</p>
<p>Take care,<br />
Bill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Curro</title>
		<link>http://www.as3dp.com/2009/03/08/actionscript-30-easy-and-practical-strategy-design-pattern/comment-page-1/#comment-1809</link>
		<dc:creator>Curro</dc:creator>
		<pubDate>Tue, 17 Mar 2009 20:03:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.as3dp.com/?p=749#comment-1809</guid>
		<description>Hi Jiri,
I do agree with you that instantiating the text area (or a text field) inside the TextLoader class is not very elegant but as the IMasterLoader interface stands there is no other way as far as I know.

The same happens with your version: the getContainer function returns a display object and you cannot turn a text file into a display object unless you put it inside one. 

Unlike the Loader class, the URLLoader class is not a display object and you do need a URLLoader object to load a text file. If you try to load it with the Loader class you get a IOErrorEvent 2044. 

It occurs to me right now that we could have getContainer return a &quot;*&quot; type and then have a concrete TextContext class to instantiate the textfields, textareas or whatever and deal with the incoming data. I don&#039;t know how to do this myself but I think I will give the idea a try.

Well, I think this discussion is really interesting and instructive. 
Thank you Jiri and Bill for your help.

Curro

BTW: how can you format the text in this blog?</description>
		<content:encoded><![CDATA[<p>Hi Jiri,<br />
I do agree with you that instantiating the text area (or a text field) inside the TextLoader class is not very elegant but as the IMasterLoader interface stands there is no other way as far as I know.</p>
<p>The same happens with your version: the getContainer function returns a display object and you cannot turn a text file into a display object unless you put it inside one. </p>
<p>Unlike the Loader class, the URLLoader class is not a display object and you do need a URLLoader object to load a text file. If you try to load it with the Loader class you get a IOErrorEvent 2044. </p>
<p>It occurs to me right now that we could have getContainer return a &#8220;*&#8221; type and then have a concrete TextContext class to instantiate the textfields, textareas or whatever and deal with the incoming data. I don&#8217;t know how to do this myself but I think I will give the idea a try.</p>
<p>Well, I think this discussion is really interesting and instructive.<br />
Thank you Jiri and Bill for your help.</p>
<p>Curro</p>
<p>BTW: how can you format the text in this blog?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
