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

<channel>
	<title>Ryan Phelan &#187; Custom Components</title>
	<atom:link href="http://www.rphelan.com/tag/custom-components/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rphelan.com</link>
	<description>Exploring Flex, Design, and Visualization</description>
	<lastBuildDate>Thu, 12 Aug 2010 14:56:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>FLVPlayback Memory Leak &#8211; Fixed</title>
		<link>http://www.rphelan.com/2008/09/22/flvplayback-memory-leak-fixed/</link>
		<comments>http://www.rphelan.com/2008/09/22/flvplayback-memory-leak-fixed/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 19:46:42 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Custom Components]]></category>
		<category><![CDATA[FLVPlayback]]></category>
		<category><![CDATA[Memory Management]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Profiling]]></category>

		<guid isPermaLink="false">http://www.rphelan.com/?p=107</guid>
		<description><![CDATA[So the Flash CS3 FLVPlayback control has a memory leak.  Based on prior experiences with Flash components, I'm not too shocked.... here's my solution. I'm working on a straight AS3 project that has a dynamically generated pop-up type window which can contain a video player. You open the window, a video player is created - [...]]]></description>
			<content:encoded><![CDATA[<p>So the Flash CS3 FLVPlayback control has a memory leak.  Based on prior experiences with Flash components, I'm not too shocked.... here's my solution.</p>
<p>I'm working on a straight AS3 project that has a dynamically generated pop-up type window which can contain a video player. You open the window, a video player is created - you close it, and the player is removed.  The client requested that we use Flash's FLVPlayback component.   When I started doing some profiling I noticed that instances of FLVPlayback and its subcomponents weren't getting garbage collected.  After several hours of frustration, I created a project from scratch that just loaded and unloaded FLVPlaybacks to see if I could recreate the problem.  Here it is:</p>
<p><a href="http://www.rphelan.com/flex/FLVMemoryLeak/FLVMemoryLeak.html">Application</a> -  <a href="http://www.rphelan.com/flex/FLVMemoryLeak/srcview/index.html">Source</a></p>
<p>You'll notice that each time you create a video player, System.totalMemory goes up by several megs!  (your results may vary)  and it never comes back down.  Here's what it looks like after creating and destroying 10 FLVPlaybacks:</p>
<p><a href="http://www.rphelan.com/flex/uploads/2008/09/flv-leak.jpg"><img class="alignnone size-full wp-image-109" title="flv-leak" src="http://www.rphelan.com/flex/uploads/2008/09/flv-leak.jpg" alt="" width="500" height="477" /></a></p>
<p><em>Note that I sorted by current number of instances, and removed flash.*.* from the filters list so that I could see the Timers.</em></p>
<p>All of the objects in the fl.video.skin package are still hanging around.  I actually have no idea why it created two skins for each instance, but I'm sure there is a good explanation... the main point is that none of these objects were getting garbage collected.</p>
<p>It took a lot of rooting around in the source before figuring out what the culprits were, but I knew I would have to do some manual cleanup work in order to clear out all object references.  My solution was to subclass FLVPlayback and implement a dispose() method to do the necessary cleanup.  (Just for fun, I got the same solution working with an old school prototype hack, but I think we're supposed to pretend those don't exist anymore.)  Now, I may have been a little aggressive on my cleanup - but the overhead is tiny, and it's important to me that this always works.  If anybody knows of a simpler solution, please post it in the comments.  Here's the breakdown:</p>
<ol>
<li>Call stop().  Obviously if the video is still playing it cannot be garbage collected.</li>
<li>Stop all timers in FLVPlayback and UIManager and remove the TimerEvent.TIMER event listeners attached to each one.</li>
<li>Call the close() method on the VideoPlayer instances.  This will stop their timers, remove event listeners, and close NetConnections.</li>
</ol>
<p>Here's the same application, but using FLVPlayback2 and the FLVPlayback2.dispose() method:</p>
<p><a href="http://www.rphelan.com/flex/FLVMemoryLeak/FLVMemoryLeakFixed.html">Application</a> -  <a href="http://www.rphelan.com/flex/FLVMemoryLeak/srcview/index.html">Source</a></p>
<p>And here are the profiler results:</p>
<p><a href="http://www.rphelan.com/flex/uploads/2008/09/flv-fixed.jpg"><img class="alignnone size-full wp-image-112" title="flv-fixed" src="http://www.rphelan.com/flex/uploads/2008/09/flv-fixed.jpg" alt="" width="500" height="478" /></a></p>
<p>Success!  I wish that hadn't taken so much detective work... why aren't the Flash components built to the same standards as the Flex ones?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rphelan.com/2008/09/22/flvplayback-memory-leak-fixed/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>MXML Implementation of ChangeWatcher</title>
		<link>http://www.rphelan.com/2008/04/10/mxml-implementation-of-changewatcher/</link>
		<comments>http://www.rphelan.com/2008/04/10/mxml-implementation-of-changewatcher/#comments</comments>
		<pubDate>Thu, 10 Apr 2008 14:15:22 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Custom Components]]></category>
		<category><![CDATA[MXML]]></category>

		<guid isPermaLink="false">http://www.rphelan.com/?p=25</guid>
		<description><![CDATA[I often find myself needing a simple implementation of ChangeWatcher. I make a CreationComplete event handler for a component, create the ChangeWatcher, create a listener function, and do some simple action in the listener. I was thinking today that it would be nice if you could do all this in one line of mxml (like [...]]]></description>
			<content:encoded><![CDATA[<p>I often find myself needing a simple implementation of ChangeWatcher.  I make a CreationComplete event handler for a component, create the ChangeWatcher, create a listener function, and do some simple action in the listener.  I was thinking today that it would be nice if you could do all this in one line of mxml (like the mx:binding tag).  So, I created the RPChangeWatcher which does just that.</p>
<p>I have to credit <a href="http://brianjoseph31.typepad.com/smashedapples/2008/02/who-wants-to-se.html">Brian Holmes</a> for  providing a really easy way to  do non-visual components without extending UIComponent.  This makes the RPChangeWatcher (thusly named to avoid namespace conflicts) really lightweight.  Check out the sample application:</p>
<p><a href="http://www.rphelan.com/flex/MXMLChangeWatcher/MXMLChangeWatcher.html">application</a> -  <a href="http://www.rphelan.com/flex/MXMLChangeWatcher/srcview/index.html">source</a></p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_MXMLChangeWatcher_699230252"
			class="flashmovie"
			width="450"
			height="240">
	<param name="movie" value="http://www.rphelan.com/flex/MXMLChangeWatcher/MXMLChangeWatcher.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.rphelan.com/flex/MXMLChangeWatcher/MXMLChangeWatcher.swf"
			name="fm_MXMLChangeWatcher_699230252"
			width="450"
			height="240">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>This is a very simple example, but imagine you're using some form of MVC and the currentDP being a variable in your model.  This particular view doesn't care how or why currentDP gets updated, it just wants to display an animation to transition between datasets.  That isn't possible using regular data binding, but it's pretty clean and simple with an mxml ChangeWatcher.</p>
<p>I haven't experimented with this a lot yet, but given that you can use data binding on the host and chain properties, I can see some potential for some pretty advanced use cases.</p>
<p>Any thoughts?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rphelan.com/2008/04/10/mxml-implementation-of-changewatcher/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Creating an All-purpose Loading Indicator</title>
		<link>http://www.rphelan.com/2008/04/08/creating-an-all-purpose-loading-indicator/</link>
		<comments>http://www.rphelan.com/2008/04/08/creating-an-all-purpose-loading-indicator/#comments</comments>
		<pubDate>Tue, 08 Apr 2008 23:31:49 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Custom Components]]></category>

		<guid isPermaLink="false">http://www.rphelan.com/?p=24</guid>
		<description><![CDATA[Display an animated load indicator and fade out a control or group of controls while waiting for a response from the server. This works great for DataGrids, Images, and lots of other components. Application - Source I am working on a large project that has many different panels that populate with different kinds of data [...]]]></description>
			<content:encoded><![CDATA[<p><em>Display an animated load indicator and fade out a control or group of controls while waiting for a response from the server.  This works great for DataGrids, Images, and lots of other components.</em></p>
<p><a href="http://www.rphelan.com/flex/LoadCanvas/LoadCanvasExample.html" target="_self">Application</a> -  <a href="http://www.rphelan.com/flex/LoadCanvas/srcview/index.html" target="_self">Source</a></p>
<p>I am working on a large project that has many different panels that populate with different kinds of data from HTTP requests... i.e. an image, or a "search" window that displays its results in a datagrid.  Since they are all independent from each other, I wanted a way to disable a given control and show a load indicator while the application was waiting for a response.  There could be one or several requests pending at the same time.</p>
<p>So I created a class called LoadCanvas which extends Canvas.  The class is really simple.  It has a <code>loadImageSource </code>property for the loading indicator swf (or image), and an <code>isLoading </code>property which tells it when to display the load indicator.</p>
<p>Here's an example app:</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_LoadCanvasExample-nvs_153664921"
			class="flashmovie"
			width="470"
			height="260">
	<param name="movie" value="http://www.rphelan.com/flex/LoadCanvas/LoadCanvasExample-nvs.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.rphelan.com/flex/LoadCanvas/LoadCanvasExample-nvs.swf"
			name="fm_LoadCanvasExample-nvs_153664921"
			width="470"
			height="260">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>If you are using <a href="http://labs.adobe.com/wiki/index.php/Cairngorm">cairngorm </a>(which I highly recommend), then you can create a boolean variable in your model that is set to true in your command's <code>execute </code>function and back to false in the <code>result </code>and <code>fault </code>functions.  Then you can bind the LoadCanvas's <code>isLoading </code>property to this variable.  I sometimes also bind the <code>enabled </code>property of some of the controls, like the buttons in my example, to that variable so that the user can't make the same request several times in a row.  Notice how the buttons are disabled while the request is pending.</p>
<p><strong>Note:</strong><br />
If you are performing an operation where you <em>can</em> track the progress... then I recommend using a progress bar.  Your users will appreciate the additional feedback.</p>
<p><a href="http://www.rphelan.com/flex/LoadCanvas/LoadCanvasExample.html" target="_self">Application</a> -  <a href="http://www.rphelan.com/flex/LoadCanvas/srcview/index.html" target="_self">Source</a></p>
<p><strong>Update:</strong><br />
I have updated this component to use the Flex4 architecture.  It's not fully skinnable yet, but will hopefully fix the compatibility issue that Keith mentioned below.<br />
<a href="http://rphelan.com/flex/LoadCanvasFlex4/LoadCanvas.as">Load Canvas Flex 4 Edition</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rphelan.com/2008/04/08/creating-an-all-purpose-loading-indicator/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Flex Menu Accelerators</title>
		<link>http://www.rphelan.com/2008/03/17/flex-menu-accelerators/</link>
		<comments>http://www.rphelan.com/2008/03/17/flex-menu-accelerators/#comments</comments>
		<pubDate>Mon, 17 Mar 2008 07:06:01 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Custom Components]]></category>
		<category><![CDATA[Menu Accelerators]]></category>

		<guid isPermaLink="false">http://www.rphelan.com/archives/7</guid>
		<description><![CDATA[An experiment in placing accelerators into a Flex MenuBar, and dynamically generating key handlers to trigger the menu events. Application - Source Flex MenuBars are lacking several features that are standard on most other platforms. The most glaring of these is that lack of support for displaying accelerators (shortcut key combos like Ctrl+N for opening [...]]]></description>
			<content:encoded><![CDATA[<p><em>An experiment in placing accelerators into a Flex MenuBar, and dynamically generating key handlers to trigger the menu events.</em></p>
<p><a href="http://www.rphelan.com/flex/MenuAccelerators/MenuAccelerators.html" target="_blank">Application</a> -  <a href="http://www.rphelan.com/flex/MenuAccelerators/srcview/index.html" target="_blank">Source</a></p>
<p>Flex MenuBars are lacking several features that are standard on most other platforms.  The most glaring of these is that lack of support for displaying accelerators (shortcut key combos like Ctrl+N for opening a new file).  After hunting around on the internet a bit, I came across some sample code by <a href="http://blog.xsive.co.nz/archives/152">Campbell Anderson</a> which uses the Menu's icon to display an accelerator.  This is a step in the right direction, but the icons in a Flex Menu show up on the left side which is opposite of both Windows and Mac standards.  I wrote my own class which overrides some of MenuItemRenderer's layout logic in order to place the icon on the right.  (Scroll to the bottom for the source.)   Now we can write a menu dataProvider that looks like this:</p>
<p><img src="http://www.rphelan.com/flex/uploads/2008/03/menuaccelerators1.png" alt="menuaccelerators1.png" /></p>
<p>... and get a menu that looks like this:</p>
<p><img src="http://www.rphelan.com/flex/uploads/2008/03/menuaccelerators4.png" alt="menuaccelerators4.png" /></p>
<p>It's a good start, but I wanted to take it a step further.  Once you put together a bunch of accelerators, your key handler that listens to all of the accelerators is going to become a giant mess.  Wouldn't it be nice if your app automatically listened for all accelerator events and utilized the same handler function that you already wrote for your menu?</p>
<p><strong>Enter:  the Accelerator class</strong><br />
My solution was to create a class that encapsulates an accelerator (e.g. control key plus the letter 'Z') and generate a list of all accelerators directly from the Menu's dataProvider.  Notice that I am also storing the 'data' attribute from the menu xml... we'll be needing that later.</p>
<p><img src="http://www.rphelan.com/flex/uploads/2008/03/menuaccelerators2.png" alt="menuaccelerators2.png" /></p>
<p>Under the hood, the Accelerator class basically splits the string by '+' and pulls out each component.  It also has a handy little method called test() which accepts a KeyboardEvent, and checks to see if the event matches the accelerator.</p>
<p>Finally, I added a KEY_UP listener to the application that tests each accelerator, and if there is a match -- we can use that 'data' variable that we stored earlier to call the SAME handler that would have been called if the user clicked that menu item!</p>
<p><img src="http://www.rphelan.com/flex/uploads/2008/03/menuaccelerators3.png" alt="menuaccelerators3.png" /><br />
<strong>But - here's the down side... </strong><br />
Some browsers may trap certain key combos before they ever reach the Flash player. This means that - as far as I know - combos like Ctrl-N and Ctrl-S are out.  You may have better luck in a standalone or projector player, but I haven't tested it.  Also - It seems that you have to click on the movie to give it focus before it begins capturing key events.  This is a bit disappointing, but there seem to be quite a few options still available. Maybe use Shift in place of Ctrl?</p>
<p>So, was this a failure?  You be the judge... a nice by-product of this experiment though was the KeyUtils class which does conversions between strings and keyCodes - similar to what you can do with String.fromCharCode() and String.charCodeAt().</p>
<p><strong>Check it out:</strong><br />
In this application, clicking on menu items just displays a message indicating which item was clicked.  Try hitting some of the accelerator combos - you should get the same message you got when you clicked the item (its calling the same function.)  Remember that you have to click on the app to give it focus first.  Notice that the accelerators are compatible with 'check' and 'radio' types, and also items that branch.  The only feature that you can't use is the icon, since it is getting used to display the accelerator.</p>
<p><a href="http://www.rphelan.com/flex/MenuAccelerators/MenuAccelerators.html" target="_blank">Application</a> -  <a href="http://www.rphelan.com/flex/MenuAccelerators/srcview/index.html" target="_blank">Source</a></p>
<p><strong>Update:</strong><br />
In response to Steve's question below - here is an example which underlines characters in the menu item's label.  An ampersand preceding the character indicates that it should be underlined, and because this is XML we have to XML encode the ampersand.</p>
<p><img src="http://www.rphelan.com/flex/uploads/2008/03/menuaccelerators_5.png" alt="menuaccelerators_5.png" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rphelan.com/2008/03/17/flex-menu-accelerators/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Adding dock functionality to FlexMDI Part I</title>
		<link>http://www.rphelan.com/2008/03/09/adding-dock-functionality-to-flexmdi-part-i/</link>
		<comments>http://www.rphelan.com/2008/03/09/adding-dock-functionality-to-flexmdi-part-i/#comments</comments>
		<pubDate>Sun, 09 Mar 2008 22:55:46 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[360Flex]]></category>
		<category><![CDATA[Custom Components]]></category>
		<category><![CDATA[FlexLib]]></category>
		<category><![CDATA[FlexMDI]]></category>

		<guid isPermaLink="false">http://www.rphelan.com/archives/5</guid>
		<description><![CDATA[Ben Clinkinbeard gave a great presentation at 360&#124;Flex Atlanta about an open source project he's working on called FlexMDI (MDI stands for multiple document interface). I won't go into a lot of detail, but it's a really amazing windowing system (based on mx.controls.Panel) that has minimize, maximize, etc., and is fully resizable &#038; skinnable. I've [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.returnundefined.com/" target="_blank">Ben Clinkinbeard</a> gave a great presentation at <a href="http://www.360conferences.com/360flex/" target="_blank">360|Flex</a> Atlanta about an open source project he's working on called <a href="http://code.google.com/p/flexmdi/" title="FlexMDI" target="_blank">FlexMDI</a> (MDI stands for multiple document interface).   I won't go into a lot of detail, but it's a really amazing windowing system (based on mx.controls.Panel) that has minimize, maximize, etc., and is fully resizable & skinnable.   I've been working on a similar project, so I thought I'd see if I could combine them.</p>
<p><strong>Here's the plan:</strong><br />
My goal is to extend this library to support docking.  I'd like to take a cue from Adobe's CS3 product line, and enable three different types of docking:</p>
<ol>
<li>Dragging or resizing a window to within a certain distance of another will cause it to "snap" into alignment.</li>
<li>Dragging a window onto the bottom section of another will cause them to combine into a window stack that moves and resizes as a single unit.</li>
<li>Dragging a window onto the title bar of another window will create a single window with a tab bar at the top.</li>
</ol>
<p>To keep things simple, I'm tackling these one at a time.  Here's part I:</p>
<p><a href="http://www.rphelan.com/flex/flexMDI_dock_pt1/MDIExampleExplorer.html" target="_blank">Application</a> - <a href="http://www.rphelan.com/flex/flexMDI_dock_pt1/FlexMDI_dock_pt1.zip" target="_blank">Source</a></p>
<p>The FlexMDI guys have graciously accepted my offer to include this in a future update of <a href="http://code.google.com/p/flexlib/" target="_blank">FlexLib</a>, but the code will likely get refactored a bit first.  To illustrate the added functionality, I separated it out into two new classes: MDIDockCanvas and MDIDockManager.  These will probably end up getting merged back into the MDICanvas and MDIManager classes respectively.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rphelan.com/2008/03/09/adding-dock-functionality-to-flexmdi-part-i/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
