<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xml:lang="en" xml:base="http://jacwright.com/blog/wp-atom.php">
	<title type="text">Jacob Wright - Flex, AIR, PHP, etc.</title>
	<subtitle type="text">Flex, AIR, PHP, etc.</subtitle>

	<updated>2009-09-03T17:37:09Z</updated>
	<generator uri="http://wordpress.org/" version="2.8.5">WordPress</generator>

	<link rel="alternate" type="text/html" href="http://jacwright.com/blog" />
	<id>http://jacwright.com/blog/feed/atom/</id>
	

			<link rel="self" href="http://feeds.feedburner.com/jacwright" type="application/atom+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><entry>
		<author>
			<name>Jacob Wright</name>
						<uri>http://www.jacwright.com</uri>
					</author>
		<title type="html"><![CDATA[Flex Styling without the Flex (example and source)]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jacwright/~3/MSuDWx70DxE/" />
		<id>http://jacwright.com/blog/?p=295</id>
		<updated>2009-08-31T17:14:32Z</updated>
		<published>2009-08-31T16:48:25Z</published>
		<category scheme="http://jacwright.com/blog" term="ActionScript 3" /><category scheme="http://jacwright.com/blog" term="CSS" /><category scheme="http://jacwright.com/blog" term="Flex" />		<summary type="html"><![CDATA[Question: What&#8217;s 2.8KB, can style any DisplayObject on the stage, and enjoys long walks on the beach?
Answer: Flex styling pwned!
So it&#8217;s leaked out on twitter that Ben Stucki, Ryan Campbell, Tyler Wright, and myself are working together on a new RIA component initiative. Taking a different approach than Open Flux, we are starting from scratch [...]]]></summary>
		<content type="html" xml:base="http://jacwright.com/blog/295/flex-styling-without-the-flex/">&lt;p&gt;&lt;strong&gt;Question:&lt;/strong&gt; What&amp;#8217;s 2.8KB, can style any DisplayObject on the stage, and enjoys long walks on the beach?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt; Flex styling pwned!&lt;/p&gt;
&lt;p&gt;So it&amp;#8217;s leaked out on twitter that &lt;a href="http://www.benstucki.net"&gt;Ben Stucki&lt;/a&gt;, &lt;a href="http://www.bobjim.com/"&gt;Ryan Campbell&lt;/a&gt;, &lt;a href="http://xtyler.com/"&gt;Tyler Wright&lt;/a&gt;, and myself are working together on a new RIA component initiative. Taking a different approach than Open Flux, we are starting from scratch and building up fresh. We&amp;#8217;re bringing together what we&amp;#8217;ve learned from Open Flux and Stealth with the goal to release finished features and stable builds. We hope to provide something that we all can use in production. We haven&amp;#8217;t announced the name yet, officially.&lt;/p&gt;
&lt;p&gt;Ryan posted about &lt;a href="http://www.bobjim.com/2009/08/26/using-mxml-without-flex-example-and-source/"&gt;using MXML without Flex&lt;/a&gt; last week. Though it isn&amp;#8217;t for the new framework, the principle can be used for that framework. Maybe someday styling could be too. Today, I&amp;#8217;m posting about using Flex styling without the Flex framework. I&amp;#8217;ve taken the same example that Ryan posted and embellished. The components in there are Explanation of what is styled after the example.&lt;/p&gt;
&lt;p&gt;&lt;iframe width="100%" height="150" src="/blog/resources/no-flex-styling/"&gt;&lt;/iframe&gt;&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s the new MinimalComps.mxml source:&lt;/p&gt;
&lt;p&gt;&lt;iframe width="100%" height="620" src="/blog/resources/no-flex-styling/srcview/source/MinimalComps.mxml.html"&gt;&lt;/iframe&gt;&lt;/p&gt;
&lt;p&gt;And the styles.css source:&lt;/p&gt;
&lt;p&gt;&lt;iframe width="100%" height="350" src="/blog/resources/no-flex-styling/srcview/source/styles.css.html"&gt;&lt;/iframe&gt;&lt;/p&gt;
&lt;p&gt;The example looks very similar to Ryan&amp;#8217;s, but notice differences including:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the PushButton label is set from the stylesheet&lt;/li&gt;
&lt;li&gt;x, y, and spacing are no longer in the MXML on the VBox, they are only in the stylesheet&lt;/li&gt;
&lt;li&gt;Descendent selectors work&lt;/li&gt;
&lt;li&gt;#id can match the name property of DisplayObject&lt;/li&gt;
&lt;li&gt;There is no styling code built into the components. This styling is not intrusive and can work with any display objects.&lt;/li&gt;
&lt;li&gt;If you were to extend the IStylable interface provided, then you could also match against .stylenames and :pseudo selectors for state.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Pros and Cons&lt;/h3&gt;
&lt;p&gt;In order to accomplish this, I had to provide the mx.style.* classes that a stylesheet expects to be there when it is loaded. That means you cannot use this approach along with Flex, only in place of Flex. We could get it to work in a sub-applicationDomain, but that is more work and this is only a proof-of-concept.&lt;/p&gt;
&lt;p&gt;This may actually be considered more of a IoC framework than styling. We do not have getStyle/setStyle on the components and anything (any public property that is) can be set from the stylesheet, not just stylable properties. That may be considered a con to styling purists, or a pro to those who have wanted to set whatever they want.&lt;/p&gt;
&lt;p&gt;&lt;a href="/blog/resources/no-flex-styling/srcview/"&gt;View&lt;/a&gt; or &lt;a href="/blog/resources/no-flex-styling/srcview/MinimalComps.zip"&gt;Download&lt;/a&gt; the source code.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; Oh, I forgot a couple pros and cons.&lt;br /&gt;
Pro: Using Flex styling for non-flex projects allows you to embed assets and class references into the stylesheet. Something you can&amp;#8217;t do with traditional text-only styling. It allows a stylesheet full of skin classes to be overridden with another stylesheet full of skin classes for theming.&lt;br /&gt;
Con: It only supports CSS up to what Flex 4 does. That means only descendent selectors, no child selectors, sibling selectors, attribute selectors, etc. because MXMLC just ignores those rules it doesn&amp;#8217;t understand.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/jacwright/~4/MSuDWx70DxE" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://jacwright.com/blog/295/flex-styling-without-the-flex/#comments" thr:count="3" />
		<link rel="replies" type="application/atom+xml" href="http://jacwright.com/blog/295/flex-styling-without-the-flex/feed/atom/" thr:count="3" />
		<thr:total>3</thr:total>
	<feedburner:origLink>http://jacwright.com/blog/295/flex-styling-without-the-flex/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Jacob Wright</name>
						<uri>http://www.jacwright.com</uri>
					</author>
		<title type="html"><![CDATA[Using AMF as a file format]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jacwright/~3/zBVpjg0wn2s/" />
		<id>http://jacwright.com/blog/?p=248</id>
		<updated>2009-08-26T21:04:10Z</updated>
		<published>2009-08-26T20:57:40Z</published>
		<category scheme="http://jacwright.com/blog" term="AIR" /><category scheme="http://jacwright.com/blog" term="ActionScript 3" /><category scheme="http://jacwright.com/blog" term="Applications" /><category scheme="http://jacwright.com/blog" term="CSS" />		<summary type="html"><![CDATA[Flash is a great platform. You can build applications for the browser, the desktop, and&#8230; well, what else is there?
When building applications, especially those with a document-based model such as the Aviary apps, Odosketch, My Canvas, ZenStudio, the apps on acrobat.com, and many others, you need a file format for the document or project. Or [...]]]></summary>
		<content type="html" xml:base="http://jacwright.com/blog/248/using-amf-as-a-file-format/">&lt;p&gt;Flash is a great platform. You can build applications for the browser, the desktop, and&amp;#8230; well, what else is there?&lt;/p&gt;
&lt;p&gt;When building applications, especially those with a document-based model such as the &lt;a href="http://aviary.com/"&gt;Aviary&lt;/a&gt; apps, &lt;a href="http://sketch.odopod.com/"&gt;Odosketch&lt;/a&gt;, &lt;a href="http://www.mycanvas.com/"&gt;My Canvas&lt;/a&gt;, &lt;a href="http://zenstudio.zenprint.com/"&gt;ZenStudio&lt;/a&gt;, the apps on acrobat.com, and many others, you need a file format for the document or project. Or some way to save it.&lt;/p&gt;
&lt;h3&gt;What Not To Do&lt;/h3&gt;
&lt;p&gt;You don&amp;#8217;t want to save each item into a table in the database. I know a guy&amp;#8230;who had a dream&amp;#8230;that his friend did this. This guy&amp;#8217;s friend in his dream had a table for each item that needed to be stored with foreign keys etc. When a project needed to be loaded, the server-side script did a ton of queries and created a sometimes-quite-large XML structure that it then sent to the Flash app. When saving, this XML was sent back and parsed back into the database with INSERTS and UPDATES.&lt;/p&gt;
&lt;p&gt;That does not scale, and none of that data was needed to be pulled up in reports or anything that you might consider useful and require a database for. It was complex, hard to add features, and slow. That is, it would have been had that guy&amp;#8217;s dream friend been real.&lt;/p&gt;
&lt;h3&gt;Warmer, warmer&lt;/h3&gt;
&lt;p&gt;Saving document/project files to disk is the way to go. You can store metadata about each project or document in a database if you are storing them server-side. If it is an AIR app, give it a unique extension and the user can double-click on the file to open it. If you are AIR only, you can save your file as a SQLite database file. Pretty sweet option, but doesn&amp;#8217;t work for the browser &amp;#8217;cause Flash can&amp;#8217;t do that. The format could be XML like OpenOffice documents and the new MS Office formats. You would need to parse the files in and out and they could get very large, so you&amp;#8217;d want to compress them anyway.&lt;/p&gt;
&lt;h3&gt;Hot, burning, you&amp;#8217;re on fire!&lt;/h3&gt;
&lt;p&gt;So, XML might be the most portable format, but hey, that&amp;#8217;s what Import/Export dialogs are for, right? We&amp;#8217;re talking about Save/Save As&amp;#8230; :) Enter our new contender, AMF! AMF isn&amp;#8217;t really new, however I haven&amp;#8217;t heard of many people using it as their file format. The cool thing about using AMF is that after you&amp;#8217;ve prepared your objects for it, you could store (in player 10) pieces of your document on the clipboard for copy/paste from one place to another (even after a page refresh or from AIR to browser!). You can do an auto-save of a document or page to the user&amp;#8217;s SharedObject store.&lt;/p&gt;
&lt;h3&gt;Preparation and implementation&lt;/h3&gt;
&lt;p&gt;To use AMF as the format for you data you&amp;#8217;ll need to prepare your objects sufficiently. Here are a few rules:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;No&lt;/strong&gt;&lt;/em&gt; required parameters in your constructors. When AMF unserializes it has to create those objects and assign the public properties to it. You&amp;#8217;ll get errors otherwise.&lt;/li&gt;
&lt;li&gt;Register your classes using &lt;span style="font-family: Monaco, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: normal; font-size: 11px; "&gt;flash.net.registerClassAlias&lt;span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px; "&gt; or [RemoteClass(alias="...")]. This will store the registered alias name to map a class to a string for serializing and unserializing.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Use IExternalizable for more complex items that only need a few properties stored, or for Flash classes that can&amp;#8217;t be stored (e.g. BitmapData). This allows you to get around the constructor parameter issue, but it is more work. :)&lt;/li&gt;
&lt;li&gt;Make sure any data you need stored is a public getter/setter or you&amp;#8217;ll have to use IExternalizable. AMF serialization will only store data that is public and read/write. If you think about it, it makes sense.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The way to store your document object or project object (or page, or widget, or whatever) to AMF depends on where you are storing it. There are a lot of Flash APIs that use AMF already. If you are storing it to SharedObject, just assign the item to the data property or one of its properties.&lt;/p&gt;
&lt;pre&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco;"&gt;SharedObject.getLocal(&lt;span style="color: #990000;"&gt;"_myProject"&lt;/span&gt;).data.project1 = myProject;
&lt;/pre&gt;
&lt;p&gt;To send it from one app to another over LocalConection is just as easy.&lt;/p&gt;
&lt;pre&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco;"&gt;&lt;span style="color: #6699cc;"&gt;var&lt;/span&gt; conn:LocalConnection = &lt;span style="color: #0033ff;"&gt;new&lt;/span&gt; LocalConnection();
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco;"&gt;conn.send(&lt;span style="color: #990000;"&gt;"_connName"&lt;/span&gt;, &lt;span style="color: #990000;"&gt;"passProject"&lt;/span&gt;, myProject);
&lt;/pre&gt;
&lt;p&gt;To send it to the server vi Flash Remoting you pass the object as-is the same as with LocalConnection.&lt;/p&gt;
&lt;p&gt;If you want to save the project to disk or pass it to the server in a RESTful manner or as a file upload, you&amp;#8217;ll need to serialize it to AMF first. But that is pretty easy. Just remember to compress after you write it and uncompress before you read. This will save a lot of room.&lt;/p&gt;
&lt;pre&gt;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco;"&gt;&lt;span style="color: #6699cc;"&gt;var&lt;/span&gt; byteArray:ByteArray = &lt;span style="color: #0033ff;"&gt;new&lt;/span&gt; ByteArray();
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco;"&gt;byteArray.writeObject(myProject);
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco;"&gt;byteArray.compress();
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #009900;"&gt;// write the bytearray to file or send to server
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #009900;"&gt;// or we can pull it back out making a clone! (save as...)
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco;"&gt;byteArray.position = 0;
&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco;"&gt;myProject = byteArray.readObject();
&lt;/pre&gt;
&lt;p&gt;Easy cheesy. I will leave it as an exercise to the reader to figure out how to store it to the clipboard for copy/paste.&lt;/p&gt;
&lt;p&gt;XML might be an easier format, though more verbose and prone to errors in the creation and parsing. Though it could allow for greater flexibility and accessibility to other programs to read the file.&lt;/p&gt;
&lt;p&gt;Let me know if you use AMF for your document/project file storage. I&amp;#8217;d be interested to hear how many people use this method and how well it has worked out for you.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/jacwright/~4/zBVpjg0wn2s" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://jacwright.com/blog/248/using-amf-as-a-file-format/#comments" thr:count="3" />
		<link rel="replies" type="application/atom+xml" href="http://jacwright.com/blog/248/using-amf-as-a-file-format/feed/atom/" thr:count="3" />
		<thr:total>3</thr:total>
	<feedburner:origLink>http://jacwright.com/blog/248/using-amf-as-a-file-format/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Jacob Wright</name>
						<uri>http://www.jacwright.com</uri>
					</author>
		<title type="html"><![CDATA[Component Architecture, Two Approaches]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jacwright/~3/vfCvN4_dPw8/" />
		<id>http://jacwright.com/blog/?p=284</id>
		<updated>2009-08-25T23:10:24Z</updated>
		<published>2009-08-25T23:09:30Z</published>
		<category scheme="http://jacwright.com/blog" term="General" />		<summary type="html"><![CDATA[Been thinking about component architecture. Ok, so it&#8217;s a regular topic of discussion with Tyler. There&#8217;s a lot that goes into it, but at a high-level there seems to be two trains of thought, at least for me, that I&#8217;m trying to decide between: building for the component creator, or building for the component user. [...]]]></summary>
		<content type="html" xml:base="http://jacwright.com/blog/284/component-architecture-two-approaches/">&lt;p&gt;Been thinking about component architecture. Ok, so it&amp;#8217;s a regular topic of discussion with Tyler. There&amp;#8217;s a lot that goes into it, but at a high-level there seems to be two trains of thought, at least for me, that I&amp;#8217;m trying to decide between: building for the component creator, or building for the component user. I&amp;#8217;d like to discuss these two and round it up with the pros and cons. Maybe I&amp;#8217;ll settle on one by that point.&lt;/p&gt;
&lt;h3&gt;Component Creator&lt;/h3&gt;
&lt;p&gt;The component creator wants legos. He wants the pieces he can build components with easily (when I say &amp;#8220;he&amp;#8221; I mean me). He is frustrated with extending, building, and wrestling with components in Flex.&lt;/p&gt;
&lt;p&gt;So, we&amp;#8217;re looking at splitting out the component into a skin (view), one or more behaviors (controller), and then perhaps some reusable model objects (um&amp;#8230;model). The component creator wants an interface that describes the relationship between the component and the behaviors. Between the behaviors and the skin. It would be easy to assemble these into a component. Just drag-n-drop, right? You could create new and inventive and creative components all day! Beautiful.&lt;/p&gt;
&lt;h3&gt;Component User&lt;/h3&gt;
&lt;p&gt;The component user wants a shiny gadget. He wants to have a finished product that will do what he needs, out-of-the-box. He was very happy with Flex (until he needed a custom component, but that gets back to the creator). He is happy with solid components that are easy to use. He doesn&amp;#8217;t want to know what the guts look like, and he doesn&amp;#8217;t care, as long as it works well.&lt;/p&gt;
&lt;p&gt;This guy (me too by the way) would have an interface for each type of component: IButton, ICombo, IList. And though he might not even know those interfaces exist, he would know what each component could do and would be pleased with it. The component might be made up of reusable models, behaviors, etc. behind the shiny API, but he wouldn&amp;#8217;t know or care.&lt;/p&gt;
&lt;h3&gt;Which way is best?&lt;/h3&gt;
&lt;p&gt;So, is one better than the other? Or are we just hitting two different types of users?&lt;/p&gt;
&lt;p&gt;The pro for the first model is that it would be easy to create new components. The con would be the steeper learning curve for people using the components. If you&amp;#8217;re a component creator you&amp;#8217;re probably thinking &amp;#8220;yeah whatever, that&amp;#8217;s not a learning curve, not more than anything else,&amp;#8221; but it really is. You have to understand how the components work. It&amp;#8217;s so easy to just drop a component down and read that it supports a &amp;#8220;label&amp;#8221; property. Learning a front-facing API is easier than learning interactions.&lt;/p&gt;
&lt;p&gt;The pro for the second model would then be that it is easier to learn and use. The con, it could be implemented poorly underneath that nice interface, and would thus be hard to extend, modify, reuse. Here we have Flex (no offense Flex team). It&amp;#8217;s getting better, especially with Flex 4, but backwards compatibility always has costs, and there is still a lot of cobwebs in there.&lt;/p&gt;
&lt;p&gt;So, I suppose we could have reusable pieces in the implementation, but have the interfaces stay out of that and simply give us good API. If we made it easy for component users with shiny front-facing interfaces, and used behaviors and all that complex stuff under-the-hood so to speak, we could end up with easy components that were still extendable and reusable.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/jacwright/~4/vfCvN4_dPw8" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://jacwright.com/blog/284/component-architecture-two-approaches/#comments" thr:count="3" />
		<link rel="replies" type="application/atom+xml" href="http://jacwright.com/blog/284/component-architecture-two-approaches/feed/atom/" thr:count="3" />
		<thr:total>3</thr:total>
	<feedburner:origLink>http://jacwright.com/blog/284/component-architecture-two-approaches/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Jacob Wright</name>
						<uri>http://www.jacwright.com</uri>
					</author>
		<title type="html"><![CDATA[Response Pattern in ActionScript 3]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jacwright/~3/O80NOT8168M/" />
		<id>http://jacwright.com/blog/?p=271</id>
		<updated>2009-08-24T19:19:36Z</updated>
		<published>2009-08-24T19:13:32Z</published>
		<category scheme="http://jacwright.com/blog" term="ActionScript 3" /><category scheme="http://jacwright.com/blog" term="Flash" />		<summary type="html"><![CDATA[Earlier I posted about the Response Pattern. Today I wanted to show an ActionScript implementation and how it would be used.
The API I decided to go with for this pattern uses method chaining. This is one of those things where people love it or they despise it. I'm sorry if you are one of the [...]]]></summary>
		<content type="html" xml:base="http://jacwright.com/blog/271/response-pattern-in-actionscript-3/">&lt;p&gt;Earlier I posted about the Response Pattern. Today I wanted to show an ActionScript implementation and how it would be used.&lt;/p&gt;
&lt;p&gt;The API I decided to go with for this pattern uses method chaining. This is one of those things where people love it or they despise it. I'm sorry if you are one of the latter. Method chaining is where an object returns a reference to itself as the result of its methods. This allows you to call many methods on the object in one line. jQuery uses this and it is used a lot in the Zend Framework. As example you might have a drawing API helper that does this:&lt;/p&gt;
&lt;div class="igBar"&gt;&lt;span id="lactionscript-4"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('actionscript-4'); return false;"&gt;PLAIN TEXT&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="syntax_hilite"&gt;&lt;span class="langName"&gt;Actionscript:&lt;/span&gt;
&lt;div id="actionscript-4"&gt;
&lt;div class="actionscript"&gt;
&lt;ol&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;shape.&lt;span style="color: #006600;"&gt;fill&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;0x660000&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;.&lt;span style="color: #006600;"&gt;rect&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;color:#800000;"&gt;0&lt;/span&gt;, &lt;span style="color: #cc66cc;color:#800000;"&gt;0&lt;/span&gt;, &lt;span style="color: #cc66cc;color:#800000;"&gt;100&lt;/span&gt;, &lt;span style="color: #cc66cc;color:#800000;"&gt;100&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;.&lt;span style="color: #006600;"&gt;fill&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;0x990000&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;.&lt;span style="color: #006600;"&gt;rect&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #cc66cc;color:#800000;"&gt;1&lt;/span&gt;, &lt;span style="color: #cc66cc;color:#800000;"&gt;1&lt;/span&gt;, &lt;span style="color: #cc66cc;color:#800000;"&gt;98&lt;/span&gt;, &lt;span style="color: #cc66cc;color:#800000;"&gt;98&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;; &lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;This would draw a red box with a darker red border around it, all in one line. If the above code gives you tingles in your stomach, you'll like response. If it upsets you, you can still use response with one method per line of code.&lt;/p&gt;
&lt;p&gt;You can see in the interface &lt;a href="http://code.google.com/p/jacwright/source/browse/trunk/flash/jac/src/jac/net/IResponse.as"&gt;IResponse&lt;/a&gt; that it has method chaining and supports a bindable progress property as well. The &lt;a href="http://code.google.com/p/jacwright/source/browse/trunk/flash/jac/src/jac/net/Response.as"&gt;Response&lt;/a&gt; implementation has a few more methods that are useful when first creating a response. It allows events to trigger the complete cycle (which runs through the result handlers and calls them) or the error cycle. It also will create a flash.net.Responder object that can be used in NetConnection calls or other situations that take a native responder object. There are also some more advanced uses of Response which we might talk about another time. But let's see it in action!&lt;/p&gt;
&lt;p&gt;I've posted my &lt;a href="http://code.google.com/p/jacwright/source/browse/#svn/trunk/flash/jac"&gt;library of code&lt;/a&gt; I reuse on Google Code under the MIT license. Here you'll find a class called &lt;a href="http://code.google.com/p/jacwright/source/browse/trunk/flash/jac/src/jac/image/ImageLibrary.as"&gt;ImageLibrary&lt;/a&gt;. Here is how it works.&lt;/p&gt;
&lt;div class="igBar"&gt;&lt;span id="lactionscript-5"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('actionscript-5'); return false;"&gt;PLAIN TEXT&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="syntax_hilite"&gt;&lt;span class="langName"&gt;Actionscript:&lt;/span&gt;
&lt;div id="actionscript-5"&gt;
&lt;div class="actionscript"&gt;
&lt;ol&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #808080; font-style: italic;"&gt;// MySprite which extends Sprite&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0066CC;"&gt;public&lt;/span&gt; &lt;span style="color: #000000; font-weight: bold;"&gt;function&lt;/span&gt; addImage&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0066CC;"&gt;url&lt;/span&gt;:&lt;span style="color: #0066CC;"&gt;String&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;:&lt;span style="color: #0066CC;"&gt;void&lt;/span&gt; &lt;span style="color: #66cc66;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #000000; font-weight: bold;"&gt;var&lt;/span&gt; bitmap:Bitmap = &lt;span style="color: #000000; font-weight: bold;"&gt;new&lt;/span&gt; Bitmap&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; addChild&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;bitmap&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; ImageLibrary.&lt;span style="color: #006600;"&gt;getInstance&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;.&lt;span style="color: #006600;"&gt;getImage&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0066CC;"&gt;url&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;.&lt;span style="color: #006600;"&gt;handle&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;addDataToBitmap, bitmap&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #66cc66;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0066CC;"&gt;private&lt;/span&gt; &lt;span style="color: #000000; font-weight: bold;"&gt;function&lt;/span&gt; addDataToBitmap&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0066CC;"&gt;data&lt;/span&gt;:&lt;span style="color: #0066CC;"&gt;Object&lt;/span&gt;, bitmap:Bitmap&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;:&lt;span style="color: #0066CC;"&gt;void&lt;/span&gt; &lt;span style="color: #66cc66;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt; &lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0066CC;"&gt;data&lt;/span&gt; is BitmapData&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #66cc66;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bitmap.&lt;span style="color: #006600;"&gt;bitmapData&lt;/span&gt; = &lt;span style="color: #0066CC;"&gt;data&lt;/span&gt; as BitmapData;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color: #66cc66;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #66cc66;"&gt;&amp;#125;&lt;/span&gt; &lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;In this example, we have a result handler that sets the BitmapData object to the bitmap object. We could have created and added the bitmap to the Sprite in the handler, but I wanted to show how you can pass extra parameters to the handlers in the &lt;code&gt;handle(resultHandler:Function, ...rest)&lt;/code&gt; method. Another thing to note, is that if we were to add the same image to our &lt;code&gt;MySprite&lt;/code&gt; class again, addDataToBitmap would be called instantly because ImageLibrary caches the results of previous calls so that the player won't have to load them from the server again. This results in virtualized lists having the images instantaneously showing up after the first load.&lt;/p&gt;
&lt;p&gt;The RemoteProxy class is a Flash remoting service which is extremely small. It uses Response.&lt;/p&gt;
&lt;div class="igBar"&gt;&lt;span id="lactionscript-6"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('actionscript-6'); return false;"&gt;PLAIN TEXT&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="syntax_hilite"&gt;&lt;span class="langName"&gt;Actionscript:&lt;/span&gt;
&lt;div id="actionscript-6"&gt;
&lt;div class="actionscript"&gt;
&lt;ol&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0066CC;"&gt;public&lt;/span&gt; &lt;span style="color: #000000; font-weight: bold;"&gt;function&lt;/span&gt; loadContacts&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;:IResponse &lt;span style="color: #66cc66;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #000000; font-weight: bold;"&gt;var&lt;/span&gt; service:RemoteProxy = &lt;span style="color: #000000; font-weight: bold;"&gt;new&lt;/span&gt; RemoteProxy&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;gateway&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #808080; font-style: italic;"&gt;// call the list operation and then handle the results with setContacts&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #808080; font-style: italic;"&gt;// and handle errors with errorLoading&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;return&lt;/span&gt; service.&lt;span style="color: #006600;"&gt;contacts&lt;/span&gt;.&lt;span style="color: #0066CC;"&gt;list&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;.&lt;span style="color: #006600;"&gt;handle&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;setContacts&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;.&lt;span style="color: #006600;"&gt;handleError&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;errorLoading&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #66cc66;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0066CC;"&gt;public&lt;/span&gt; &lt;span style="color: #000000; font-weight: bold;"&gt;function&lt;/span&gt; setContacts&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;contacts:&lt;span style="color: #0066CC;"&gt;Array&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;:&lt;span style="color: #0066CC;"&gt;void&lt;/span&gt; &lt;span style="color: #66cc66;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; _contacts = contacts;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #66cc66;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;protected &lt;span style="color: #000000; font-weight: bold;"&gt;function&lt;/span&gt; errorLoading&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0066CC;"&gt;error&lt;/span&gt;:&lt;span style="color: #0066CC;"&gt;Error&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;:&lt;span style="color: #0066CC;"&gt;void&lt;/span&gt; &lt;span style="color: #66cc66;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; Logging.&lt;span style="color: #0066CC;"&gt;log&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #ff0000;"&gt;"Error loading contacts: "&lt;/span&gt; + &lt;span style="color: #0066CC;"&gt;error&lt;/span&gt;.&lt;span style="color: #0066CC;"&gt;toString&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #66cc66;"&gt;&amp;#125;&lt;/span&gt; &lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;In this example we pass the Response object along so that whoever is calling &lt;code&gt;loadContacts&lt;/code&gt; can know when the result is ready or if there was an error.&lt;/p&gt;
&lt;p&gt;Here is a list of some of the classes I've made which use Response:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://code.google.com/p/jacwright/source/browse/trunk/flash/jac/src/jac/image/ImageLibrary.as"&gt;jac.image.ImageLoader&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://code.google.com/p/jacwright/source/browse/trunk/flash/jac/src/jac/net/RemoteProxy.as"&gt;jac.net.RemoteProxy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://code.google.com/p/jacwright/source/browse/trunk/flash/jac/src/jac/net/RemoteService.as"&gt;jac.net.RemoteService&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://code.google.com/p/jacwright/source/browse/trunk/flash/jac_air/src/jac/db/Database.as"&gt;jac.db.Database&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://code.google.com/p/jacwright/source/browse/trunk/flash/jac_air/src/jac/filesystem/AsyncFile.as"&gt;jac.filesystem.AsyncFile&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is just a little taste of using the Response Pattern. I have found it much nicer to use when you are waiting for the results of a particular call. Event listeners are still useful for user input and for socket-based libraries such as XMPP or FMS, but I like Response for most other async operations.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/jacwright/~4/O80NOT8168M" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://jacwright.com/blog/271/response-pattern-in-actionscript-3/#comments" thr:count="4" />
		<link rel="replies" type="application/atom+xml" href="http://jacwright.com/blog/271/response-pattern-in-actionscript-3/feed/atom/" thr:count="4" />
		<thr:total>4</thr:total>
	<feedburner:origLink>http://jacwright.com/blog/271/response-pattern-in-actionscript-3/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Jacob Wright</name>
						<uri>http://www.jacwright.com</uri>
					</author>
		<title type="html"><![CDATA[The Response Pattern]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jacwright/~3/79f0q6ycA4M/" />
		<id>http://jacwright.com/blog/?p=259</id>
		<updated>2009-08-31T18:26:10Z</updated>
		<published>2009-08-21T15:56:16Z</published>
		<category scheme="http://jacwright.com/blog" term="General" />		<summary type="html"><![CDATA[I don't presume to place myself at the status of GoF or Martin Fowler, but I came up with a concept that was then improved upon by my twin brother, Tyler, which I feel could stand to be called a pattern. I may not be the first one to do this, but if I am, [...]]]></summary>
		<content type="html" xml:base="http://jacwright.com/blog/259/the-response-pattern/">&lt;p&gt;I don't presume to place myself at the status of GoF or Martin Fowler, but I came up with a concept that was then improved upon by my twin brother, &lt;a href="http://xtyler.com/"&gt;Tyler&lt;/a&gt;, which I feel could stand to be called a pattern. I may not be the first one to do this, but if I am, then it really shouldn't be called a pattern since design patterns are observable patterns found in a lot of code that can be documented and generalized. I apologize in advance if it should not hold "pattern" status, but I think it is worth discussing, so please be kind. It's pretty simple in concept, and has turned out to be quite useful in practice. I call it the Response pattern.&lt;/p&gt;
&lt;p&gt;This pattern was developed for ActionScript 3, but might be applied to JavaScript or other languages where functions or methods can be passed by reference.&lt;/p&gt;
&lt;h3&gt;The Problem&lt;/h3&gt;
&lt;p&gt;Services (being used in the sense of web services being consumed) or other asynchronous operations must be responded to and handled correctly. Often the data returned will be formatted before it is passed on to the caller for consumption. Sometimes the data has been retrieved previously and cached by the system, requiring a check to the cache before calling the service.&lt;/p&gt;
&lt;p&gt;Two existing solutions exist, the Callback and the Subscribe solution. Both of these have their drawbacks.&lt;/p&gt;
&lt;p&gt;The Callback is a simple solution in which a method is passed in as a parameter of the service call. This method will then be called and passed in the results of the service call once the asynchronous operation is complete. While this is easy and simple, it only allows one method to respond to the call and additional complexity must be added to handle errors which might occur.&lt;/p&gt;
&lt;p&gt;The Subscribe solution allows objects to subscribe to messages (or events) which may be broadcast by an object. This solution is the Flash player and Javascript's event model with addEventListener etc. Some good things about this solution it it allows many methods to handle the results of a service call. It also allows you to "listen" to errors as well as results. While this solution works great for user interface events which may happen at any time, it has significant drawbacks for asynchronous service calls. The primary drawback is that when a service call is made the method handling the result cannot be sure which call it is handling. For example, you wouldn't want a QUERY_RESULT event to be dispatched to handle queries because what if several objects in your system called a query? You'd have one method expecting a list of users but it might get a list of addresses first. In order to funnel results you have to become very specific in your events such as USER_QUERY_RESULT, and then you have a host of events you need to support. Though this solution does not promote formatting of data, it doesn't prohibit it. If you add your listener first, you can modify the result data on the event object before other listeners get to it. This can be tricky however since you can't always guarantee the order of the listeners.&lt;/p&gt;
&lt;p&gt;There needs to be a way to handle the results of a service call that:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;allows you to deal with the results of a specific call (not any that match some event name)&lt;/li&gt;
&lt;li&gt;handles errors&lt;/li&gt;
&lt;li&gt;allows more than one method to respond to an operation&lt;/li&gt;
&lt;li&gt;allows methods to format the data in set order&lt;/li&gt;
&lt;li&gt;allows synchronous operations with the same method (e.g. a cached item in memory can be returned)&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;The Solution&lt;/h3&gt;
&lt;h4&gt;Participants&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Service&lt;/strong&gt;: An object or objects which facilitate calling remote system asynchronously. This may be a webservice API but may also include loading resources such as images.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Handlers&lt;/strong&gt;: A "handler" is a method or function which handles the results or errors of a call from the service.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Formatters&lt;/strong&gt;: A handler which formats the data or converts it into a different data type for other methods handling the results or errors.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Response&lt;/strong&gt;: An object that stores the handlers and formatters and calls them when the service results (or errors) are returned.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;Interaction&lt;/h4&gt;
&lt;p&gt;When a call is made on a service, the service returns a Response object. The caller of the service may then add handlers to the response object. When the call is completed or receives an error, the response object is told to call the result handlers or the error handlers. Each result handler will have at least one parameter which the data from the result (if any) will be passed into. Each error handler will have at least one parameter which the error will be passed into. If a handler method returns a value, that value will become the new data/error. Thus a handler becomes a formatter taking the data it receives and converting it or changing it to a new type of value.&lt;/p&gt;
&lt;p&gt;This solution allows for layers of services which abstract the lower level from the higher. The following is an example of how the response might be used.&lt;/p&gt;
&lt;h3&gt;Example&lt;/h3&gt;
&lt;p&gt;A system depends on a RESTful XML web service. A low-level service class has been created which loads HTTP data, we'll call it WebLoader. This class uses the response pattern and is used to load images, documents, etc. from the web. Another service class called XMLLoader is layered on top of WebLoader, that is, it uses a WebLoader object to handle the low-level loading of an XML document from the web, but then converts that document into an XML object the system can use. Finally, a system specific service is layered on top of these other two utility services, called MyLoader. MyLoader takes XML objects and converts them into domain-specific objects, such as User, Product, or Contact.&lt;/p&gt;
&lt;p&gt;The system needs to load all the contacts for the logged-in user and display them on-screen. It calls MyLoader.loadContacts(), which in turn, calls XMLLoader.load("http://example.com/contacts.xml") which in turn calls WebLoader.load("http://example.com/contacts.xml"). The WebLoader.load call creates a new response object and stores it for when the result is loaded or an error occurs. Once created it returns the response object from the load method. The XMLLoader.load method receives the response object, adds a handler to it called stringToXML which takes a string, parses it, and returns and XML object, and then returns that response object from its load method. The MyLoader class receives the response object, adds its own handler, xmlToContacts, to format the XML into a list of Contact objects and returns the response. The system receives the response object and adds its own handler, displayContacts, to display the list of contacts on the screen.&lt;/p&gt;
&lt;p&gt;When the load is completed, WebLoader calls complete(data) on the stored response object. The response object then loops through the handlers added to it, calling stringToXML first, receiving a value back from it, passing that value into xmlToContacts, receiving a value back from that, and passing a list of contacts into the displayContacts handler which doesn't return anything, but displays the contacts.&lt;/p&gt;
&lt;p&gt;Let's add a cache to our MyLoader class. When the contact list is loaded, it stores the array of contacts in memory. Next time loadContacts is called, the MyLoader class creates a response object, calls complete(cachedContacts) on it, and returns it. Then, as soon as the caller adds displayContacts handler to the response, the response calls displayContacts and passes in the array of contacts which was cached. Thus, the caller doesn't need to know whether the call has been cached or not, whether it is asynchronous or not.&lt;/p&gt;
&lt;p&gt;While this may sound like a lot is going on, it is actually quite simple and allows service classes to be created and added to libraries for use in other systems. In the XMLLoader example, you don't have to know or worry about how it gets the XML, the calling class can just know that it will receive XML in the response. The same goes for the MyLoader class. These services can be layered on top of each other like TCP and HTTP do, abstracting the higher levels from the lower levels.&lt;/p&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;The Response Pattern is something I made up. I created a Response class and as I've been using it more and more, it has turned out to be extremely useful and fun to use. I have found it much more preferable to using event listeners, Responder objects, and callbacks in Flash. I have wrapped the SQL classes in Adobe AIR with a service class that uses Reponse to make asynchronous database operations palatable. I have wrapped the File class for AIR. I have created a teeny tiny version of RemoteObject called RemoteService that uses Response. And I have created an ImageLibrary class which stores loaded images for me and resizes them to the size I need. Because it stores the images, sometimes calls are asynchronous and sometimes synchronous, but it is handled the same either way.&lt;/p&gt;
&lt;p&gt;I plan to put together a library of often used services that are built around this concept for everyone to use. But until then, you can find a version of the Response class in the flight.net package of the &lt;a href="http://www.flightxd.com/flightframework/"&gt;Flight framework&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; I posted about the &lt;a href="http://jacwright.com/blog/271/response-pattern-in-actionscript-3/"&gt;ActionScript implementation of the Response pattern&lt;/a&gt;. You can see how it is used and why it is different. It looks similar to other type of implementations, but if you ever use it you'll see how different it is. It's the littlest things in life that make the biggest differences.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/jacwright/~4/79f0q6ycA4M" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://jacwright.com/blog/259/the-response-pattern/#comments" thr:count="4" />
		<link rel="replies" type="application/atom+xml" href="http://jacwright.com/blog/259/the-response-pattern/feed/atom/" thr:count="4" />
		<thr:total>4</thr:total>
	<feedburner:origLink>http://jacwright.com/blog/259/the-response-pattern/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Jacob Wright</name>
						<uri>http://www.jacwright.com</uri>
					</author>
		<title type="html"><![CDATA[Best Show I&#8217;ve Seen]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jacwright/~3/fOfB2XClaUk/" />
		<id>http://jacwright.com/blog/?p=230</id>
		<updated>2009-08-01T03:32:57Z</updated>
		<published>2009-08-01T03:32:57Z</published>
		<category scheme="http://jacwright.com/blog" term="General" />		<summary type="html"><![CDATA[Just wanted to let you know about a show I've fallen in love with. I've seen the commercials and thought it might be interesting to watch, but never got around to it. Once I saw a few episodes I was totally hooked.
A couple of weeks ago I watched two seasons of NBC's Chuck within 48 [...]]]></summary>
		<content type="html" xml:base="http://jacwright.com/blog/230/best-show-ive-seen/">&lt;p&gt;Just wanted to let you know about a show I've fallen in love with. I've seen the commercials and thought it might be interesting to watch, but never got around to it. Once I saw a few episodes I was totally hooked.&lt;/p&gt;
&lt;p&gt;A couple of weeks ago I watched two seasons of NBC's Chuck within 48 hours. I has become my favorite TV series followed by The Office and Lost, and I can't wait for season 3 to air next March. You can watch all 13 episodes from season 1 starting with the pilot on &lt;a title="Chuck Pilot" href="http://www.thewb.com/shows/chuck/pilot/f4184f082f"&gt;Warner Bros website&lt;/a&gt;. The second season has only about half of its 22 episodes online at nbc.com or hulu.com. You'll have to rent the DVD or buy episodes on iTunes. You can buy both seasons on iTunes and xbox live I believe.&lt;/p&gt;
&lt;p&gt;Be sure to catch up on the first two seasons so you can be up on season 3!&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/jacwright/~4/fOfB2XClaUk" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://jacwright.com/blog/230/best-show-ive-seen/#comments" thr:count="1" />
		<link rel="replies" type="application/atom+xml" href="http://jacwright.com/blog/230/best-show-ive-seen/feed/atom/" thr:count="1" />
		<thr:total>1</thr:total>
	<feedburner:origLink>http://jacwright.com/blog/230/best-show-ive-seen/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Jacob Wright</name>
						<uri>http://www.jacwright.com</uri>
					</author>
		<title type="html"><![CDATA[High quality, high performance thumbnails in Flash]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jacwright/~3/Hdi_wDa-SBQ/" />
		<id>http://jacwright.com/blog/?p=221</id>
		<updated>2009-09-03T17:03:20Z</updated>
		<published>2009-07-17T19:37:03Z</published>
		<category scheme="http://jacwright.com/blog" term="ActionScript 3" /><category scheme="http://jacwright.com/blog" term="Flash" /><category scheme="http://jacwright.com/blog" term="Flex" />		<summary type="html"><![CDATA[Ever need a thumbnail of an image in Flash? I do, and honestly speaking, the resampling that Flash does is less than ideal. Unless you only need to resize by half or bigger. But my thumbnails usually need to be smaller.
I searched for a solution and found on voq.com a promising library with some algorithms [...]]]></summary>
		<content type="html" xml:base="http://jacwright.com/blog/221/high-quality-high-performance-thumbnails-in-flash/">&lt;p&gt;Ever need a thumbnail of an image in Flash? I do, and honestly speaking, the resampling that Flash does is less than ideal. Unless you only need to resize by half or bigger. But my thumbnails usually need to be smaller.&lt;/p&gt;
&lt;p&gt;I searched for a solution and found on voq.com a &lt;a href="http://blog.voq.jp/2007/12/creating_high_quality_thumnail.html"&gt;promising library&lt;/a&gt; with some algorithms that worked quite nicely and a demo. The quality was nice, but the speed was slow. It also fiddled with the color a little bit. If I put the "easyScaling" parameter down from .5 to .25 I ended up with a nicer thumbnail but was slower to make and had more color disfiguration. You could tell what the original piece was better though.&lt;/p&gt;
&lt;p&gt;After some more searching I found that &lt;a href="http://www.brooksandrus.com/blog/2009/03/11/bilinear-resampling-with-flash-player-and-pixel-bender/"&gt;Brooks Andrus played with some algorithms using Pixel Bender&lt;/a&gt;. The conclusion to that was he found he could do the same thing with the "smoothing" option in the BitmapData.draw() method. And this still leaves me with yucky thumbnails at small sizes.&lt;/p&gt;
&lt;p&gt;I began thinking I would need to take the algorithms from the first source and port them into pixel bender like Brooks did for his ThumbGenie application.&lt;/p&gt;
&lt;p&gt;I thought I'd try one more option first. I had played around in my mind with the idea of resizing a bitmap in half, then in half again, until I reached my destination size, since resizing by half still had good results. After discussing it with Tyler I tried it out and ended up with some great results. That last resize to get to the final thumbnail size wasn't half because in an imperfect world your thumbnails aren't always a power of two times smaller than your original. So I had an odd-man-out scale at the end I was applying. Tyler suggested I put that odd-man-out scale at the first instead. So instead of:&lt;/p&gt;
&lt;p&gt;1000x750 * .5 resize * .5 resize * .5 resize * .8 = 100x75&lt;/p&gt;
&lt;p&gt;It worked like this:&lt;/p&gt;
&lt;p&gt;1000x750 * .8 resize * .5 resize * .5 resize * .5 = 100x75&lt;/p&gt;
&lt;p&gt;Doing it that way landed me with even better results! It seems that Flash does it's best work when resizing by exactly 1/2.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://jacwright.com/blog/wp-content/uploads/2009/07/Thumbnailing-Results.png" alt="Thumbnail tests" /&gt;&lt;/p&gt;
&lt;p&gt;The above image shows my test results as follows taking a snapshot of my homepage in an HTMLLoader in AIR.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Regular BitmapData.draw() method without smoothing (0 miliseconds)&lt;/li&gt;
&lt;li&gt;Regular BitmapData.draw() method &lt;strong&gt;with&lt;/strong&gt; smoothing (1 miliseconds)&lt;/li&gt;
&lt;li&gt;Using my own method that resizes by the odd scale first, then by halves (8 milliseconds)&lt;/li&gt;
&lt;li&gt;Using my method but after the odd scale, only scaling down by quarters (33 miliseconds)&lt;/li&gt;
&lt;li&gt;Using the voq Lanczos3 method with easyScaling at .25 and sharpening (694 miliseconds)&lt;/li&gt;
&lt;li&gt;Using the voq Lanczos3 method with easyScaling at .25 and no sharping (676 miliseconds)&lt;/li&gt;
&lt;li&gt;Using the voq Triangle method with easyScaling at .25 and sharpening (275 miliseconds)&lt;/li&gt;
&lt;li&gt;Using the voq Triangle method with easyScaling at .25 and no sharpening (266 miliseconds)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;My personal opinion is that the best looking thumb is #3. I was surprised that #4 wouldn't be as good. I knew the performance would be lower because I was doing more iterations of BitmapData.draw(), but I thought that scaling it to 75% (down a quarter) each time would end up nicer. Looks like 50% is the best scale to use.&lt;/p&gt;
&lt;p&gt;The voq.com algos looked pretty decent, but obviously were slow. I'm quite happy with the solution I've found. I only had to write a little bit of code, it's fast enough, and looks better than any other solution I've found (even Fireworks resizing IMO).&lt;/p&gt;
&lt;p&gt;Here is the method I wrote for this. Note, when scaling up, it seemed to look better to just use smoothing and do it in one draw() and not iterations of 2.&lt;/p&gt;
&lt;div class="igBar"&gt;&lt;span id="lactionscript-8"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('actionscript-8'); return false;"&gt;PLAIN TEXT&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="syntax_hilite"&gt;&lt;span class="langName"&gt;Actionscript:&lt;/span&gt;
&lt;div id="actionscript-8"&gt;
&lt;div class="actionscript"&gt;
&lt;ol&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0066CC;"&gt;private&lt;/span&gt; &lt;span style="color: #0066CC;"&gt;static&lt;/span&gt; const IDEAL_RESIZE_PERCENT:&lt;span style="color: #0066CC;"&gt;Number&lt;/span&gt; = .&lt;span style="color: #cc66cc;color:#800000;"&gt;5&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0066CC;"&gt;public&lt;/span&gt; &lt;span style="color: #0066CC;"&gt;static&lt;/span&gt; &lt;span style="color: #000000; font-weight: bold;"&gt;function&lt;/span&gt; resizeImage&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;source:BitmapData, &lt;span style="color: #0066CC;"&gt;width&lt;/span&gt;:uint, &lt;span style="color: #0066CC;"&gt;height&lt;/span&gt;:uint, constrainProportions:&lt;span style="color: #0066CC;"&gt;Boolean&lt;/span&gt; = &lt;span style="color: #000000; font-weight: bold;"&gt;true&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;:BitmapData&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #66cc66;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #000000; font-weight: bold;"&gt;var&lt;/span&gt; scaleX:&lt;span style="color: #0066CC;"&gt;Number&lt;/span&gt; = &lt;span style="color: #0066CC;"&gt;width&lt;/span&gt;/source.&lt;span style="color: #0066CC;"&gt;width&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #000000; font-weight: bold;"&gt;var&lt;/span&gt; scaleY:&lt;span style="color: #0066CC;"&gt;Number&lt;/span&gt; = &lt;span style="color: #0066CC;"&gt;height&lt;/span&gt;/source.&lt;span style="color: #0066CC;"&gt;height&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt; &lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;constrainProportions&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #66cc66;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt; &lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;scaleX&amp;gt; scaleY&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt; scaleX = scaleY;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;else&lt;/span&gt; scaleY = scaleX;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #66cc66;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #000000; font-weight: bold;"&gt;var&lt;/span&gt; bitmapData:BitmapData = source;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt; &lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;scaleX&amp;gt;= &lt;span style="color: #cc66cc;color:#800000;"&gt;1&lt;/span&gt; &amp;amp;&amp;amp; scaleY&amp;gt;= &lt;span style="color: #cc66cc;color:#800000;"&gt;1&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #66cc66;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bitmapData = &lt;span style="color: #000000; font-weight: bold;"&gt;new&lt;/span&gt; BitmapData&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0066CC;"&gt;Math&lt;/span&gt;.&lt;span style="color: #0066CC;"&gt;ceil&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;source.&lt;span style="color: #0066CC;"&gt;width&lt;/span&gt;*scaleX&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;, &lt;span style="color: #0066CC;"&gt;Math&lt;/span&gt;.&lt;span style="color: #0066CC;"&gt;ceil&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;source.&lt;span style="color: #0066CC;"&gt;height&lt;/span&gt;*scaleY&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;, &lt;span style="color: #000000; font-weight: bold;"&gt;true&lt;/span&gt;, &lt;span style="color: #cc66cc;color:#800000;"&gt;0&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bitmapData.&lt;span style="color: #006600;"&gt;draw&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;source, &lt;span style="color: #000000; font-weight: bold;"&gt;new&lt;/span&gt; Matrix&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;scaleX, &lt;span style="color: #cc66cc;color:#800000;"&gt;0&lt;/span&gt;, &lt;span style="color: #cc66cc;color:#800000;"&gt;0&lt;/span&gt;, scaleY&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;, &lt;span style="color: #000000; font-weight: bold;"&gt;null&lt;/span&gt;, &lt;span style="color: #000000; font-weight: bold;"&gt;null&lt;/span&gt;, &lt;span style="color: #000000; font-weight: bold;"&gt;null&lt;/span&gt;, &lt;span style="color: #000000; font-weight: bold;"&gt;true&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;return&lt;/span&gt; bitmapData;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #66cc66;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #808080; font-style: italic;"&gt;// scale it by the IDEAL for best quality&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #000000; font-weight: bold;"&gt;var&lt;/span&gt; nextScaleX:&lt;span style="color: #0066CC;"&gt;Number&lt;/span&gt; = scaleX;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #000000; font-weight: bold;"&gt;var&lt;/span&gt; nextScaleY:&lt;span style="color: #0066CC;"&gt;Number&lt;/span&gt; = scaleY;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;while&lt;/span&gt; &lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;nextScaleX &amp;lt;&lt;span style="color: #cc66cc;color:#800000;"&gt;1&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt; nextScaleX /= IDEAL_RESIZE_PERCENT;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;while&lt;/span&gt; &lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;nextScaleY &amp;lt;&lt;span style="color: #cc66cc;color:#800000;"&gt;1&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt; nextScaleY /= IDEAL_RESIZE_PERCENT;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt; &lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;scaleX &amp;lt;IDEAL_RESIZE_PERCENT&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt; nextScaleX *= IDEAL_RESIZE_PERCENT;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt; &lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;scaleY &amp;lt;IDEAL_RESIZE_PERCENT&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt; nextScaleY *= IDEAL_RESIZE_PERCENT;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #000000; font-weight: bold;"&gt;var&lt;/span&gt; temp:BitmapData = &lt;span style="color: #000000; font-weight: bold;"&gt;new&lt;/span&gt; BitmapData&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;bitmapData.&lt;span style="color: #0066CC;"&gt;width&lt;/span&gt;*nextScaleX, bitmapData.&lt;span style="color: #0066CC;"&gt;height&lt;/span&gt;*nextScaleY, &lt;span style="color: #000000; font-weight: bold;"&gt;true&lt;/span&gt;, &lt;span style="color: #cc66cc;color:#800000;"&gt;0&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; temp.&lt;span style="color: #006600;"&gt;draw&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;bitmapData, &lt;span style="color: #000000; font-weight: bold;"&gt;new&lt;/span&gt; Matrix&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;nextScaleX, &lt;span style="color: #cc66cc;color:#800000;"&gt;0&lt;/span&gt;, &lt;span style="color: #cc66cc;color:#800000;"&gt;0&lt;/span&gt;, nextScaleY&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;, &lt;span style="color: #000000; font-weight: bold;"&gt;null&lt;/span&gt;, &lt;span style="color: #000000; font-weight: bold;"&gt;null&lt;/span&gt;, &lt;span style="color: #000000; font-weight: bold;"&gt;null&lt;/span&gt;, &lt;span style="color: #000000; font-weight: bold;"&gt;true&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; bitmapData = temp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; nextScaleX *= IDEAL_RESIZE_PERCENT;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; nextScaleY *= IDEAL_RESIZE_PERCENT;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;while&lt;/span&gt; &lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;nextScaleX&amp;gt;= scaleX || nextScaleY&amp;gt;= scaleY&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #66cc66;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color: #000000; font-weight: bold;"&gt;var&lt;/span&gt; actualScaleX:&lt;span style="color: #0066CC;"&gt;Number&lt;/span&gt; = nextScaleX&amp;gt;= scaleX ? IDEAL_RESIZE_PERCENT : &lt;span style="color: #cc66cc;color:#800000;"&gt;1&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color: #000000; font-weight: bold;"&gt;var&lt;/span&gt; actualScaleY:&lt;span style="color: #0066CC;"&gt;Number&lt;/span&gt; = nextScaleY&amp;gt;= scaleY ? IDEAL_RESIZE_PERCENT : &lt;span style="color: #cc66cc;color:#800000;"&gt;1&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; temp = &lt;span style="color: #000000; font-weight: bold;"&gt;new&lt;/span&gt; BitmapData&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;bitmapData.&lt;span style="color: #0066CC;"&gt;width&lt;/span&gt;*actualScaleX, bitmapData.&lt;span style="color: #0066CC;"&gt;height&lt;/span&gt;*actualScaleY, &lt;span style="color: #000000; font-weight: bold;"&gt;true&lt;/span&gt;, &lt;span style="color: #cc66cc;color:#800000;"&gt;0&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; temp.&lt;span style="color: #006600;"&gt;draw&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;bitmapData, &lt;span style="color: #000000; font-weight: bold;"&gt;new&lt;/span&gt; Matrix&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;actualScaleX, &lt;span style="color: #cc66cc;color:#800000;"&gt;0&lt;/span&gt;, &lt;span style="color: #cc66cc;color:#800000;"&gt;0&lt;/span&gt;, actualScaleY&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;, &lt;span style="color: #000000; font-weight: bold;"&gt;null&lt;/span&gt;, &lt;span style="color: #000000; font-weight: bold;"&gt;null&lt;/span&gt;, &lt;span style="color: #000000; font-weight: bold;"&gt;null&lt;/span&gt;, &lt;span style="color: #000000; font-weight: bold;"&gt;true&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bitmapData.&lt;span style="color: #006600;"&gt;dispose&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; nextScaleX *= IDEAL_RESIZE_PERCENT;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; nextScaleY *= IDEAL_RESIZE_PERCENT;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bitmapData = temp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #66cc66;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;return&lt;/span&gt; bitmapData;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #66cc66;"&gt;&amp;#125;&lt;/span&gt; &lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; I was getting unsatisfactory images when the resize scale was more than 50%. For example, the original code posted would size an image from 100x100 to 60x60 using one BitmapData.draw() step. And it didn't look that great.&lt;/p&gt;
&lt;p&gt;I found that if I sized the image up to a scale that allowed it to be size back down by exactly 50% that the results were much better. In the above example, the 100x100 would scale up by 120% to 120x120, then scale down 50% to 60x60. The final image looks much better this way. The code has been updated to work like this. It also had the option to turn constrain proportions off.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; I've &lt;a href="http://code.google.com/p/jacwright/source/browse/#svn/trunk/flash/jac/src/jac/image"&gt;posted my code&lt;/a&gt; library to Google Code. You can see my final implementation of bitmap resizing in the &lt;a href="http://code.google.com/p/jacwright/source/browse/trunk/flash/jac/src/jac/image/ImageUtils.as"&gt;ImageUtils&lt;/a&gt; class.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/jacwright/~4/Hdi_wDa-SBQ" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://jacwright.com/blog/221/high-quality-high-performance-thumbnails-in-flash/#comments" thr:count="9" />
		<link rel="replies" type="application/atom+xml" href="http://jacwright.com/blog/221/high-quality-high-performance-thumbnails-in-flash/feed/atom/" thr:count="9" />
		<thr:total>9</thr:total>
	<feedburner:origLink>http://jacwright.com/blog/221/high-quality-high-performance-thumbnails-in-flash/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Jacob Wright</name>
						<uri>http://www.jacwright.com</uri>
					</author>
		<title type="html"><![CDATA[Flight Framework at 360&#124;Flex!]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jacwright/~3/y5_OnK9J2XE/" />
		<id>http://jacwright.com/blog/?p=213</id>
		<updated>2009-05-15T18:29:20Z</updated>
		<published>2009-05-15T18:29:20Z</published>
		<category scheme="http://jacwright.com/blog" term="General" />		<summary type="html"><![CDATA[Another reason to attend 360&#124;Flex is the Flight Framework will be there. We'll be doing a workshop-style presentation Tuesday on getting started with Flight. Hope to see you there!
]]></summary>
		<content type="html" xml:base="http://jacwright.com/blog/213/flight-framework-at-360flex/">&lt;p&gt;Another reason to attend &lt;a href="http://www.360flex.com/"&gt;360|Flex&lt;/a&gt; is the &lt;a href="http://code.google.com/p/flight-framework/"&gt;Flight Framework&lt;/a&gt; will be there. We'll be doing a workshop-style presentation Tuesday on getting started with Flight. Hope to see you there!&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/jacwright/~4/y5_OnK9J2XE" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://jacwright.com/blog/213/flight-framework-at-360flex/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://jacwright.com/blog/213/flight-framework-at-360flex/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://jacwright.com/blog/213/flight-framework-at-360flex/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Jacob Wright</name>
						<uri>http://www.jacwright.com</uri>
					</author>
		<title type="html"><![CDATA[Would it be bad to leave behind our Flash roots?]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jacwright/~3/ZaLR_Q6eOxE/" />
		<id>http://jacwright.com/blog/?p=209</id>
		<updated>2009-05-14T18:50:33Z</updated>
		<published>2009-05-14T17:02:49Z</published>
		<category scheme="http://jacwright.com/blog" term="AIR" /><category scheme="http://jacwright.com/blog" term="Flash" /><category scheme="http://jacwright.com/blog" term="Flex" />		<summary type="html"><![CDATA[I am working with Tyler on Stealth, our high-performance component framework. After reading this article on performance by Arno Gourdol of Adobe I began wondering if we should leave behind our Flash roots of motion and timeline design by defaulting framerate to 0 in our Stealth-based applications.
Framerate makes great sense when doing games or timeline [...]]]></summary>
		<content type="html" xml:base="http://jacwright.com/blog/209/would-it-be-bad-to-leave-behind-our-flash-roots/">&lt;p&gt;I am working with &lt;a href="http://www.xtyler.com/"&gt;Tyler&lt;/a&gt; on Stealth, our high-performance component framework. After reading &lt;a href="http://arno.org/arnotify/2009/05/writing-well-behaved-efficient-air-applications/" title="Writing well-behaved, efficient, AIR applications"&gt;this article&lt;/a&gt; on performance by Arno Gourdol of Adobe I began wondering if we should leave behind our Flash roots of motion and timeline design by defaulting framerate to 0 in our Stealth-based applications.&lt;/p&gt;
&lt;p&gt;Framerate makes great sense when doing games or timeline based animations, but in applications do we need it? We can update the screen on mouse moves, roll overs, etc. with the MouseEvent.updateAfterEvent instance method. And for transitions and tweening the class could use a Timer for the duration of the animation and again call Timer.updateAfterEvent. Then the screen would only refresh when it needs to. Performance would be greatly increased. Seems like it makes sense. Would this be something to add to Flex? Would it give us the performance we need/want for mobile applications and more responsive desktop applications?&lt;/p&gt;
&lt;p&gt;Any foreseeable drawbacks? What do you think?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; I did some testing and it seems that the Timer class is directly influenced by the frameRate. With a frame rate of 0 a timer which should fire immediately (set to 0ms) doesn't fire for 20 seconds! With the frame rate a 0.1 it happens at about 2 seconds, a frame rate of 1 is about 145 ms and a frame rate of anything over 4 seems to be around the same (10ms - 30ms probably depending on what the OS is currently doing).&lt;/p&gt;
&lt;p&gt;MouseEvent updating and such happen as they should however, so as long as you start of with a frame rate of 4 so that the app can initialize visually, you could drop it down to 0 until a tween is needed and then bump it up to 4 for the duration of the tween. The rest of the visual changes can respond to mouse events (resize, click, rollover, etc). Or leaving it at 4 frames a second probably isn't too bad on CPU, either way, you'd have to call updateAfterEvent when needed.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/jacwright/~4/ZaLR_Q6eOxE" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://jacwright.com/blog/209/would-it-be-bad-to-leave-behind-our-flash-roots/#comments" thr:count="2" />
		<link rel="replies" type="application/atom+xml" href="http://jacwright.com/blog/209/would-it-be-bad-to-leave-behind-our-flash-roots/feed/atom/" thr:count="2" />
		<thr:total>2</thr:total>
	<feedburner:origLink>http://jacwright.com/blog/209/would-it-be-bad-to-leave-behind-our-flash-roots/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Jacob Wright</name>
						<uri>http://www.jacwright.com</uri>
					</author>
		<title type="html"><![CDATA[Sweet Gumbo/Spark interfaces]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/jacwright/~3/qa3-ZkgJkrk/" />
		<id>http://jacwright.com/blog/?p=207</id>
		<updated>2009-05-01T18:32:39Z</updated>
		<published>2009-05-01T18:32:39Z</published>
		<category scheme="http://jacwright.com/blog" term="General" />		<summary type="html"><![CDATA[Hooray for the Flex team! They're coding to interfaces. I've been looking through the source of recent Flex 4 code and I have to say, I'm getting excited to use this stuff. Here are a few of the things I've found with just a few minutes of going through their code:
IDeferredContentOwner - The current version [...]]]></summary>
		<content type="html" xml:base="http://jacwright.com/blog/207/sweet-gumbospark-interfaces/">&lt;p&gt;Hooray for the Flex team! They're coding to interfaces. I've been looking through the source of &lt;a href="http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4"&gt;recent Flex 4 code&lt;/a&gt; and I have to say, I'm getting excited to use this stuff. Here are a few of the things I've found with just a few minutes of going through their code:&lt;/p&gt;
&lt;p&gt;IDeferredContentOwner - The current version of Flex has something like this, but much more complex. This interface makes sense, and simply allows the deferred creation of its children when they are needed (such as a ViewStack in the current Flex). Just a couple of properties and it allows the component to figure out how to do it.&lt;/p&gt;
&lt;p&gt;IViewport - This allows any component to have scrolling. What a step forward from the current monster called Container which we probably use more than any other component for layouts (e.g. Canvas, HBox, VBox). &lt;/p&gt;
&lt;p&gt;IGraphicElement - This interface is pretty sweet. It allows 1) objects to be drawn on the same DisplayObject (e.g. several Rects could all be drawn on one Shape) and 2) it allows non-DisplayObjects to be used as children of Group by providing their own DisplayObject. I can think of some pretty fun things to do with that as far as custom components/functionality is concerned. :)  Maybe I'll join the OpenFlux initiative and talk more with Ryan Campbell and Ben Stucki about this one.&lt;/p&gt;
&lt;p&gt;There's some good things cooking in the Adobe kitchen. I'll write about more as I discover it.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/jacwright/~4/qa3-ZkgJkrk" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://jacwright.com/blog/207/sweet-gumbospark-interfaces/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://jacwright.com/blog/207/sweet-gumbospark-interfaces/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://jacwright.com/blog/207/sweet-gumbospark-interfaces/</feedburner:origLink></entry>
	</feed>
