<?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>GravityBlast &#187; AIR</title>
	<atom:link href="http://gravityblast.com/category/air/feed/" rel="self" type="application/rss+xml" />
	<link>http://gravityblast.com</link>
	<description>...coding blast beat!</description>
	<lastBuildDate>Thu, 08 Apr 2010 08:12:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using CouchDB from Air applications with CouchDB Flex</title>
		<link>http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/</link>
		<comments>http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 14:31:37 +0000</pubDate>
		<dc:creator>Andrea Franz</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Couchdb]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://gravityblast.com/?p=379</guid>
		<description><![CDATA[In the last weeks I played a lot with CouchDB and I love it. I always used it from ruby but yesterday I tried to use it with flex. I started a new Actionscript project called CouchDB Flex, you can browse the source from github. The implementation is inspired by couchrest, but it&#8217;s asynchronous because [...]]]></description>
			<content:encoded><![CDATA[<p>In the last weeks I played a lot with <a href="http://couchdb.apache.org/" title="CouchDB">CouchDB</a> and I love it. I always used it from ruby but yesterday I tried to use it with flex. I started a new Actionscript project called <a href="http://github.com/pilu/couchdb-flex" title="CouchDB Flex">CouchDB Flex</a>, you can browse the source from <a href="http://github.com/pilu/couchdb-flex" title="CouchDB Flex on Github">github</a>. The implementation is inspired by <a href="http://github.com/jchris/couchrest">couchrest</a>, but it&#8217;s asynchronous because I use <a href="http://livedocs.adobe.com/flex/3/langref/flash/net/URLLoader.html" title="URLLoaer">URLLoader</a> internally. Since the flash player  doesn&#8217;t support the PUT and DELETE HTTP methods, you must create an AIR project if you want to try the library.  You can find a compiled swc <a href="http://github.com/pilu/couchdb-flex/downloads">here</a>, put it in your libs folder and you are ready to go. Here a small example, but it&#8217;s still in development, and a lot of functionality are not implemented yet.</p>
<p><strong>CouchdbFlexExample.mxml:</strong> the main mxml file, it&#8217;s just a window with a textarea that will display the data loaded from CouchDB.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>c<span style="color: #000000; font-weight: bold;">:</span>App xmlns<span style="color: #000000; font-weight: bold;">:</span>fx=<span style="color: #990000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> xmlns<span style="color: #000000; font-weight: bold;">:</span>s=<span style="color: #990000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> xmlns<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">c</span>=<span style="color: #990000;">&quot;com.gravityblast.couchdbflexexample.*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
  <span style="color: #000000; font-weight: bold;">&lt;</span>s<span style="color: #000000; font-weight: bold;">:</span>TextArea id=<span style="color: #990000;">&quot;textarea&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{log}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>			
<span style="color: #000000; font-weight: bold;">&lt;/</span><span style="color: #004993;">c</span><span style="color: #000000; font-weight: bold;">:</span>App<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p><strong>com/gravityblast/couchdbflexexample/Contact.as:</strong> the model I&#8217;ll save on CouchDB. By default the model has a name and an email, but I can add more properties since it&#8217;s a dynamic class.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.gravityblast.couchdbflexexample
<span style="color: #000000;">&#123;</span>
  <span style="color: #0033ff; font-weight: bold;">import</span> com.gravityblast.couchdb.Document;
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">public</span> dynamic <span style="color: #9900cc; font-weight: bold;">class</span> Contact extends Document
  <span style="color: #000000;">&#123;</span>		
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">name</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> email<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Contact<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
      <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p><strong>com/gravityblast/couchdbflexexample/App.as:</strong> the main application, where I create a new Contact Document, and I load all the contacts using a view created with the Design and View classes.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.gravityblast.couchdbflexexample
<span style="color: #000000;">&#123;</span>
  <span style="color: #0033ff; font-weight: bold;">import</span> com.gravityblast.couchdb.CouchDb;
  <span style="color: #0033ff; font-weight: bold;">import</span> com.gravityblast.couchdb.Database;
  <span style="color: #0033ff; font-weight: bold;">import</span> com.gravityblast.couchdb.Design;
  <span style="color: #0033ff; font-weight: bold;">import</span> com.gravityblast.couchdb.View;
  <span style="color: #0033ff; font-weight: bold;">import</span> com.gravityblast.couchdb.events.CouchRestEvent;
  <span style="color: #0033ff; font-weight: bold;">import</span> com.gravityblast.couchdb.events.DocumentEvent;
  <span style="color: #0033ff; font-weight: bold;">import</span> com.gravityblast.couchdb.events.ViewEvent;
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">import</span> mx.events.FlexEvent;
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">import</span> spark.components.TextArea;
  <span style="color: #0033ff; font-weight: bold;">import</span> spark.components.WindowedApplication;
&nbsp;
  <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> App extends WindowedApplication
  <span style="color: #000000;">&#123;</span>		
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> couchdb<span style="color: #000000; font-weight: bold;">:</span>CouchDb;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> database<span style="color: #000000; font-weight: bold;">:</span>Database;
&nbsp;
    <span style="color: #000000;">&#91;</span>Bindable<span style="color: #000000;">&#93;</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> 	<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">log</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>;
    <span style="color: #0033ff; font-weight: bold;">public</span> 	<span style="color: #6699cc; font-weight: bold;">var</span> textarea<span style="color: #000000; font-weight: bold;">:</span>TextArea;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> App<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>			
      <span style="color: #0033ff; font-weight: bold;">this</span>.couchdb = <span style="color: #0033ff; font-weight: bold;">new</span> CouchDb<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #0033ff; font-weight: bold;">this</span>.database = <span style="color: #0033ff; font-weight: bold;">this</span>.couchdb.database<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;couchdb-flex-example&quot;</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">log</span> = <span style="color: #990000;">&quot;&quot;</span>;
      <span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>FlexEvent.CREATION_COMPLETE, <span style="color: #0033ff; font-weight: bold;">this</span>.creationCompleteHandler<span style="color: #000000;">&#41;</span>;
      <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> creationCompleteHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span>FlexEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>			
      <span style="color: #0033ff; font-weight: bold;">this</span>.database.create<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span>.databaseCreateHandler<span style="color: #000000;">&#41;</span>;	
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> databaseCreateHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span>CouchRestEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>
      <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>event.json.ok <span style="color: #000000; font-weight: bold;">||</span> event.json.<span style="color: #004993;">error</span>.<span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> == <span style="color: #990000;">&quot;file_exists&quot;</span><span style="color: #000000;">&#41;</span>
      <span style="color: #000000;">&#123;</span>
        <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">map</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;function(doc) {if (doc['couchdb-flex-type'] == 'com.gravityblast.couchdbflexexample::Contact') emit(null, doc);}&quot;</span>;
        <span style="color: #6699cc; font-weight: bold;">var</span> view<span style="color: #000000; font-weight: bold;">:</span>View = <span style="color: #0033ff; font-weight: bold;">new</span> View<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;all&quot;</span>, <span style="color: #004993;">map</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #6699cc; font-weight: bold;">var</span> design<span style="color: #000000; font-weight: bold;">:</span>Design = <span style="color: #0033ff; font-weight: bold;">new</span> Design<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;contacts&quot;</span><span style="color: #000000;">&#41;</span>;
        design.addView<span style="color: #000000;">&#40;</span>view<span style="color: #000000;">&#41;</span>;
        design.<span style="color: #004993;">save</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span>.designSaveHandler<span style="color: #000000;">&#41;</span>;	
      <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> designSaveHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span>DocumentEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>
      <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span>;									
      <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>event.json.ok <span style="color: #000000; font-weight: bold;">||</span> event.json.<span style="color: #004993;">error</span> == <span style="color: #990000;">&quot;conflict&quot;</span><span style="color: #000000;">&#41;</span>			
        <span style="color: #0033ff; font-weight: bold;">this</span>.createContacts<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #0033ff; font-weight: bold;">else</span>
        <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Error saving design document: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> event.<span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span>			
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> createContacts<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>
      <span style="color: #6699cc; font-weight: bold;">var</span> contact<span style="color: #000000; font-weight: bold;">:</span>Contact = <span style="color: #0033ff; font-weight: bold;">new</span> Contact<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      contact.<span style="color: #004993;">name</span>    = <span style="color: #990000;">&quot;jack&quot;</span>;
      contact.email   = <span style="color: #990000;">&quot;jack@example.com&quot;</span>;
      contact.address = <span style="color: #990000;">&quot;Jack Street&quot;</span>;
      contact.<span style="color: #004993;">save</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span>.contactSaveHandler<span style="color: #000000;">&#41;</span>;			
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> contactSaveHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span>DocumentEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>			
      <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #6699cc; font-weight: bold;">var</span> contact<span style="color: #000000; font-weight: bold;">:</span>Contact = event.document <span style="color: #0033ff; font-weight: bold;">as</span> Contact;
      contact.address = <span style="color: #990000;">&quot;Jack Street updated at &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      contact.<span style="color: #004993;">save</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span>.contactUpdateHandler<span style="color: #000000;">&#41;</span>;			
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> contactUpdateHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span>DocumentEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>			
      <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span>;
      View.<span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;contacts&quot;</span>, <span style="color: #990000;">&quot;all&quot;</span>, <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span>, <span style="color: #0033ff; font-weight: bold;">this</span>.contactsLoadHandler<span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> contactsLoadHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span>ViewEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>					
      <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #0033ff; font-weight: bold;">each</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> contact<span style="color: #000000; font-weight: bold;">:</span>Contact <span style="color: #0033ff; font-weight: bold;">in</span> event.documents<span style="color: #000000;">&#41;</span>
      <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> property<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> <span style="color: #0033ff; font-weight: bold;">in</span> contact.<span style="color: #004993;">attributes</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
          <span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">log</span> <span style="color: #000000; font-weight: bold;">+</span>= property <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> contact<span style="color: #000000;">&#91;</span>property<span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;<span style="">\n</span>&quot;</span>;	
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">log</span> <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;-------------<span style="">\n</span>&quot;</span>;
      <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>I&#8217;ll write more about the library as soon as it&#8217;s more stable.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>share</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/&amp;submitHeadline=Using+CouchDB+from+Air+applications+with+CouchDB+Flex&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/&amp;title=Using+CouchDB+from+Air+applications+with+CouchDB+Flex" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/&amp;title=Using+CouchDB+from+Air+applications+with+CouchDB+Flex" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Using+CouchDB+from+Air+applications+with+CouchDB+Flex&amp;url=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/&amp;title=Using+CouchDB+from+Air+applications+with+CouchDB+Flex" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/&amp;title=Using+CouchDB+from+Air+applications+with+CouchDB+Flex" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/&amp;T=Using+CouchDB+from+Air+applications+with+CouchDB+Flex" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/&amp;title=Using+CouchDB+from+Air+applications+with+CouchDB+Flex" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/&amp;title=Using+CouchDB+from+Air+applications+with+CouchDB+Flex" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/&amp;title=Using+CouchDB+from+Air+applications+with+CouchDB+Flex" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Using+CouchDB+from+Air+applications+with+CouchDB+Flex+@+http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/&amp;t=Using+CouchDB+from+Air+applications+with+CouchDB+Flex" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://gravityblast.com/2009/11/03/using-couchdb-from-air-applications-with-couchdb-flex/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Creating PDF with images using flex and AlivePDF</title>
		<link>http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/</link>
		<comments>http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 00:25:39 +0000</pubDate>
		<dc:creator>Andrea Franz</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://gravityblast.com/?p=216</guid>
		<description><![CDATA[
Today I&#8217;m working on an AIR application, and I need to create a PDF starting from a list of images. This PDF needs to have one image for each page. I used AlivePDF, a very useful ActionScript3 library for PDF generation, and I created a simple class that takes an array of image paths and [...]]]></description>
			<content:encoded><![CDATA[<p>
Today I&#8217;m working on an AIR application, and I need to create a PDF starting from a list of images. This PDF needs to have one image for each page. I used<a href="http://alivepdf.bytearray.org/" title="AlivePDF"> AlivePDF</a>, a very useful ActionScript3 library for PDF generation, and I created a simple class that takes an array of image paths and creates the PDF I need.
</p>
<p>Here the class I use:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>	
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">EventDispatcher</span>;
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">filesystem</span>.<span style="color: #006600;">File</span>;
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">filesystem</span>.<span style="color: #006600;">FileMode</span>;
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">filesystem</span>.<span style="color: #006600;">FileStream</span>;
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLLoader</span>;
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLLoaderDataFormat</span>;
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLRequest</span>;
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">ByteArray</span>;
&nbsp;
  <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">alivepdf</span>.<span style="color: #006600;">pdf</span>.<span style="color: #006600;">PDF</span>;	
  <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">alivepdf</span>.<span style="color: #006600;">display</span>.<span style="color: #006600;">Display</span>;
  <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">alivepdf</span>.<span style="color: #006600;">images</span>.<span style="color: #006600;">ResizeMode</span>;
  <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">alivepdf</span>.<span style="color: #006600;">layout</span>.<span style="color: #006600;">Layout</span>;
  <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">alivepdf</span>.<span style="color: #006600;">layout</span>.<span style="color: #006600;">Orientation</span>;
  <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">alivepdf</span>.<span style="color: #006600;">layout</span>.<span style="color: #0066CC;">Size</span>;
  <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">alivepdf</span>.<span style="color: #006600;">layout</span>.<span style="color: #006600;">Unit</span>;
  <span style="color: #0066CC;">import</span> org.<span style="color: #006600;">alivepdf</span>.<span style="color: #006600;">saving</span>.<span style="color: #006600;">Method</span>;
&nbsp;
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PdfGenerator <span style="color: #0066CC;">extends</span> EventDispatcher
  <span style="color: #66cc66;">&#123;</span>		  
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> pdf:PDF;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> images:<span style="color: #0066CC;">Array</span>;		
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> outFilePath:<span style="color: #0066CC;">String</span>;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> completedPages:<span style="color: #0066CC;">int</span>;
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> PdfGenerator<span style="color: #66cc66;">&#40;</span>images:<span style="color: #0066CC;">Array</span>, outFilePath:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">outFilePath</span> = outFilePath;
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">images</span> = images;
    <span style="color: #66cc66;">&#125;</span>				
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> generate<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>						
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">completedPages</span> = <span style="color: #cc66cc;">0</span>;
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">pdf</span> = <span style="color: #000000; font-weight: bold;">new</span> PDF<span style="color: #66cc66;">&#40;</span>Orientation.<span style="color: #006600;">LANDSCAPE</span>, Unit.<span style="color: #006600;">MM</span>, <span style="color: #0066CC;">Size</span>.<span style="color: #006600;">A4</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">nextPage</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;		
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> nextPage<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">completedPages</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #0066CC;">this</span>.<span style="color: #006600;">images</span>.<span style="color: #0066CC;">length</span> ? <span style="color: #0066CC;">this</span>.<span style="color: #006600;">loadImage</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">images</span><span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">completedPages</span>++<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">this</span>.<span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> loadImage<span style="color: #66cc66;">&#40;</span>path:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>						
      <span style="color: #000000; font-weight: bold;">var</span> urlLoader:URLLoader = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;			
      urlLoader.<span style="color: #006600;">dataFormat</span> = URLLoaderDataFormat.<span style="color: #006600;">BINARY</span>;
      urlLoader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, <span style="color: #0066CC;">this</span>.<span style="color: #006600;">onImageLoadComplete</span><span style="color: #66cc66;">&#41;</span>;
      urlLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span>path<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;						
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onImageLoadComplete<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>						
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">pdf</span>.<span style="color: #0066CC;">addPage</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">pdf</span>.<span style="color: #006600;">addImageStream</span><span style="color: #66cc66;">&#40;</span>ByteArray<span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">1</span>, ResizeMode.<span style="color: #006600;">FIT_TO_PAGE</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">dispatchEvent</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> PdfGeneratorEvent<span style="color: #66cc66;">&#40;</span>PdfGeneratorEvent.<span style="color: #006600;">PDF_GENERATOR_PAGE_COMPLETE</span>, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #0066CC;">this</span>.<span style="color: #006600;">images</span>.<span style="color: #0066CC;">length</span>, <span style="color: #0066CC;">this</span>.<span style="color: #006600;">completedPages</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">nextPage</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> save<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>				
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">pdf</span>.<span style="color: #0066CC;">end</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">writeOutFile</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;												
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">dispatchEvent</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> PdfGeneratorEvent<span style="color: #66cc66;">&#40;</span>PdfGeneratorEvent.<span style="color: #006600;">PDF_GENERATOR_COMPLETE</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> writeOutFile<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
    <span style="color: #66cc66;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">var</span> fileStream:FileStream = <span style="color: #000000; font-weight: bold;">new</span> FileStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;								
      fileStream.<span style="color: #006600;">open</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> File<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">outFilePath</span><span style="color: #66cc66;">&#41;</span>, FileMode.<span style="color: #006600;">WRITE</span><span style="color: #66cc66;">&#41;</span>;			
      fileStream.<span style="color: #006600;">writeBytes</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">pdf</span>.<span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span>Method.<span style="color: #006600;">LOCAL</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
      fileStream.<span style="color: #0066CC;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Basically for each image it creates a new URLRequest and when the request is completed it adds a new page with the image. As you can see I also dispatch a custom Event called PdfGeneratorEvent. That because I need to create a PDF with a large number of images, and doing like this I can give a feedback to the user with a ProgressBar that display the generation progress.
</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
&nbsp;
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PdfGeneratorEvent <span style="color: #0066CC;">extends</span> Event
  <span style="color: #66cc66;">&#123;</span>			
    <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const PDF_GENERATOR_PAGE_COMPLETE:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;PDF_GENERATOR_PAGE_COMPLETE&quot;</span>;
    <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const PDF_GENERATOR_COMPLETE:<span style="color: #0066CC;">String</span>      = <span style="color: #ff0000;">&quot;PDF_GENERATOR_COMPLETE&quot;</span>;			
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> totalPages:<span style="color: #0066CC;">int</span>;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> completedPages:<span style="color: #0066CC;">int</span>;
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> PdfGeneratorEvent<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>:<span style="color: #0066CC;">String</span>, bubbles:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span>, cancelable:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span>, totalPages:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">0</span>, completedPages:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>			
      <span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>, bubbles, cancelable<span style="color: #66cc66;">&#41;</span>;
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">totalPages</span>     = totalPages;
      <span style="color: #0066CC;">this</span>.<span style="color: #006600;">completedPages</span> = completedPages;
    <span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>And here the main file that uses this class:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> createPdf<span style="color: #66cc66;">&#40;</span>images:<span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">var</span> generator:PdfGenerator = <span style="color: #000000; font-weight: bold;">new</span> PdfGenerator<span style="color: #66cc66;">&#40;</span>images, <span style="color: #ff0000;">&quot;/path/to/my/test.pdf&quot;</span><span style="color: #66cc66;">&#41;</span>;
  generator.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>PdfGeneratorEvent.<span style="color: #006600;">PDF_GENERATOR_COMPLETE</span>, <span style="color: #0066CC;">this</span>.<span style="color: #006600;">onPdfComplete</span><span style="color: #66cc66;">&#41;</span>;
  generator.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>PdfGeneratorEvent.<span style="color: #006600;">PDF_GENERATOR_PAGE_COMPLETE</span>, <span style="color: #0066CC;">this</span>.<span style="color: #006600;">onPdfPageComplete</span><span style="color: #66cc66;">&#41;</span>;				
  generator.<span style="color: #006600;">generate</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;				
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> onPdfPageComplete<span style="color: #66cc66;">&#40;</span>event:PdfGeneratorEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>					
  progressBar.<span style="color: #006600;">setProgress</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">completedPages</span>, event.<span style="color: #006600;">totalPages</span><span style="color: #66cc66;">&#41;</span>;
  progressBar.<span style="color: #006600;">label</span> = event.<span style="color: #006600;">completedPages</span> + <span style="color: #ff0000;">&quot; of &quot;</span> + event.<span style="color: #006600;">totalPages</span>;															
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> onPdfComplete<span style="color: #66cc66;">&#40;</span>event:PdfGeneratorEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>											
  <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;completed&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>share</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/&amp;submitHeadline=Creating+PDF+with+images+using+flex+and+AlivePDF&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/&amp;title=Creating+PDF+with+images+using+flex+and+AlivePDF" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/&amp;title=Creating+PDF+with+images+using+flex+and+AlivePDF" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Creating+PDF+with+images+using+flex+and+AlivePDF&amp;url=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/&amp;title=Creating+PDF+with+images+using+flex+and+AlivePDF" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/&amp;title=Creating+PDF+with+images+using+flex+and+AlivePDF" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/&amp;T=Creating+PDF+with+images+using+flex+and+AlivePDF" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/&amp;title=Creating+PDF+with+images+using+flex+and+AlivePDF" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/&amp;title=Creating+PDF+with+images+using+flex+and+AlivePDF" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/&amp;title=Creating+PDF+with+images+using+flex+and+AlivePDF" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Creating+PDF+with+images+using+flex+and+AlivePDF+@+http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/&amp;t=Creating+PDF+with+images+using+flex+and+AlivePDF" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://gravityblast.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://gravityblast.com/2009/07/19/creating-pdf-with-images-using-flex-and-alivepdf/feed/</wfw:commentRss>
		<slash:comments>35</slash:comments>
		</item>
	</channel>
</rss>
