<?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>Kalen Gibbons &#187; Custom Printing with Flex</title>
	<atom:link href="http://www.kalengibbons.com/blog/index.php/tag/custom-printing-with-flex/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kalengibbons.com/blog</link>
	<description>The Dead Tree Blog</description>
	<lastBuildDate>Wed, 10 Mar 2010 07:28:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Custom Printing with Flex, Part 3: Printing Data</title>
		<link>http://www.kalengibbons.com/blog/index.php/2009/04/custom-printing-with-flex-part-3-printing-data/</link>
		<comments>http://www.kalengibbons.com/blog/index.php/2009/04/custom-printing-with-flex-part-3-printing-data/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 06:19:52 +0000</pubDate>
		<dc:creator>Kalen Gibbons</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Coldfusion]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[AlivePDF]]></category>
		<category><![CDATA[Custom Printing with Flex]]></category>
		<category><![CDATA[series]]></category>

		<guid isPermaLink="false">http://www.kalengibbons.com/blog/?p=254</guid>
		<description><![CDATA[In the first article of this series, I discussed how to prevent users from printing directly from Flash&#8217;s default context menu. In the second article, I wrote about using the AlivePDF library to create PDFs from your application for printing or saving. Today I will be covering how to print application data from Flex. The [...]]]></description>
			<content:encoded><![CDATA[<p>In the <a href="http://www.kalengibbons.com/blog/index.php/2009/02/custom-printing-with-flex-part-1-overriding-flashs-built-in-printing/">first article</a> of this series, I discussed how to prevent users from printing directly from Flash&#8217;s default context menu.  In the <a href="http://www.kalengibbons.com/blog/index.php/2009/03/custom-printing-with-flex-part-2-generating-pdfs-with-alivepdf/">second article</a>, I wrote about using the <a href="http://alivepdf.org/" target="_blank">AlivePDF</a> library to create PDFs from your application for printing or saving. Today I will be covering how to print application data from Flex.</p>
<p>The Flex framework comes with several classes to assist you in printing; however, they don&#8217;t tend to produce the greatest results.  The <a href="http://livedocs.adobe.com/flex/3/langref/mx/printing/PrintDataGrid.html" target="_blank">PrintDataGrid</a> class is probably your best option when it comes to printing data, but whenever I&#8217;ve worked with it in the past I&#8217;ve always ended up disappointed.  Even after formatting, there are always issues; like rows getting cut off and pages breaks in weird places.</p>
<p>There have been talks about AlivePDF offering a Grid class to the library, which may be interesting, but it hasn&#8217;t been released and would probably only handle DataGrid data. So the best option I&#8217;ve found for printing data is to allow a server to generate a PDF, which can then be sent back to Flex and output however you want.</p>
<p>A great benefit of this option is the ability to easily format the print results.  You can use simple HTML and CSS to customize the printout much easier than you could using ActionScript.  You can also add custom styles, letterheads, and footers to fit your needs.</p>
<p>Here is an example, you can <a target="_blank" href="/assets/pages/srcview/PrintDataExample/index.html">view the source here</a>.<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_PrintDataExample_1167610492"
			class="flashmovie"
			width="750"
			height="500">
	<param name="movie" value="/assets/flash/PrintDataExample.swf" />
	<param name="bgcolor" value="#000000" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/assets/flash/PrintDataExample.swf"
			name="fm_PrintDataExample_1167610492"
			width="750"
			height="500">
		<param name="bgcolor" value="#000000" />
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>This will work with any server-side script that can generate PDF content.  In this demo I am using a ColdFusion script which simply generates an HTML table and returns it in PDF format.  You can view the ColdFusion code along with the rest of the source code <a target="_blank" href="/assets/pages/srcview/PrintDataExample/index.html">here</a>.</p>
<p>The data from the server is returned to Flex as a ByteArray.  You can take that ByteArray and output it to the user in several different ways:</p>
<h3>Using the Browser</h3>
<p>Similar to the last article in this series, you can send the results to a server-side script to either display the PDF in the browser or prompt the user to open or save the document. This time, however, the AlivePDF library is no longer necessary since the PDF binary has already been created.</p>
<div class="code">
<span class="asReserved">private</span> <span class="asFunction">function</span> generatePDF(pdfBinary:ByteArray, method:String):<span class="asReserved">void</span>{</p>
<div class="indent">
		<span class="asComment">//result comes back as binary, create a new URL request and pass it back to the server</span><br />
        <span class="asVar">var</span> header:URLRequestHeader = <span class="asReserved">new</span> URLRequestHeader(&quot;<span class="asString">Content-type</span>&quot;, &quot;<span class="asString">application/octet-stream</span>&quot;);<br />
        <span class="asVar">var</span> urlString:String = &quot;<span class="asString">http://kalengibbons.com/assets/pages/pdfCreator.cfm</span>&quot;;<br />
        <span class="asReserved">if</span>(method == &quot;<span class="asString">inline</span>&quot;)</p>
<div class="indent">
        urlString += &quot;<span class="asString">?method=inline</span>&quot;;		</div>
<p>        <span class="asReserved">else</span></p>
<div class="indent">
        urlString += &quot;<span class="asString">?method=attachment&amp;name=dataPrintSample.pdf</span>&quot;;		</div>
<p>        <span class="asVar">var</span> sendRequest:URLRequest = <span class="asReserved">new</span> URLRequest(urlString);<br />
        sendRequest.requestHeaders.push(header);<br />
        sendRequest.method = URLRequestMethod.POST;<br />
        sendRequest.data = pdfBinary;<br />
        navigateToURL(sendRequest, &quot;<span class="asString">_blank</span>&quot;);		</div>
<p>        }
</p></div>
<h3>Save locally from Flash</h3>
<p>Thanks to new capabilities in <a href="http://www.adobe.com/products/flashplayer/features/" target="_blank">Flash Player 10</a>, you can also provide users the option to save the PDF directly from Flash.  This eliminates the need for the second server-side script.</p>
<div class="code">
<span class="asReserved">private</span> <span class="asFunction">function</span> savePDF(pdfBinary:ByteArray):<span class="asReserved">void</span>{</p>
<div class="indent">
		<span class="asVar">var</span> fileRef:FileReference = <span class="asReserved">new</span> FileReference();<br />
        fileRef.save(pdfBinary, &quot;<span class="asString">yourPrintout.pdf</span>&quot;);		</div>
<p>        }
</p></div>
<p>If you plan to use the save functionality you&#8217;ll need to set the &#8220;Required Flash Player version&#8221; in your project preferences to 10.0.0 or higher or else Flex Builder will complain.  You have to remember that only users with Flash Player 10 or above will be able to use this functionality, so some type of version validation is a necessity.</p>
<p>Another caveat is that the save method must be triggered by some type of <a href="http://kb.adobe.com/selfservice/viewContent.do?externalId=kb405546" target="_blank">user interaction</a>, that&#8217;s why the sample application prompts for system access before saving.  Although the user has clicked the &#8220;Print Data&#8221; button, that event is lost when the server call is made, so we need another interaction from the user.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kalengibbons.com/blog/index.php/2009/04/custom-printing-with-flex-part-3-printing-data/feed/</wfw:commentRss>
		<slash:comments>38</slash:comments>
		</item>
		<item>
		<title>Custom Printing with Flex, Part 2: Generating PDFs with AlivePDF</title>
		<link>http://www.kalengibbons.com/blog/index.php/2009/03/custom-printing-with-flex-part-2-generating-pdfs-with-alivepdf/</link>
		<comments>http://www.kalengibbons.com/blog/index.php/2009/03/custom-printing-with-flex-part-2-generating-pdfs-with-alivepdf/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 08:10:27 +0000</pubDate>
		<dc:creator>Kalen Gibbons</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Coldfusion]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[AlivePDF]]></category>
		<category><![CDATA[Custom Printing with Flex]]></category>
		<category><![CDATA[series]]></category>

		<guid isPermaLink="false">http://www.kalengibbons.com/blog/?p=191</guid>
		<description><![CDATA[In the first article of this series, Overriding Flash’s Built-In Print Option, I discussed how to prevent users from printing directly from Flash, by replacing the default context menu. I demonstrated how poorly Flash handles printing directly, and now we will start discussing what alternatives are available to developers. In this article I will demonstrate [...]]]></description>
			<content:encoded><![CDATA[<p>In the first article of this series, <a href="http://www.kalengibbons.com/blog/index.php/2009/02/custom-printing-with-flex-part-1-overriding-flashs-built-in-printing/">Overriding Flash’s Built-In Print Option</a>, I discussed how to prevent users from printing directly from Flash, by replacing the default context menu.  I demonstrated how poorly Flash handles printing directly, and now we will start discussing what alternatives are available to developers.</p>
<p>In this article I will demonstrate how to print and save any part of your application by utilizing the <a href="http://www.alivepdf.org/" target="_blank">AlivePDF library</a>.  AlivePDF is  an ActionScript 3 open-source PDF library that easily creates PDF documents from your Flex application.  The library is pretty robust and offers much more functionality than I will be able to cover here.  In this article I want to demonstrate how simple it is to dynamically generate PDF documents using ActionScript and AlivePDF.</p>
<p>To give you a better understanding of what can be done with AlivePDF, let&#8217;s revisit one of the printing examples that was used in <a href="http://www.kalengibbons.com/blog/index.php/2009/02/custom-printing-with-flex-part-1-overriding-flashs-built-in-printing/">part 1</a> of the series.  The two images below are printouts of the The <a href="http://examples.adobe.com/flex2/inproduct/sdk/flexstore/flexstore.html" target="_blank">Flex Store</a> &#8211; one printed with Flash&#8217;s default print option and the other with AlivePDF.</p>
<table>
<tr>
<td>
<strong>Flex Store printed using Flash&#8217;s default print option</strong><br />
<img src="/assets/images/flexStore_printout.jpg" alt="Flex Store Printed from Flash" />
</td>
<td>
<strong>Flex Store printed using AlivePDF</strong><br />
<img src="/assets/images/flexStore_alivePDF.jpg" alt="Flex Store PDF created with AlivePDF" />
</td>
</tr>
</table>
<p>In addition, here is a sample application for you to play with some of AlivePDF&#8217;s options.  You can <a href="/assets/pages/srcview/AlivePDFExample/index.html" target="_blank">view the source here</a>.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_AlivePDFExample_591797119"
			class="flashmovie"
			width="750"
			height="500">
	<param name="movie" value="/assets/flash/AlivePDFExample.swf" />
	<param name="bgcolor" value="#000000" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/assets/flash/AlivePDFExample.swf"
			name="fm_AlivePDFExample_591797119"
			width="750"
			height="500">
		<param name="bgcolor" value="#000000" />
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>So now that you&#8217;ve had a taste of what AlivePDF can do, lets look at how it works:</p>
<h3>Adding AlivePDF to your project</h3>
<p>First, download the library from <a href="http://www.alivepdf.org/" target="_blank">www.AlivePDF.org</a>, and then add it to your project in one of two ways.  The easiest way is to copy the AlivePDF.swc into your project&#8217;s <em>lib</em> folder.  Flex Builder should automatically detect the swc and add it to the compile settings.  The second approach is to add it manually in Flex Builder, by clicking Project >> Properties >> Flex Build Path >> Library Path >> Add SWC&#8230; and selecting the swc from the file system.</p>
<h3>Displaying PDFs in the Browser</h3>
<p>After the swc has been added to your project you can begin working with the AlivePDF library.  The sample code below could be used to generate a PDF document from any UI component in your application.  We simply turn it into an image (think of it as a screenshot) and publish it to a PDF for the user to save or print.  </p>
<p>The code is fairly simple, we start by creating a new instance of the PDF class and adding a page to it. Then we add our UIComponent to the document as an image.  Finally, we tell AlivePDF how we want to generate the PDF with the save() method.  In this example, the third argument of the method, Download.INLINE, specifies that we want the PDF to be displayed in the browser instead of prompting the user to save (that will be covered in the next section).</p>
<div class="code">
<p><span class="asReserved">import</span> mx.core.UIComponent;</p>
<p>&nbsp;</p>
<p><span class="asReserved">import</span> org.alivepdf.display.Display;<br />
        <span class="asReserved">import</span> org.alivepdf.images.ResizeMode;<br />
        <span class="asReserved">import</span> org.alivepdf.layout.Layout;<br />
        <span class="asReserved">import</span> org.alivepdf.layout.Orientation;<br />
        <span class="asReserved">import</span> org.alivepdf.layout.Size;<br />
        <span class="asReserved">import</span> org.alivepdf.layout.Unit;<br />
        <span class="asReserved">import</span> org.alivepdf.pdf.PDF;<br />
        <span class="asReserved">import</span> org.alivepdf.saving.Download;</p>
<p><span class="asReserved">import</span> org.alivepdf.saving.Method;</p>
<p>&nbsp;</p>
<p>
        <span class="asReserved">private</span> <span class="asFunction">function</span> doPrint(whatToPrint:UIComponent):<span class="asReserved">void</span>{</p>
<div class="indent">
		<span class="asVar">var</span> printPDF:PDF = <span class="asReserved">new</span> PDF( Orientation.LANDSCAPE, Unit.MM, Size.A4 );<br />
        printPDF.setDisplayMode( Display.FULL_PAGE, Layout.SINGLE_PAGE );<br />
        printPDF.addPage();<br />
        printPDF.addImage( whatToPrint, 0, 0, 0, 0, <span class="asString">&#8216;PNG&#8217;</span>, 100, 1, ResizeMode.FIT_TO_PAGE );<br />
        printPDF.save( Method.REMOTE, <span class="asString">&quot;/includes/pdfCreator.cfm&quot;</span>, Download.INLINE, <span class="asString">&quot;test.pdf&quot;</span> );    </div>
<p>    }</p>
</div>
<h3>Prompting Users to Save</h3>
<p>Now that works great and all&#8230; but what if you want to prompt the user to save or open in Adobe Reader?  Fortunately, AlivePDF makes that easy; all you have have to do is change Download.INLINE to Download.ATTACHMENT.</p>
<div class="code">
printPDF.save( Method.REMOTE, <span class="asString">&quot;/includes/pdfCreator.cfm&quot;</span>, Download.ATTACHMENT, <span class="asString">&quot;test.pdf&quot;</span> );
</div>
<h3>Using AlivePDF with ColdFusion</h3>
<p>A PHP script is provided with the download of the AlivePDF library, but if you don&#8217;t like PHP you can use any other server-side language that can generate PDF content.  For those of you who are ColdFusion fans, like myself, here is a basic example of a ColdFusion script that can be used.</p>
<div class="code">
<p><span class="cfComment">&lt;!&ndash;&ndash;&ndash; establish parameters &ndash;&ndash;&ndash;&gt;</span><br />
        <span class="cfTag">&lt;cfparam name=</span><span class="cfString">&quot;URL.method&quot;</span><span class="cfTag"> default=</span><span class="cfString">&quot;&quot;</span><span class="cfTag"> /&gt;<br />
&lt;cfparam name=</span><span class="cfString">&quot;URL.name&quot;</span><span class="cfTag"> default=</span><span class="cfString">&quot;&quot;</span><span class="cfTag"> /&gt;</span></p>
<p>&nbsp;</p>
<p>        <span class="cfComment">&lt;&ndash;&ndash;&ndash; get the content from the http data &ndash;&ndash;&ndash;&gt;</span><br />
        <span class="cfTag">&lt;cfset</span> httpContent = <span class="cfReserved">GetHttpRequestData()</span><span class="cfTag">&gt;</span><br /><br/>
    </p>
<p><span class="cfComment">&lt;!&ndash;&ndash;&ndash; make sure content was passed in &ndash;&ndash;&ndash;&gt;</span><br />
        <span class="cfTag">&lt;cfif</span> <span class="cfReserved">len(</span>httpContent.content<span class="cfReserved">)</span> <span class="cfReserved">gt</span> <span class="cfNumber">0</span><span class="cfTag">&gt;</span></p>
<div class="indent">
			<span class="cfComment">&lt;!&ndash;&ndash;&ndash; write the content to local pdf &ndash;&ndash;&ndash;&gt;</span><br />
<span class="cfTag">&lt;cfheader name=</span><span class="cfString">&quot;Content-Disposition&quot;</span><span class="cfTag"> value=</span><span class="cfString">&quot;#URL.method#; filename=#URL.name#&quot;</span>&nbsp;<span class="cfTag">/&gt;</span><br />
			<span class="cfTag">&lt;cfcontent type=</span><span class="cfString">&quot;application/pdf&quot;</span> <span class="cfTag">variable=</span><span class="cfString">&quot;#httpContent.content#&quot;</span><span class="cfTag">&gt;</span></div>
<p>	    <span class="cfTag">&lt;cfelse&gt;</span></p>
<div class="indent">
		<span class="cfComment">&lt;!&ndash;&ndash;&ndash; redirect to home page &ndash;&ndash;&ndash;&gt;</span><br />
		<span class="cfTag">&lt;cflocation url=</span><span class="cfString">&quot;/&quot;</span><span class="cfTag"> /&gt;</span></div>
<p>	<span class="cfTag">&lt;/cfif&gt;</span> </p>
</div>
<p>AlivePDF has a wide range of capabilities and we&#8217;ve barely scratched the surface here.  I encourage you to take a good look at the library and utilize it to its full potential.</p>
<p>In the next article in this serious we will discuss how to print data from Flex.  See you soon!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kalengibbons.com/blog/index.php/2009/03/custom-printing-with-flex-part-2-generating-pdfs-with-alivepdf/feed/</wfw:commentRss>
		<slash:comments>67</slash:comments>
		</item>
		<item>
		<title>Custom Printing with Flex, Part 1: Overriding Flash&#8217;s Built-In Print Option</title>
		<link>http://www.kalengibbons.com/blog/index.php/2009/02/custom-printing-with-flex-part-1-overriding-flashs-built-in-printing/</link>
		<comments>http://www.kalengibbons.com/blog/index.php/2009/02/custom-printing-with-flex-part-1-overriding-flashs-built-in-printing/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 21:27:19 +0000</pubDate>
		<dc:creator>Kalen Gibbons</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[contextMenu]]></category>
		<category><![CDATA[contextMenuItem]]></category>
		<category><![CDATA[Custom Printing with Flex]]></category>
		<category><![CDATA[series]]></category>

		<guid isPermaLink="false">http://www.kalengibbons.com/blog/?p=145</guid>
		<description><![CDATA[If you&#8217;re like me and you&#8217;ve spent any time working with printing in Flex, you&#8217;ve probably realized that Flash&#8217;s built-in printing capabilities leave a lot to be desired. So I&#8217;ve decided to create a short series of articles on how to do custom printing in Flex. This article will be the first in the series [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re like me and you&#8217;ve spent any time working with printing in Flex, you&#8217;ve probably realized that Flash&#8217;s built-in printing capabilities leave a lot to be desired.  So I&#8217;ve decided to create a short series of articles on how to do custom printing in Flex.  This article will be the first in the series and will discuss how to prevent users from printing directly from the context menu.</p>
<div style="text-align: center">
<img alt="Default Flash Context Menu" src="/assets/images/FlashContextMenu.gif" title="Default Flash Context Menu" width="250" height="124" />
</div>
<p>By default, when users right-click on a SWF file, they receive the default context menu, which provides them several options, and one of which is the ability to print.  However, in my experience, using this option for printing returns horrible results.  Below are two examples of this, the first is the <a href=" http://examples.adobe.com/flex2/inproduct/sdk/flexstore/flexstore.html" target="_blank">The Flex Store</a>, a sample application from Adobe, and the second is the <a href="http://mediastore.verizonwireless.com/" target="_blank">Verizon Media Store</a>.  On the left is a screenshot of each and on the right is a capture of the print results that were produced by using the default print option.</p>
<table>
<tr>
<td>
<strong>The Flex Store application:</strong><br />
<img alt="Flex Store Screenshot" src="/assets/images/flexstore_screenshot.jpg" title="Flex Store Screenshot" width="365" height="216" />
</td>
<td>
<strong>Printing the Flex Store:</strong><br />
<img alt="Flex Store Printout" src="/assets/images/flexstore_printout.jpg" title="Flex Store Printout" width="365" height="216" align="center" />
</td>
</tr>
<tr>
<td>
<strong>The Verizon Media Store:</strong><br />
<img alt="Verizon Media Store Screenshot" src="/assets/images/verizonMediaStore_screenshot.jpg" title="Verizone Media Store Screenshot" width="365" height="216" />
</td>
<td>
<strong>Printing the Verizon Media Store:</strong><br />
<img alt="Verizon Media Store Printout" src="/assets/images/verizonMediaStore_printout.jpg" title="Flex Store Printout" width="365" height="216" />
</td>
</tr>
</table>
<p>As you can see, the results were less than satisfactory.  I would consider this unacceptable for my applications.  So, the question arises: <strong>&#8220;How do you prevent users from printing from the context menu?&#8221;</strong></p>
<p>The answer is simple &#8211; override Flash&#8217;s built-in context menu with your own.  This is how you do it:<br/><br/></p>
<div class="code">
<span class="asReserved">private</span> <span class="asFunction">function</span> setContextMenu():<span class="asReserved">void</span>{</p>
<div class="indent">
<span class="asComment">//create the new contextMenu </span><br />
<span class="asVar">var</span> customContextMenu:ContextMenu = <span class="asReserved">new</span> ContextMenu();<br />
<span class="asComment">//disable the default options</span><br />
customContextMenu.hideBuiltInItems();</p>
<p><span class="asComment">//create your own print option, and add it to the new contextMenu</span><br />
<span class="asVar">var</span> printOption:ContextMenuItem = <span class="asReserved">new</span> ContextMenuItem(<span class="asString">&quot;Print Me&quot;</span>);<br />
printOption.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, doPrint);<br />
customContextMenu.customItems.push(printOption);</p>
<p><span class="asComment">//set the newly created contextMenu for this application</span><br />
<span class="asReserved">this</span>.contextMenu = customContextMenu;</div>
<p>}<br />
<br />
<span class="asReserved">private</span> <span class="asFunction">function</span> doPrint(event:ContextMenuEvent):<span class="asReserved">void</span>{<br />
<span class="asComment indent">//now print this application</span><br />
}
</div>
<p>Okay, so let&#8217;s review the code.  The first thing you need to do is to create a new ContextMenu and then call its <strong>hideBuiltInItems</strong> menthod to disable the built-in options (forwardAndBack, loop, play, print, quality, rewind, save, and zoom).  This hides the print option and prevents the user from clicking it.  Next you add our own menu item to replace the default print option.  If you don&#8217;t want to do this, because you are going to provide your own print button on the application, you can skip ahead to the last line of code.</p>
<p>To add our own menu option, just create a new <strong>ContextMenuItem</strong> object and give it a label. Then add an event listener to catch when the user clicks on this option (in this example we have specified <em>doPrint</em> as our listener function; we will be working with that method in the proceeding articles of this series).  Finally, add our new menu item to the customItems array, and set our new menu as the contextMenu for the application.</p>
<p>You can see the results below. Although nothing spectacular has taken place here, we&#8217;ve disabled Flash&#8217;s built-in print capabilities and will be routing all print requests through our own function.</p>
<div style="text-align: center">
<img alt="Default Flash Context Menu" src="/assets/images/CustomContextMenu.gif" title="Custom Context Menu" width="250" height="132" />
</div>
<p><strong>Gotcha:</strong><br/><br />
When creating CustomMenuItems, the labels you provide must be different than those provided by the default items.  For example, you cannot use &#8220;Print&#8221; as your label or the application will ignore the option.  However, you can use variations, such as &#8220;Print This&#8221; or &#8220;Print Page.&#8221;</li>
</p>
<p><br/>In the next article we will discuss how to generate PDF documents for more functional printing and saving.  For more information of the ContextMenu, check out the <a href="http://livedocs.adobe.com/flex/3/langref/flash/ui/ContextMenu.html" target="_blank">Livedocs</a>.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kalengibbons.com/blog/index.php/2009/02/custom-printing-with-flex-part-1-overriding-flashs-built-in-printing/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
