<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" 
      xmlns:thr="http://purl.org/syndication/thread/1.0">
  <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/08/using-aptana-studio-to-build-j-1.html" />
  <link rel="self" type="application/atom+xml" href="http://www.insideria.com/atom.xml" />
  <id>tag:www.insideria.com,2010://34/tag:www.insideria.com,2009://34.37838-</id>
  <updated>2010-03-15T18:34:38Z</updated>
  <title>Comments for Using Aptana Studio to build jQuery/AIR Applications (2) (http://www.insideria.com/2009/08/using-aptana-studio-to-build-j-1.html)</title>
  <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.21-en</generator>
  <entry>
    <id>tag:www.insideria.com,2009://34.37838</id>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/08/using-aptana-studio-to-build-j-1.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.oreilly.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=34/entry_id=37838" title="Using Aptana Studio to build jQuery/AIR Applications (2)" />
    <published>2009-08-29T01:54:31Z</published>
    <updated>2009-08-29T01:54:31Z</updated>
    <title>Using Aptana Studio to build jQuery/AIR Applications (2)</title>
    <summary>A follow up to my previous entry on creating a simple jQuery based AIR application using the Aptana Studio product.</summary>
    <author>
      <name>Raymond Camden</name>
      <uri>http://www.coldfusionjedi.com</uri>
    </author>
    
    <category term="Blogs" />
    
    <content type="html" xml:lang="en" xml:base="http://www.insideria.com/">
      <![CDATA[In my <a href="http://www.insideria.com/2009/08/using-aptana-studio-to-build-j.html">last blog entry</a> I talked about how you can use Aptana Studio to build jQuery-powered AIR applications. In today's blog entry I'm going to take it a step further. First, I'll build an real application. Not a very powerful one, mind you, but something a bit more useful then the demo I created before. After that, I'll demonstrate how to publish your AIR project to an AIR file that can be distributed to the world. All you have to do at that point is slap a price tag on it and laugh your ways till millions.
<br/><br/>
My new project is a simple one based on the <i>very</i> well done Twitter API. The application will consist of one simple form field. The end user enters a search term, hits the button, and then results from Twitter are displayed below. 
<br/><br/>
Begin the project by following the steps I mentioned in the <a href="http://www.insideria.com/2009/08/using-aptana-studio-to-build-j.html">previous entry</a>. I named my project jqTwitterAIR, but really anything would be fine. 
<br/><br/>
I cleaned out the HTML file generated by default and used the following HTML within the BODY tags:
<br/><br/>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;"><code language="perl">
<pre>
&lt;div id="<span class="quote">searchFormDiv</span>"&gt;
	&lt;form id="<span class="quote">searchForm</span>"&gt;
		&lt;<span class="category2">input</span> <span class="category2">type</span>="<span class="quote">text</span>" id="<span class="quote">searchTerm</span>" value="<span class="quote">camden</span>"&gt; &lt;<span class="category2">input</span> <span class="category2">type</span>="<span class="quote">button</span>" id="<span class="quote">searchButton</span>" value="<span class="quote">Search</span>"&gt;
	&lt;/form&gt;        
&lt;/div&gt;
	
&lt;div id="<span class="quote">results</span>"&gt;&lt;/div&gt;
&lt;div <span class="category1">class</span>="<span class="quote">acode</span>" style="<span class="quote">overflow: auto; padding: 10px;</span>" &gt;&lt;div style="<span class="quote">overflow-x: visible;</span>"&gt;&lt;mt:CodeBeautify <span class="category2">language</span>="<span class="quote">actionscript</span>"&gt;
&lt;br/&gt;&lt;br/&gt;
The design here is rather simple. A div <span class="category1">on</span> top to hold the form <span class="category1">and</span> a div beneath it <span class="category1">for</span> the results. What'<span class="quote">s with the default value camden in the search box? Once you</span>'ve run your AIR application a few hundred times you <span class="category2">get</span> &lt;i&gt;real&lt;/i&gt; tired typing <span class="category1">in</span> sample <span class="category2">data</span>. I was going to remove that before writing <span class="category1">this</span> blog entry, but it'<span class="quote">s one of those "obvious" tips for development that I thought I</span>'d share. 
&lt;br/&gt;&lt;br/&gt;
Ok, now <span class="category1">for</span> the JavaScript. I begin <span class="category1">with</span> a simple event handler (tied to the document loading) that listens to my form.
&lt;br/&gt;&lt;br/&gt;
&lt;div <span class="category1">class</span>="<span class="quote">acode</span>" style="<span class="quote">overflow: auto; padding: 10px;</span>" &gt;&lt;div style="<span class="quote">overflow-x: visible;</span>"&gt;&lt;mt:CodeBeautify <span class="category2">language</span>="<span class="quote">actionscript</span>"&gt;
$(document).ready(<span class="category1">function</span>() {
 		
 	$("<span class="quote">#searchButton</span>").click(<span class="category1">function</span>() {
  		<span class="category1">var</span> searchTerm = $("<span class="quote">#searchTerm</span>").val()
  		searchTerm = $.trim(searchTerm)
  		<span class="category1">if</span>(searchTerm == '<span class="quote"></span>') <span class="category1">return</span> <span class="category1">false</span>
  		$("<span class="quote">#results</span>").<span class="category2">html</span>("<span class="quote">&lt;i&gt;Searching...&lt;/i&gt;</span>")
  		searchTwitter(searchTerm)
  		<span class="category1">return</span> <span class="category1">false</span>
  	})
})    </pre>
</code>

</div></div>
<br/><br/>
There isn't much here really. I get the value from the form field, trim it, and if there is actually data I add a simple loading message to the results page and then call my searchTwitter function. Notice the return false statement. This stops the form from actually submitting. 
<br/><br/>
Next up is the searchTwitter function:
<br/><br/>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;"><code language="perl">
<pre>
<span class="category1">function</span> searchTwitter(str) {
 	<span class="category1">var</span> searchURL = "<span class="quote">http://search.twitter.com/search.json?</span>"
 	$.getJSON(searchURL,{q:str},<span class="category1">function</span>(r) {
  		$("<span class="quote">#results</span>").<span class="category2">html</span>("<span class="quote"></span>")
  		<span class="linecomment">//r.results are the results</span>
  		<span class="category1">if</span> (r.results != <span class="category1">null</span>) {
   			<span class="category1">for</span> (<span class="category1">var</span> i = 0; i &lt; r.results.<span class="category2">length</span>; i++) {
    				<span class="category1">var</span> result = r.results[i]
    				drawTwitterResult(result)
    			}
   			$("<span class="quote">.twitterResult</span>").corner("<span class="quote">round</span>")
   		}
  	})
 	
}</pre>
</code>
</div></div>
<br/><br/>
This code makes use of the Twitter API. (Which, from what I can see, kicks major butt. It was incredibly easy to use and returns quite a lot of useful information. Hey Google, take a look - this is how APIs should be done.) In this case the API returns JSON so I made use of the jQuery getJSON function. Also notice that AIR will have no problem calling this external URL. Strictly speaking, you don't need AIR for this. Twitter's API supports JSONP, but for this example I figured I'd use the power of AIR. Once the results are returned, I clear out the loading message and call a new function on each result. Oh, I also made use of a nice rounded corners plugin. (You can find it here: <a href="http://jquery.malsup.com/corner">http://jquery.malsup.com/corner</a>.) As we all know, you can't be Web 2.0 with square corners. 
<br/><br/>
The final piece of code handles rendering the Twits:
<br/><br/>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;"><code language="perl">
<pre>
<span class="category1">function</span> drawTwitterResult(tweet) {
 	<span class="category1">var</span> s = "<span class="quote">&lt;div class='twitterResult'&gt;</span>"
 	s+="<span class="quote">&lt;img src='</span>"+tweet.profile_image_url+"<span class="quote">' class='twitterProfileImage'&gt;</span>"
 	s+=tweet.<span class="category2">text</span>+="<span class="quote">&lt;br/&gt;</span>"
 	s+="<span class="quote">&lt;div class='twitterByline'&gt;</span>"+tweet.from_user+'<span class="quote"> at </span>'+tweet.created_at+"<span class="quote">&lt;/div&gt;</span>"
 	s+="<span class="quote">&lt;div style='clear:both'&gt;&lt;/div&gt;</span>"
 	s+="<span class="quote">&lt;/div&gt;</span>"
 	$("<span class="quote">#results</span>").append(s)
}</pre>
</code>
</div></div>
<br/><br/>
This is fairly simple. I use a bit of CSS and lay out the image, username, date, and actual text of the twit. Clicking the run button and searching for cfjedimaster shows the following:
<br/><br/>
<a href="http://www.insideria.com/upload/2009/08/jqtwitterair.png" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/upload/2009/08/jqtwitterair.png" alt="jqtwitterair.png" title="Click to enlarge" width="148"/></a>
<br/><br/>
Alright - now that we have an AIR application we can run, how do we create a file people can install? We need to export the project as an Adobe AIR package. You can do this by clicking the orange AIR icon in the toolbar, or by selecting File/Export/Adobe AIR Package. On the first page, simply leave all the options as is.
<br/><br/>
<a href="http://www.insideria.com/upload/2009/08/jqta2.png" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/upload/2009/08/jqta2.png" alt="jqta2.png" title="Click to enlarge" width="148"/></a>
<br/><br/>
The next step asks you to sign your AIR application. This sounds scary, but is pretty harmless. You need to create a simple certificate to go along with your AIR application. Once you get into "real" AIR development you will want to buy a certificate, but Adobe (and Aptana) make it easy to generate a certificate you can sign yourself, all for free. Click the configure certificates link to bring up the AIR Certificates panel. Click the add button and create a new certificate. Be sure to select "Create a new certificate". The name doesn't really matter, but make sure you pick a password you will remember. The only required item outside of the name and password is the publisher name.
<br/><br/>
<a href="http://www.insideria.com/upload/2009/08/jqta3.png" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/upload/2009/08/jqta3.png" alt="jqta3.png" title="Click to enlarge" width="148"/></a>
<br/><br/>
After you've created the certificate, click OK to leave the certificates panel, and then select the certificate. Enter the password you just used and then click next.
<br/><br/>
<a href="http://www.insideria.com/upload/2009/08/jqta4.png" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/upload/2009/08/jqta4.png" alt="jqta4.png" title="Click to enlarge" width="148"/></a>
<br/><br/>
The next page asks you which files should be included in the package. If you created any temporary files during your development you should uncheck them now. Otherwise, just leave it as is. Wrap everything up by clicking Finish. Voila - you now have an AIR file.
<br/><br/>
You can download the my AIR file <a href="http://www.coldfusionjedi.com/downloads/jqtwitterair.air">here</a>. Enjoy!

<p>
<strong>More in This Series</strong>
<ul>
<li><a href="http://www.insideria.com/2009/08/using-aptana-studio-to-build-j.html">Using Aptana Studio to build jQuery/AIR Applications, Part 1</a></li>
<li><a href="http://www.insideria.com/2009/09/using-aptana-studio-to-build-j-2.html">Using Aptana Studio to build jQuery/AIR Applications, Part 3</a></li>
</ul>]]>
      
    </content>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.37838-comment:2075111</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.37838" type="text/html" href="http://www.insideria.com/2009/08/using-aptana-studio-to-build-j-1.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/08/using-aptana-studio-to-build-j-1.html#comment-2075111" />
    <title>Comment from watzabatza on 2009-08-30</title>
    <author>
        <name>watzabatza</name>
        <uri>http://get-infoz.blogspot.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://get-infoz.blogspot.com">
        <![CDATA[<p>Wow! a very complicated program...</p>]]>
    </content>
    <published>2009-08-30T14:04:08Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.37838-comment:2076456</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.37838" type="text/html" href="http://www.insideria.com/2009/08/using-aptana-studio-to-build-j-1.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/08/using-aptana-studio-to-build-j-1.html#comment-2076456" />
    <title>Comment from Phill on 2009-08-31</title>
    <author>
        <name>Phill</name>
        <uri>http://llihp.blogspot.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://llihp.blogspot.com">
        <![CDATA[<p>A littl off topic but is there a way to set the proxy of a Air application? I use multiple browsers and each have a different proxy setting, can I set them manually from the Air application?</p>]]>
    </content>
    <published>2009-08-31T17:53:57Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.37838-comment:2077006</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.37838" type="text/html" href="http://www.insideria.com/2009/08/using-aptana-studio-to-build-j-1.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/08/using-aptana-studio-to-build-j-1.html#comment-2077006" />
    <title>Comment from Raymond Camden on 2009-08-31</title>
    <author>
        <name>Raymond Camden</name>
        <uri>http://www.coldfusionjedi.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.coldfusionjedi.com">
        <![CDATA[<p>To be honest, I don't know. I don't remember seeing any proxy support in Flex network stuff, but I could be wrong. </p>]]>
    </content>
    <published>2009-09-01T00:55:06Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.37838-comment:2363749</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.37838" type="text/html" href="http://www.insideria.com/2009/08/using-aptana-studio-to-build-j-1.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/08/using-aptana-studio-to-build-j-1.html#comment-2363749" />
    <title>Comment from Matt on 2010-03-01</title>
    <author>
        <name>Matt</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Would it be possible to post your code? I can't duplicate your results. It just hangs on "Searching...". (I think the JSON query is failing.)</p>]]>
    </content>
    <published>2010-03-01T18:40:04Z</published>
  </entry>

</feed
