<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
    <channel>
        <title>Infinite Array - Flash / Flex / ActionScript experiments, tutorials and resources</title>
        <link>http://infinitearray.com/blog/</link>
        <description></description>
        <language>en</language>
        <copyright>Copyright 2008</copyright>
        <lastBuildDate>Mon, 11 Feb 2008 21:42:47 -0800</lastBuildDate>
        <generator>http://www.sixapart.com/movabletype/</generator>
        <docs>http://www.rssboard.org/rss-specification</docs>
        
        <item>
            <title>Smooth Image with Preloader, Drop Shadow, Smart Resizing in Flex</title>
            <description><![CDATA[By default, the Flex image component does not enable smoothing on scaled images, which makes them appear jagged.&nbsp; Ben Longoria has written a great <a href="http://www.infinitearray.com/experiments/smoothimageloader/">SmoothImage</a> class that overrides the image component and sets smoothing to true.&nbsp; I needed a bit more functionality out of it, so I have extended it a bit further.&nbsp; I wanted:<br /><br /><ul><li>Smart resizing which scales the image only if it won't fit in the application bounds</li><li>Drop shadow on the image</li><li>Centered preloader that displays while image is loading</li></ul>I have written an updated class that expands upon the original SmoothImage, and includes these new features.<br /><span class="mt-enclosure mt-enclosure-image"><img alt="smoothimage.jpg" src="http://infinitearray.com/blog/smoothimage.jpg" class="mt-image-left" style="margin: 0pt 20px 20px 0pt; float: left;" height="220" width="320" /></span><br /><br /><font style="font-size: 1.5625em;"><a href="http://www.infinitearray.com/experiments/smoothimageloader/">View the Example</a><br /><br /><a href="http://www.infinitearray.com/experiments/smoothimageloader/srcview/index.html">View Source</a><br /><br /><br /><br /><br /><br /><br /><font style="font-size: 0.64em;">Here is SmoothImageLoader.as</font><br /><br /></font> <iframe src="http://www.infinitearray.com/experiments/smoothimageloader/srcview/source/pkg/SmoothImageLoader.as.html" height="600" width="650">
</iframe>

]]></description>
            <link>http://infinitearray.com/blog/2008/02/smooth-image-with-preloader-dr.html</link>
            <guid>http://infinitearray.com/blog/2008/02/smooth-image-with-preloader-dr.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">experiments</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">resources</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">custom actionscript 3 component</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">Flex Image Component</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">Smooth Image Preloader</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">SmoothImage</category>
            
            <pubDate>Mon, 11 Feb 2008 21:42:47 -0800</pubDate>
        </item>
        
        <item>
            <title>Yahoo Pipes + Flex Tutorial</title>
            <description><![CDATA[<img alt="flexpipes.jpg" src="http://infinitearray.com/blog/flexpipes.jpg" class="mt-image-left" style="margin: 0pt 20px 20px 0pt; float: left;" height="80" width="300" />
Yahoo Pipes is a pretty nifty utility for quickly bundling data sources from the web into one neat feed.&nbsp; While you can do nearly everything Pipes does with ActionScript, the feeds must be cached locally for flash player to access them because of crossdomain policies.&nbsp; For this reason, it is nice to only have to cache one feed, instead of caching several and then piecing them all together.&nbsp; This also makes it easy to modify the data feed later on through the Pipes interface without having to touch ActionScript.&nbsp; <br /><font style="font-size: 1.25em;"><br /><br /><b>Building a Yahoo Pipes app</b><br /><br /></font><span class="mt-enclosure mt-enclosure-image"><a href="http://pipes.yahoo.com/pipes/pipe.info?_id=xv9z9HSr3BG_6gN48jxBKg"><img alt="pipes.jpg" src="http://infinitearray.com/blog/pipes.jpg" class="mt-image-left" style="margin: 0pt 20px 20px 0pt; float: left;" height="223" width="320" /></a></span>First, sign up for a Yahoo Pipes account if you haven't already:&nbsp; <a href="http://pipes.yahoo.com/pipes/">http://pipes.yahoo.com/pipes/</a><br />Next, create a simple Application.&nbsp; There are plenty of examples out there.&nbsp; You can always clone someone else's pipe, and modify it with your own favorite data sources. &nbsp; <br /><br />For this tutorial, I have created an app that pulls feeds from <a href="http://www.digg.com/">Digg.com</a>, and combines snapshots of the articles from <a href="http://www.snap.com/">Snap.com</a><br /><img alt="diggsnapshots.jpg" src="http://infinitearray.com/blog/diggsnapshots.jpg" class="mt-image-left" style="margin: 0pt 20px 20px 0pt; float: left;" height="80" width="300" />The sample app can be viewed here:<br /><a href="http://pipes.yahoo.com/pipes/pipe.info?_id=xv9z9HSr3BG_6gN48jxBKg">http://pipes.yahoo.com/pipes/pipe.info?_id=xv9z9HSr3BG_6gN48jxBKg</a><br /><br /><b><br /><font style="font-size: 1.25em;">Setting up PHP caching</font><br /></b>I am using a PHP RSS caching script called <a href="http://www.javascriptkit.com/dhtmltutors/ajaxticker/rssfetch.phps">RSS Fetch</a>.&nbsp; It can be easily customized to cache at specified intervals, or constantly pull the newest data.&nbsp; I have added a line to the rsslist array for the yahoo pipes RSS source:<br /><b>"Pipes" =&gt; "http://pipes.yahoo.com/pipes/pipe.run?_id=xv9z9HSr3BG_6gN48jxBKg&amp;_render=rss"</b><br />You'll also need to create a "cache" directory for the script to write to.&nbsp; My example can be seen here:<br /><a href="http://infinitearray.com/experiments/feeder/rssfetch.php?id=Pipes&amp;cachetime=5">http://infinitearray.com/experiments/feeder/rssfetch.php?id=Pipes&amp;cachetime=5</a><br /><br /><br /><b><font style="font-size: 1.25em;">Creating a Flex App</font><br /></b>Luckily, Adobe has done most of the work here.&nbsp; They've open sourced a few libraries that take care of parsing RSS feeds.&nbsp;&nbsp; You'll need both the <a href="http://code.google.com/p/as3corelib/">as3corelib</a> and the <a href="http://code.google.com/p/as3syndicationlib/">as3syndicationlib</a>.&nbsp; <a href="http://www.mikechambers.com/blog/2008/01/22/parsing-rss-20-feeds-in-actionscript-3/">Mike Chambers</a> has built a great demo App for working with these libraries.<br /><br /> <div><span class="mt-enclosure mt-enclosure-image"><a href="http://www.infinitearray.com/experiments/feeder/"><img alt="apppreview.jpg" src="http://infinitearray.com/blog/apppreview.jpg" class="mt-image-left" style="margin: 0pt 20px 20px 0pt; float: left;" height="302" width="400" /></a></span></div><div><a href="http://www.infinitearray.com/experiments/feeder/"><font style="font-size: 1.5625em;">View the demo</font></a><br /><br />I've built a simple demo application in Flex that pushes the Yahoo Pipes RSS feed into a TileList component. <br /><br />I've packaged the entire source for this application, including the external libraries.&nbsp; <br /><br /><a href="http://www.infinitearray.com/experiments/feeder/srcview/index.html"><font style="font-size: 1.5625em;">View Source</font></a><br /></div>]]></description>
            <link>http://infinitearray.com/blog/2008/02/yahoo-pipes-flex.html</link>
            <guid>http://infinitearray.com/blog/2008/02/yahoo-pipes-flex.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">tutorials</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">yahoo pipes flex rss atom feeds</category>
            
            <pubDate>Sun, 10 Feb 2008 12:19:01 -0800</pubDate>
        </item>
        
        <item>
            <title>Papervision3D Phong Shader + Bumpmaping Experiment</title>
            <description><![CDATA[I've been experimenting with the Papervision3D 2.0 (<a href="http://blog.papervision3d.org/2007/12/05/papervision3d-20-alpha-great-white/">Great White</a>) lately, and I must say I am impressed with the new features.&nbsp; Particularly cool is the ability to add shaders.&nbsp; This makes it much easier to create realistic models with higher quality textures and lower polygon counts.&nbsp; I created a quick golf ball demo to highlight the possibilities.&nbsp; The scene includes a point light, and a phong shader combining the texture and bump map applied to the sphere.&nbsp; If you look closely, you can see the light reflecting off the edges of the ball as it rotates.&nbsp; <br /><b><br />Controls:&nbsp; Arrow keys zoom in / out, pan around.&nbsp; Mouse wheel zooms. </b><br /><br /><a href="http://www.infinitearray.com/experiments/golfball/"><font style="font-size: 1.25em;"><b>Click to interact</b></font></a><br /><span class="mt-enclosure mt-enclosure-image"><a href="http://www.infinitearray.com/experiments/golfball"><img alt="golfpreview.jpg" src="http://infinitearray.com/blog/golfpreview.jpg" class="mt-image-left" style="margin: 0pt 20px 20px 0pt; float: left;" height="380" width="380" /></a></span> ]]></description>
            <link>http://infinitearray.com/blog/2008/01/papervision3d-phong-shading-bu.html</link>
            <guid>http://infinitearray.com/blog/2008/01/papervision3d-phong-shading-bu.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">experiments</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">bump mapping</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">papervision3d</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">phong</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">shaders</category>
            
            <pubDate>Mon, 07 Jan 2008 20:09:24 -0800</pubDate>
        </item>
        
        <item>
            <title>Design Patterns and ActionScript Part 1</title>
            <description><![CDATA[With the dawn of AS3, <a href="http://en.wikipedia.org/wiki/Design_pattern_(computer_science)">design patterns</a>&nbsp;are beginning to achieve popularity in ActionScript development.&nbsp; I am compiling a list of AS3 examples, which there are surprisingly few of online.&nbsp; It can be just as easy though to look at C# and Java examples on wikipedia, but it's still nice to see things in ActionScript.&nbsp; Also, check out books&nbsp; listed below.&nbsp; I use them for reference myself.<br /><br /><font style="FONT-SIZE: 1.56em">Creational:<br /></font>
<ul>
<li><font style="FONT-SIZE: 1.56em"><font style="FONT-SIZE: 0.8em"><a href="http://www.gskinner.com/blog/archives/2006/07/as3_singletons.html">Singleton</a></font></font></li>
<li><font style="FONT-SIZE: 1.56em"><font style="FONT-SIZE: 0.8em"><a href="http://www.ericfeminella.com/blog/2006/10/02/as3-factory-pattern-implementation/">Factory</a></font></font></li>
<li><font style="FONT-SIZE: 1.56em"><font style="FONT-SIZE: 0.8em"><a href="http://www.flex2components.com/f2cblog/2006/07/29/as3-builder-pattern/">Builder</a></font></font></li></ul><font style="FONT-SIZE: 1.56em"><br />Structural:<br /><a href="http://www.tink.ws/blog/stricter-singletons/"></a></font>
<ul>
<li><font style="FONT-SIZE: 1.56em"><font style="FONT-SIZE: 0.8em"><a href="http://www.as3dp.com/2007/05/26/composite-pattern-book-part-1/#more-19">Composite</a></font></font></li>
<li><font style="FONT-SIZE: 1.56em"><font style="FONT-SIZE: 0.8em"><a href="http://www.as3dp.com/category/design-patterns/flyweight/">Flyweight</a></font></font></li>
<li><font style="FONT-SIZE: 1.56em"><font style="FONT-SIZE: 0.8em"><a href="http://www.oreilly.com/catalog/9780596528461/chapter/ch04.pdf">Decorator (PDF)</a></font></font></li></ul><br /><br />Books:<br />
<ul>
<li><b><a href="http://www.amazon.com/Advanced-ActionScript-3-Design-Patterns/dp/0321426568/ref=pd_bbs_sr_2?ie=UTF8&amp;s=books"><b class="sans">Advanced ActionScript 3 with Design Patterns (Paperback)</b></a></b></li>
<li><a href="http://www.amazon.com/ActionScript-3-0-Design-Patterns-Programming/dp/0596528469/ref=pd_bbs_sr_1?ie=UTF8&amp;s=books"><b class="sans">ActionScript 3.0 Design Patterns: Object Oriented Programming Techniques </b></a></li>
<li><a href="http://www.amazon.com/exec/obidos/ASIN/0201633612/"><b class="sans">Design Patterns: Elements of Reusable Object-Oriented Software </b></a></li></ul><br /><br /><br /><a href="http://www.amazon.com/ActionScript-3-0-Design-Patterns-Programming/dp/0596528469/ref=pd_bbs_sr_1?ie=UTF8&amp;s=books"></a><br /><br /><br />]]></description>
            <link>http://infinitearray.com/blog/2008/01/design-patterns-and-actionscri.html</link>
            <guid>http://infinitearray.com/blog/2008/01/design-patterns-and-actionscri.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">resources</category>
            
            
            <pubDate>Wed, 02 Jan 2008 20:32:03 -0800</pubDate>
        </item>
        
        <item>
            <title>The best actionscript libraries for flash / flex development</title>
            <description><![CDATA[This is my complete listing of valuable resources for flash developers.&nbsp; These projects have been undertaken by talented people who have invented the wheel that people like you and I don't have to.&nbsp; Please consider donating / supporting these projects, especially if you intend to use them commercially.<br /><br /><font style="font-size: 1.25em;">3D engines: </font><br /><b>Papervision3D </b>-&nbsp; The most popular 3D engine. Easy to implement, amazingly powerful. <br /><a href="http://blog.papervision3d.org/">http://blog.papervision3d.org/</a><br /><br /><b>Away3d</b> - branch of Papervision3D focusing on advanced rendering and materials <br /><a href="http://www.away3d.com/">http://www.away3d.com/</a><br /><br /><b>Sandy</b> - Great engine for small games. Sandy was the original 3D engine, and is still quite an ambitious project.<br /><a href="http://osflash.org/sandy">http://osflash.org/sandy</a><br /><br /><font style="font-size: 1.25em;">Physics: </font><br /><b>APE</b> (Actionscript Physics Engine) - While still in early development, this is a great framework for simulating 2D physics in flash.&nbsp; <br /><a href="http://www.cove.org/ape/index.htm">http://www.cove.org/ape/index.htm</a><br /><br /><font style="font-size: 1.25em;">Animation:</font><br /><b>Tweener</b> - This is the AS3 port of mcTween, and it is fantastic.&nbsp; It has excellent event handling, and support for a lot more parameters than typically necessary.<br /><a href="http://code.google.com/p/tweener/">http://code.google.com/p/tweener/<br /></a> <br /><font style="font-size: 1.25em;">Audio: </font><br /><b>Popforge</b> - This is a library built for controlling audio playback in AS3.<br /><a href="http://code.google.com/p/popforge/">http://code.google.com/p/popforge/</a><br /><br /><font style="font-size: 1.25em;">Image Editing:</font><br /><b>Imageprocessing Library</b> (Flex Only at the moment) - Great library for doing advanced image transformations and adjustments.<br /><a href="http://blog.je2050.de/imageprocessing-library/">http://blog.je2050.de/imageprocessing-library/</a><br /><br /><font style="font-size: 1.25em;">Data / Remoting:</font><br /><b>Amfphp</b> -&nbsp; An extremely fast way to work with external data by communicating with PHP files through ActionScript Message Format.&nbsp; It is a fast versatile way to provide mySQL data interaction for your flash / flex apps.<br /><a href="http://www.amfphp.org/">http://www.amfphp.org/</a><br /><br /><font style="font-size: 1.25em;">Mashup Libraries</font><br />These are libraries that allow integration of data from various web sites with flash applications<br /><b>Flickr</b> - <a href="http://code.google.com/p/as3flickrlib/">http://code.google.com/p/as3flickrlib/</a><br /><b>YouTube</b> - <a href="http://code.google.com/p/as3youtubelib/">http://code.google.com/p/as3youtubelib/</a><br /><b>Mappr</b> - <a href="http://code.google.com/p/as3mapprlib/">http://code.google.com/p/as3mapprlib/</a><br /><b>Facebook</b> - <a href="http://code.google.com/p/facebook-actionscript-api/">http://code.google.com/p/facebook-actionscript-api/</a><b><br />Yahoo - </b><a href="http://developer.yahoo.com/flash/astra-webapis/">http://developer.yahoo.com/flash/astra-webapis/</a><b><br />Ebay </b>- <a href="http://code.google.com/p/as3ebaylib/">http://code.google.com/p/as3ebaylib/</a><b><br />Amazon Web Services - </b><a href="http://code.google.com/p/as3awss3lib/">http://code.google.com/p/as3awss3lib/</a><b><br />Odeo - </b><a href="http://code.google.com/p/as3odeolib/">http://code.google.com/p/as3odeolib/</a><b><br />LastFM - </b><a href="http://code.google.com/p/lastfm-as3/">http://code.google.com/p/lastfm-as3/</a><b><br />Atom / RSS Syndication</b> - <a href="http://code.google.com/p/as3syndicationlib/">http://code.google.com/p/as3syndicationlib/</a><br /><br />For more open source projects, visit these sites:<br /><a href="http://osflash.org/projects">http://osflash.org/projects</a><br /><a href="http://code.google.com/#q=actionscript">http://code.google.com/#q=actionscript</a><br /><br /><br /><br /> ]]></description>
            <link>http://infinitearray.com/blog/2007/11/the-best-actionscript-librarie.html</link>
            <guid>http://infinitearray.com/blog/2007/11/the-best-actionscript-librarie.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">resources</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">flash open source libraries actionscript flex</category>
            
            <pubDate>Thu, 15 Nov 2007 13:53:14 -0800</pubDate>
        </item>
        
        <item>
            <title>[Flex Labs] Overlaying a tiled PNG on an application background gradient in flex.</title>
            <description><![CDATA[<style type="text/css">
<!--
.style1 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
}
.style3 {font-family: "Courier New", Courier, monospace; font-size: 12px; }
-->
</style>
<p class="style1">This is quite a simple tutorial.&nbsp; It is more about design than programming.&nbsp; It will cover adding an application gradient background, and then overlaying a tiled PNG pattern on top.&nbsp; With a little creativity, this effect can make a nice application or website background that is not easily reproducible with html / css.<br /><br />First, begin by setting up your application.&nbsp; First we’ll add a background gradient, and set up a few other parameters:</p>
<table bgcolor="#eeeeee" border="0" cellpadding="10" height="95" width="633">
  <tbody><tr>
    <td height="84"><span class="style3">&lt;?xml version=”1.0” encoding=”utf-8”?&gt;<br />
&lt;mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; width=”100%” height=”100%” fontAntiAliasType=”advanced” layout=”absolute”<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <b>backgroundGradientColors=”[#535353,&nbsp; #2f2f2f]”</b> horizontalScrollPolicy=”off”&gt;</span></td>
  </tr>
</tbody></table>
<p class="style1"><br /></p><p class="style1">Next, we add a <b>VBox</b> that will take up the whole application background.&nbsp; The CSS class <b>dottedBG</b> will contain the location for the tile image:<span class="style1"><br />
</span></p>
<table bgcolor="#eeeeee" border="0" cellpadding="10" height="95" width="637">
  <tbody><tr>
    <td height="84"><span class="style3">&lt;mx:VBox width=”100%” height=”100%”<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; verticalAlign=”top” horizontalAlign=”center” verticalGap=”0”<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; paddingLeft=”0” paddingRight=”0” paddingTop=”30” paddingBottom=”20” <br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <b>styleName=”dottedBG”</b> </span><span class="style3">horizontalCenter=”0”</span><span class="style3">&gt;</span></td>
  </tr>
</tbody></table>
<p class="style1"><br /></p><p class="style1">Finally, add the CSS class:</p>
<table bgcolor="#eeeeee" border="0" cellpadding="10" height="78" width="456">
  <tbody><tr>
    <td height="84"><span class="style3">.dottedBG{<br />
      &nbsp;&nbsp;&nbsp; background-image:&nbsp; Embed(“dottedtile.png”);<br />
    }</span></td>
  </tr>
</tbody></table>
<p class="style1"><br /></p><p class="style1">I will post the source for this example soon.&nbsp; Feel free to post links to your own examples.<br />
</p>
<p class="style1"><br /></p><p class="style1"><br /> </p>
]]></description>
            <link>http://infinitearray.com/blog/2007/11/flex-labs-overlaying-a-tiled-p.html</link>
            <guid>http://infinitearray.com/blog/2007/11/flex-labs-overlaying-a-tiled-p.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">tutorials</category>
            
            
            <pubDate>Mon, 12 Nov 2007 15:38:04 -0800</pubDate>
        </item>
        
        <item>
            <title>[Flex Labs] Customizing the flex datagrid</title>
            <description><![CDATA[<style type="text/css">
<!--
.style1 {
	font-family: "Courier New", Courier, monospace;
	font-size: 12px;
}
.style2 {color: #339933}
.style3 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
}
-->
</style>
<span class="style3">This is a slightly advanced tutorial covering a more in depth way to customize the datagrid.&nbsp; Many of the style properties of the datagrid are protected, or not otherwise accessible.&nbsp; In order to really customize it, you will need to override specific methods related to the drawing of the component.&nbsp; Without knowing specifically which ones need to be adjusted, the implementation can be buggy.&nbsp; I have managed to go through all of the methods in the component line by line to verify which ones need to be modified. Here is a list of key methods, along with their parameters:</span><br />
<br />
<table bgcolor="eeeeee" border="0" cellpadding="10" width="732">
  <tbody><tr>
    <td width="708"><span class="style1">drawHeaderBackground(headerBG:UIComponent):void<br />
drawRowBackgrounds():void<br />
drawRowBackground(s:Sprite, rowIndex:int, y:Number, height:Number, color:uint, dataIndex:int):void <br />
updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void</span></td>
  </tr>
</tbody></table>
<p class="style3">Next, comes the actual override code. I have created an AS file named DrawListingsGrid.as in the pkg/controls/ directory of the project. I have added comments as place holders in the areas where adjustments are made.</p>
<table bgcolor="eeeeee" border="0" cellpadding="10" width="600">
  <tbody><tr>
    <td><p class="style1">package pkg.controls<br />
      {</p>
      <p class="style1">import flash.display.DisplayObject;<br />
        import flash.display.GradientType;<br />
        import flash.display.Graphics;<br />
        import flash.display.SpreadMethod;<br />
        import flash.display.Sprite;<br />
        import flash.events.MouseEvent;<br />
        import flash.display.Shape;<br />
        import flash.geom.*;<br />
        <br />
        import mx.controls.DataGrid;<br />
        import mx.controls.dataGridClasses.DataGridColumn;<br />
        import mx.controls.listClasses.IListItemRenderer;<br />
        import mx.core.EdgeMetrics;<br />
        import mx.core.mx_internal;<br />
        import mx.core.FlexSprite;<br />
        import mx.core.FlexShape;<br />
        import mx.core.UIComponent;<br />
        import flash.display.BitmapData;<br />
        import mx.core.BitmapAsset;<br />
        import mx.controls.Image;<br />
        import mx.styles.StyleManager;</p>
      <p class="style1">use namespace mx_internal;<br />
      </p>
      <p class="style1"> public class DrawListingsGrid extends DataGrid<br />
      {</p>
      <p class="style1"> <span class="style2">// embedding an image for the row background</span><br />
        [Embed(source="../assets/datagrid_row_bg.jpg")]<br />
        [Bindable]<br />
        public var rowbgCls:Class;<br />
        </p>
      <p class="style1"><span class="style2">// embedding an image for the header background</span><br />
        [Embed(source="../assets/datagrid_header_bg.jpg")]<br />
        [Bindable]<br />
        public var imgCls:Class;<br />
        <br />
        private var displayWidth:Number;<br />
        <br />
        override protected function drawHeaderBackground(headerBG:UIComponent):void<br />
        {<br />
        var g:Graphics = headerBG.graphics;<br />
        var imgObj:BitmapAsset = new imgCls() as BitmapAsset;<br />
        g.clear();<br />
        <br />
        var bm:EdgeMetrics = borderMetrics;<br />
        var adjustedWidth:Number = unscaledWidth - (bm.left + bm.right);<br />
        maskShape.width = adjustedWidth;<br />
        <br />
        var hh:Number = rowInfo.length ? rowInfo[0].height : headerHeight;<br />
        <br />
        var vdistance:int;<br />
        var vstart:int;<br />
        var vstartOffset:int;<br />
        var vdistanceOffset:int;<br />
      </p>
      <p class="style1"><span class="style2">// filling in header with embedded background image</span><br />
        g.lineStyle(0, 0x000000, 0);<br />
        g.beginBitmapFill(imgObj.bitmapData);<br />
        g.moveTo(0, 0);<br />
        g.lineTo(adjustedWidth, 0);<br />
        g.lineTo(adjustedWidth, hh);<br />
        g.lineTo(0, hh);<br />
        g.lineStyle(0, 0x000000, 0);<br />
        g.endFill();<br />
        }<br />
        <br />
        override protected function drawRowBackgrounds():void<br />
        {<br />
        if (displayWidth != unscaledWidth - viewMetrics.right - viewMetrics.left)<br />
        {<br />
        displayWidth = unscaledWidth - viewMetrics.right - viewMetrics.left;<br />
        }<br />
        var rowBGs:Sprite = Sprite(listContent.getChildByName("rowBGs"));<br />
        if (!rowBGs)<br />
        {<br />
        rowBGs = new FlexSprite();<br />
        rowBGs.mouseEnabled = false;<br />
        rowBGs.name = "rowBGs";<br />
        listContent.addChildAt(rowBGs, 0);<br />
        }<br />
        <br />
        var colors:Array;<br />
        <br />
        colors = getStyle("alternatingItemColors");<br />
        <br />
        if (!colors || colors.length == 0)<br />
        return;<br />
        <br />
        var curRow:int = 0;<br />
        curRow++;<br />
        <br />
        var i:int = 0;<br />
        var actualRow:int = verticalScrollPosition;<br />
        var n:int = listItems.length;<br />
        <br />
        while (curRow &lt; n)<br />
        {<br />
        drawRowBackground(rowBGs, i++, rowInfo[curRow].y, rowInfo[curRow].height, colors[actualRow % colors.length], actualRow);<br />
        curRow++;<br />
        actualRow++;<br />
        }<br />
        <br />
        while (rowBGs.numChildren &gt; i)<br />
        {<br />
        rowBGs.removeChildAt(rowBGs.numChildren - 1);<br />
        }<br />
      }</p>
      <p class="style1"><br />
        override protected function drawRowBackground(s:Sprite, rowIndex:int, y:Number, height:Number, color:uint, dataIndex:int):void { <br />
        <br />
        var background:Shape;<br />
        if (rowIndex &lt; s.numChildren)<br />
        {<br />
        background = Shape(s.getChildAt(rowIndex));<br />
        }<br />
        else<br />
        {<br />
        background = new FlexShape();<br />
        background.name = "background";<br />
        s.addChild(background);<br />
        }<br />
        <br />
        background.y = y;<br />
        <br />
        var height:Number = Math.min(height,
        listContent.height -
        y);<br />
        var bm:EdgeMetrics = borderMetrics;<br />
        var adjustedWidth:Number = unscaledWidth - (bm.left + bm.right);<br />
      </p>
      <p class="style1"><span class="style2">//fill the row background with the embedded image</span><br />
        var imgObj:BitmapAsset = new rowbgCls() as BitmapAsset;<br />
        <br />
        var g:Graphics = background.graphics;<br />
        g.lineStyle(0, 0x000000, 0);<br />
        g.beginBitmapFill(imgObj.bitmapData);<br />
        g.moveTo(0, 0);<br />
        g.lineTo(displayWidth, 0);<br />
        g.lineTo(displayWidth, height);<br />
        g.lineTo(0, height);<br />
        g.lineStyle(0, 0x000000, 0);<br />
        g.endFill();<br />
        <br />
        }<br />
        <br />
        override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void<br />
        {<br />
        super.updateDisplayList(unscaledWidth, unscaledHeight); <br />
        if (displayWidth != unscaledWidth - viewMetrics.right - viewMetrics.left)<br />
        {<br />
        displayWidth = unscaledWidth - viewMetrics.right - viewMetrics.left;<br />
        }<br />
    }</p></td>
  </tr>
</tbody></table>
<p class="style3">In order to use this class, you will need to embed it as a custom component in the MXML file. </p>
<table bgcolor="eeeeee" border="0" cellpadding="10" width="600">
  <tbody><tr>
    <td><span class="style1">&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"<br />
  xmlns:con="pkg.controls.*"&gt;</span></td>
  </tr>
</tbody></table>
<p class="style3">Next, you can actually add the component to the stage, by referencing the link from the header:</p>
<table bgcolor="eeeeee" border="0" cellpadding="10" width="600">
  <tbody><tr>
    <td><p class="style1">&lt;con:DrawListingsGrid width="100%" height="100%"&gt;<br />
  &lt;mx:columns&gt;<br />
  &lt;mx:DataGridColumn headerText="Column1"/&gt;<br />
  &lt;mx:DataGridColumn headerText="Column2"/&gt;
        <br />
&lt;/mx:columns&gt;<br />
&lt;/con:DrawListingsGrid&gt; </p></td>
  </tr>
</tbody></table>
]]></description>
            <link>http://infinitearray.com/blog/2007/11/flex-labs-customizing-the-flex.html</link>
            <guid>http://infinitearray.com/blog/2007/11/flex-labs-customizing-the-flex.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">tutorials</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">flex datagrid customization override methods updatedisplaylist</category>
            
            <pubDate>Thu, 08 Nov 2007 13:46:02 -0800</pubDate>
        </item>
        
    </channel>
</rss>
