<?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>Joey Rivera &#187; AIR</title>
	<atom:link href="http://www.joeyrivera.com/category/categories/air/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.joeyrivera.com</link>
	<description>Blogging about PHP, Actionscript, MySQL, and other interests.</description>
	<lastBuildDate>Wed, 04 Aug 2010 14:52:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to build an Adobe AIR Badge</title>
		<link>http://www.joeyrivera.com/2010/how-to-build-adobe-air-badge/</link>
		<comments>http://www.joeyrivera.com/2010/how-to-build-adobe-air-badge/#comments</comments>
		<pubDate>Wed, 04 Aug 2010 14:52:07 +0000</pubDate>
		<dc:creator>Joey</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[badge]]></category>

		<guid isPermaLink="false">http://www.joeyrivera.com/?p=593</guid>
		<description><![CDATA[NOTE: This article was written with AIR 1.5 in mind. I can&#8217;t say if the following information will work as intended on AIR 2. If you already know how to build you own Adobe AIR badge, you won&#8217;t find much new information here. This post is more to inform users that you can in fact [...]]]></description>
			<content:encoded><![CDATA[<p>NOTE: This article was written with AIR 1.5 in mind. I can&#8217;t say if the following information will work as intended on AIR 2. If you already know how to build you own Adobe AIR badge, you won&#8217;t find much new information here. This post is more to inform users that you can in fact create your own AIR badge if you didn&#8217;t already know. When I first started working with AIR, I learned about the badge but as far as I was concerned, the badge was a black box who&#8217;s functionality was designed to remain mysterious.  The badge I used was the one <a title="Grant Skinner's website" href="http://www.gskinner.com/">Grant Skinner</a> created and you can get more information from <a title="About the Badge" href="http://www.adobe.com/devnet/air/articles/badge_for_air.html">Adobe</a> on how to use it. For a long time this badge worked well but finally the time has come where I need to make it behave a bit differently so I decided to do a bit of research.</p>
<p>After doing a few Google searches, I found a link to Adobe&#8217;s site with all the technical information on how to create your own AIR badge! I was completely surprised that I never even thought about the possibility that I could write my own badge&#8230; not sure what I was thinking. Nothing is more fun that reinventing the wheel right? After looking at the <a title="Adobe AIR 1.5 Badge" href="http://help.adobe.com/en_US/AIR/1.5/devappsflex/WS5b3ccc516d4fbf351e63e3d118666ade46-7e15.html">specifications</a>, I realized it wasn&#8217;t too bad and started to plan out a logical flow on how my badge was supposed to work.</p>
<h2>Requirements</h2>
<p>My current badge has the following issue: a user installs my app through the badge, every time after that point that the user comes back to the badge, they have to &#8216;install&#8217; the app again even thought it was already installed. Instead, I want the badge to sense if the application is installed and if so, launch it (I haven&#8217;t spend much time looking into Grants Badger app but I think it&#8217;ll let you do this as well if used correctly&#8230; I think). The logic for the new badge should be:</p>
<ol>
<li>Check if AIR is installed (If not, install)</li>
<li>Check if my app is installed (If not install)</li>
<li>Launch my app</li>
</ol>
<h2>Setup</h2>
<p>I&#8217;ll be using Flash CS3 since that&#8217;s what I have available to me for this tutorial and I am making the assumption you already know how to use Flash, understand ActionScript 3, and have an AIR app to test. Open Flash and create a new AS3 file and save it in some folder. Now attach a class called &#8216;Badge&#8217; to your file that extends MovieClip. Your class should look like the following:</p>
<div class="dean_ch" style="white-space: wrap;">package<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">display</span>.<span class="kw3">MovieClip</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">class</span> Badge <span class="kw3">extends</span> <span class="kw3">MovieClip</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> Badge<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&#8216;hi&#8217;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p>I added a trace in the constructor so I can make sure my class is working. When you test your badge you should see &#8216;hi&#8217; in your output window. Now we are ready to continue.<span id="more-593"></span></p>
<h2>air.swf</h2>
<p>Adobe created a file called air.swf that resides on their server at http://airdownload.adobe.com/air/browserapi/air.swf. This file contains all the functionality required to interact with AIR files through your badge. It can check to see if you have air installed on the local machine and install it, it can check to see if an air app is installed on the local machine and install it or launch. It does it all so the first step in creating a badge is to load this file so you can call it&#8217;s methods.</p>
<p>All we need to do is create a Loader instance, add an event listener to alert us when it&#8217;s done loading the air.swf file and call the load method passing in the url as a URLRequest. The code is below with all the required imports:</p>
<div class="dean_ch" style="white-space: wrap;">package<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">display</span>.<span class="kw3">MovieClip</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">events</span>.<span class="me1">Event</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">display</span>.<span class="me1">Loader</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">net</span>.<span class="me1">URLRequest</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">class</span> Badge <span class="kw3">extends</span> <span class="kw3">MovieClip</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">var</span> _air:<span class="kw3">Object</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> Badge<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> loader:Loader = <span class="kw2">new</span> Loader<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loader.<span class="me1">contentLoaderInfo</span>.<span class="me1">addEventListener</span><span class="br0">&#40;</span>Event.<span class="me1">INIT</span>, airSwfLoaded<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loader.<span class="kw3">load</span><span class="br0">&#40;</span><span class="kw2">new</span> URLRequest<span class="br0">&#40;</span><span class="st0">&#8216;http://airdownload.adobe.com/air/browserapi/air.swf&#8217;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> airSwfLoaded<span class="br0">&#40;</span><span class="kw3">e</span>:Event<span class="br0">&#41;</span>:<span class="kw3">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>._air = <span class="kw3">e</span>.<span class="kw3">target</span>.<span class="me1">content</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="kw3">this</span>._air.<span class="me1">getStatus</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p>Test the above code and in your output you should see one of the following <a title="Different status responses" href="http://help.adobe.com/en_US/AIR/1.5/devappsflex/WS5b3ccc516d4fbf351e63e3d118666ade46-7e15.html#WS5b3ccc516d4fbf351e63e3d118666ade46-7c98">status responses</a> (taken from Adobe&#8217;s site):</p>
<table border="1" cellspacing="0" cellpadding="4">
<thead>
<tr>
<th id="d17e28828" width="NaN%" valign="top">String value</th>
<th id="d17e28831" width="NaN%" valign="top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td width="NaN%" valign="top"><samp>&#8220;available&#8221;</samp></td>
<td width="NaN%" valign="top">The runtime can be installed on this computer but currently it is not installed.</td>
</tr>
<tr>
<td width="NaN%" valign="top"><samp>&#8220;unavailable&#8221;</samp></td>
<td width="NaN%" valign="top">The runtime cannot be installed on this computer.</td>
</tr>
<tr>
<td width="NaN%" valign="top"><samp>&#8220;installed&#8221;</samp></td>
<td width="NaN%" valign="top">The runtime is installed on this computer.</td>
</tr>
</tbody>
</table>
<h2>Handling the response</h2>
<p>Now that we have a status, we can tell the badge to handle it in the appropriate manner. The first status we need to handle is &#8216;available&#8217;. This means AIR is not installed on the machine but can be. By default, AIR needs to be installed before installing an AIR app so in this scenario, all we need to call is install on our app and AIR will be installed first automatically. Here is the <strong>tricky part</strong>, we can&#8217;t automatically call install on an AIR app, it is not allowed. <span style="text-decoration: underline;">You can only call install via a user initiated event such as a button click</span>.</p>
<p>If the status is unavailable, then we can&#8217;t do much other than let the user know they can&#8217;t install AIR on their machine. If the status is installed, then the user already has AIR installed and we need to check if they have our app installed. If they do not, we install it and let them launch it. If they do have it installed, we let them launch it. Below is the complete code that does all the above:</p>
<div class="dean_ch" style="white-space: wrap;">package<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">display</span>.<span class="kw3">MovieClip</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">events</span>.<span class="me1">Event</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">display</span>.<span class="me1">Loader</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">events</span>.<span class="me1">MouseEvent</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">net</span>.<span class="me1">URLRequest</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> fl.<span class="me1">controls</span>.<span class="kw3">Button</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">class</span> Badge <span class="kw3">extends</span> <span class="kw3">MovieClip</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">var</span> _air:<span class="kw3">Object</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">var</span> _myButton:<span class="kw3">Button</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> const APPID:<span class="kw3">String</span> = <span class="st0">&#8216;YOUAPPID&#8217;</span>; <span class="co1">// replace with your app id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> const PUBID:<span class="kw3">String</span> = <span class="st0">&#8216;123123123123123123123123.1&#8242;</span>; <span class="co1">// replace with your publisher id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> const APPURL:<span class="kw3">String</span> = <span class="st0">&#8216;http://www.yourdomain.com/YOUAIRAPP.air&#8217;</span>; <span class="co1">// replace with your app url</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> const APPRUNTIME:<span class="kw3">String</span> = <span class="st0">&#8216;1.5&#8242;</span>; <span class="co1">// I&#8217;m using 1.5 as a minimum requirement for this example</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> const AIRSWF:<span class="kw3">String</span> = <span class="st0">&#8216;http://airdownload.adobe.com/air/browserapi/air.swf&#8217;</span>; <span class="co1">// adobe&#8217;s file</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> Badge<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> loader:Loader = <span class="kw2">new</span> Loader<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loader.<span class="me1">contentLoaderInfo</span>.<span class="me1">addEventListener</span><span class="br0">&#40;</span>Event.<span class="me1">INIT</span>, airSwfLoaded<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loader.<span class="kw3">load</span><span class="br0">&#40;</span><span class="kw2">new</span> URLRequest<span class="br0">&#40;</span><span class="kw3">this</span>.<span class="me1">AIRSWF</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>._myButton = <span class="kw2">new</span> <span class="kw3">Button</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">addChild</span><span class="br0">&#40;</span><span class="kw3">this</span>._myButton<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> airSwfLoaded<span class="br0">&#40;</span><span class="kw3">e</span>:Event<span class="br0">&#41;</span>:<span class="kw3">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>._air = <span class="kw3">e</span>.<span class="kw3">target</span>.<span class="me1">content</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">switch</span><span class="br0">&#40;</span><span class="kw3">this</span>._air.<span class="me1">getStatus</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">case</span> <span class="st0">&#8216;available&#8217;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// install app</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">installApp</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">case</span> <span class="st0">&#8216;unavailable&#8217;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// AIR not supported on this system</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">case</span> <span class="st0">&#8216;installed&#8217;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// check if app is installed</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>.<span class="me1">checkApp</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> checkApp<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>._air.<span class="me1">getApplicationVersion</span><span class="br0">&#40;</span><span class="kw3">this</span>.<span class="me1">APPID</span>, <span class="kw3">this</span>.<span class="me1">PUBID</span>, checkAppCallback<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> checkAppCallback<span class="br0">&#40;</span><span class="kw3">version</span>:<span class="kw3">String</span><span class="br0">&#41;</span>:<span class="kw3">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw3">version</span> == <span class="kw2">null</span><span class="br0">&#41;</span> <span class="co1">// app is not installed</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>._myButton.<span class="me1">label</span> = <span class="st0">&quot;Install&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>._myButton.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">CLICK</span>, installApp<span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>._myButton.<span class="me1">label</span> = <span class="st0">&quot;Launch&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>._myButton.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">CLICK</span>, launchApp<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> installApp<span class="br0">&#40;</span><span class="kw3">e</span>:Event = <span class="kw2">null</span><span class="br0">&#41;</span>:<span class="kw3">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>._air.<span class="me1">installApplication</span><span class="br0">&#40;</span><span class="kw3">this</span>.<span class="me1">APPURL</span>, <span class="kw3">this</span>.<span class="me1">APPRUNTIME</span>, <span class="kw2">new</span> <span class="kw3">Array</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> launchApp<span class="br0">&#40;</span><span class="kw3">e</span>:Event<span class="br0">&#41;</span>:<span class="kw3">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>._air.<span class="me1">launchApplication</span><span class="br0">&#40;</span><span class="kw3">this</span>.<span class="me1">APPID</span>, <span class="kw3">this</span>.<span class="me1">PUBID</span>, <span class="kw2">new</span> <span class="kw3">Array</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p>I added a button that depending on the status will display the appropriate label and call the corresponding method. If the status is available we know that my app is probably not installed (since AIR is not installed) so I tell my button to call the install app method. The install app method calls the installApplication method from the air.swf file and passes the following 3 paramets: the url of the app you are trying to install, the AIR runtime required for this app, and an array of parameters required for this app if any (make sure to modify those variables to match your needs). When a user clicks on the button, they will be asked to install AIR, install the AIR application, and allowed to start it.</p>
<p>If the status is installed, we call the check app method to see if our app is already installed on the users machine by seeing what version of the app is installed. A null version means that the app is not installed. If installed, our button will launch the application and if not, we call the install app method that I just described above. The launch application method takes in three parameters: the application id, the publisher id and a array of parameters if the application requires it. <span style="text-decoration: underline;">NOTE</span>: Your AIR application MUST have <a title="BrowserInvocation Information from Adobe" href="http://help.adobe.com/en_US/AIR/1.5/devappsflex/WS5b3ccc516d4fbf351e63e3d118676a5d46-8000.html#WS5b3ccc516d4fbf351e63e3d118666ade46-7e19">allowBrowserInvocation</a> set to true in it&#8217;s AIR application descriptor xml file for the badge to be able to launch your AIR application.</p>
<h5>Finding your application id</h5>
<p>Simply go to your AIR application&#8217;s folder and open the descriptor xml file. Look for the id node and that&#8217;s the id you want to use.</p>
<h5>Finding your publisher id</h5>
<p>This one was a bit trickier. First you need to install your AIR application on your system. Once installed, go to the folder where your application was installed and inside there will be a META-INF folder. Inside that folder there is a AIR folder with a publisherid file. Open that file and the string inside is your publisher id. For example: c:\program files\myairapp\META-INF\AIR\publisherid</p>
<p>That should do it. At this point you should have a basic working AIR badge. Now you can customize it any ways you like. Hope you all find this helpful! Feel free to leave any questions or comments.</p>
<h2>Resources:</h2>
<p><a title="Adobe Links" href="http://help.adobe.com/en_US/AIR/1.5/devappsflex/WS5b3ccc516d4fbf351e63e3d118666ade46-7e15.html">http://help.adobe.com/en_US/AIR/1.5/devappsflex/WS5b3ccc516d4fbf351e63e3d118666ade46-7e15.html</a></p>
<p><a title="Adobe Links" href="http://help.adobe.com/en_US/AIR/1.5/devappsflex/WS5b3ccc516d4fbf351e63e3d118666ade46-7ff1.html#WS5b3ccc516d4fbf351e63e3d118666ade46-7c9c">http://help.adobe.com/en_US/AIR/1.5/devappsflex/WS5b3ccc516d4fbf351e63e3d118666ade46-7ff1.html#WS5b3ccc516d4fbf351e63e3d118666ade46-7c9c</a></p>
<p><a title="Adobe Links" href="http://help.adobe.com/en_US/AIR/1.5/devappsflex/WS5b3ccc516d4fbf351e63e3d118666ade46-7ff0.html#WS5b3ccc516d4fbf351e63e3d118666ade46-7cca">http://help.adobe.com/en_US/AIR/1.5/devappsflex/WS5b3ccc516d4fbf351e63e3d118666ade46-7ff0.html#WS5b3ccc516d4fbf351e63e3d118666ade46-7cca</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.joeyrivera.com/2010/how-to-build-adobe-air-badge/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Uploader Phase 2 complete!</title>
		<link>http://www.joeyrivera.com/2008/uploader-phase-2-complete/</link>
		<comments>http://www.joeyrivera.com/2008/uploader-phase-2-complete/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 03:45:52 +0000</pubDate>
		<dc:creator>Joey</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Uploader]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.joeyrivera.com/?p=165</guid>
		<description><![CDATA[So today after work I decided it was about time to start working on phase two of my Uploader tool. Phase two consists of allowing me to drag and drop an image URL into the app so the app can then download the image to a folder in my server, create a thumbnail of this [...]]]></description>
			<content:encoded><![CDATA[<div class="wp-caption alignleft" style="width: 157px"><img title="Uploader screen shot" src="/blog_files/96/uploader_ss.gif" alt="Here is a screen shot of the Uploader 0.1.0" width="147" height="172" /><p class="wp-caption-text">Uploader 0.2.0</p></div>
<p>So today after work I decided it was about time to start working on phase two of my Uploader tool. Phase two consists of allowing me to drag and drop an image URL into the app so the app can then download the image to a folder in my server, create a thumbnail of this image, and update the WordPress database with information about the new image. The new image would then show up the next time a person visits my blog. If you notice, there is now a &#8220;Pics of Interest&#8221; section on the sidebar to the right of the page (similar to what people are doing with the flickr plugin). Every time I drag an image URL into the Uploader, the new image thumbnail will show in that area and if you click on the thumbnail you&#8217;ll see the full size image.</p>
<p>It was actually much easier than I originally thought to make this work. Technically, the Uploader already has the drag/drop functionality and already takes in a URL. The only extra <a title="Main.as" href="http://www.joeyrivera.com/blog_files/165/Main.as" target="_blank">AS3 code</a> was a check to see if the URL was an image and if so call the PHP page with a code (I&#8217;m passing &#8211;@IMAGE@&#8211; to know it&#8217;s an image &#8211; it was just the first thing that came to my head) so then PHP knows this URL should be treated as an image not just a URL. If you remember, phase 1 for the Uploader allows a person to drag/drop a URL into the app so it creates a new link under the &#8220;Links of Interest&#8221;.<span id="more-165"></span></p>
<p>Most of the changes were on the PHP end. The file that handles the request from the AIR app now does a check to see if this URL is an image. If so, it has to download the original image to the local server, make a thumbnail copy of it, and finally update the wp_images table (this is a new table I created for this - <a title="MySQL create script" href="http://www.joeyrivera.com/blog_files/165/wp_images.sql" target="_blank">MySQL script</a>) in WordPress. I&#8217;m using two PEAR packages to do this: HTTP_Request and Image_Transform. The same can be done just as easily without them but I like using PEAR on my projects. Here&#8217;s the code that does this (<a title="index.php file as text" href="http://www.joeyrivera.com/blog_files/165/file.txt" target="_blank">file.txt</a>):</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$name</span> == <span class="st0">&#8216;&#8211;@IMAGE@&#8211;&#8217;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="co1">// later use unique names?</span><br />
    <span class="re0">$name</span> = <a href="http://www.php.net/substr"><span class="kw3">substr</span></a><span class="br0">&#40;</span><span class="re0">$url</span>, strripos<span class="br0">&#40;</span><span class="re0">$url</span>,<span class="st0">&#8216;/&#8217;</span><span class="br0">&#41;</span> + <span class="nu0">1</span><span class="br0">&#41;</span>;<br />
        <br />
&nbsp; &nbsp; <span class="kw1">require</span> <span class="st0">&#8216;HTTP/Request.php&#8217;</span>;<br />
    <span class="re0">$req</span> = <span class="kw2">new</span> HTTP_Request<span class="br0">&#40;</span><span class="re0">$url</span><span class="br0">&#41;</span>;<br />
    <span class="re0">$req</span>-&gt;<span class="me1">sendRequest</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
    <br />
&nbsp; &nbsp; <span class="re0">$fp</span> = <a href="http://www.php.net/fopen"><span class="kw3">fopen</span></a><span class="br0">&#40;</span><span class="st0">&#8216;images/&#8217;</span>.<span class="re0">$name</span>, <span class="st0">&#8216;w&#8217;</span><span class="br0">&#41;</span>;<br />
    <a href="http://www.php.net/fwrite"><span class="kw3">fwrite</span></a><span class="br0">&#40;</span><span class="re0">$fp</span>, <span class="re0">$req</span>-&gt;<span class="me1">getResponseBody</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp;   <a href="http://www.php.net/fclose"><span class="kw3">fclose</span></a><span class="br0">&#40;</span><span class="re0">$fp</span><span class="br0">&#41;</span>;<br />
    <br />
&nbsp; &nbsp; <span class="co1">// create thumbnail</span><br />
    <span class="kw1">require</span> <span class="st0">&#8216;Image/Transform.php&#8217;</span>;</p>
<p>&nbsp;   <span class="co1">//create transform driver object</span><br />
&nbsp;   <span class="re0">$it</span> = Image_Transform::<span class="me2">factory</span><span class="br0">&#40;</span><span class="st0">&#8216;GD&#8217;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp;   <span class="co1">//load the original file</span><br />
&nbsp;   <span class="re0">$it</span>-&gt;<span class="me1">load</span><span class="br0">&#40;</span><span class="st0">&#8216;images/&#8217;</span>.<span class="re0">$name</span><span class="br0">&#41;</span>;</p>
<p>&nbsp;   <span class="co1">//scale it to 100px</span><br />
&nbsp;   <span class="re0">$it</span>-&gt;<span class="me1">scaleMaxLength</span><span class="br0">&#40;</span><span class="nu0">100</span><span class="br0">&#41;</span>;</p>
<p>&nbsp;   <span class="co1">//save it into a different file</span><br />
&nbsp;   <span class="re0">$tn</span> = <a href="http://www.php.net/substr"><span class="kw3">substr</span></a><span class="br0">&#40;</span><span class="re0">$name</span>,<span class="nu0">0</span>,strripos<span class="br0">&#40;</span><span class="re0">$name</span>,<span class="st0">&#8216;.&#8217;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="st0">&#8216;-tn.&#8217;</span>.<a href="http://www.php.net/substr"><span class="kw3">substr</span></a><span class="br0">&#40;</span><span class="re0">$name</span>,strripos<span class="br0">&#40;</span><span class="re0">$name</span>,<span class="st0">&#8216;.&#8217;</span><span class="br0">&#41;</span><span class="nu0">+1</span><span class="br0">&#41;</span>;<br />
&nbsp;   <span class="re0">$it</span>-&gt;<span class="me1">save</span><span class="br0">&#40;</span><span class="st0">&#8216;images/&#8217;</span>.<span class="re0">$tn</span><span class="br0">&#41;</span>;</p>
<p>&nbsp;   <span class="re0">$query</span> = <span class="st0">&#8216;<br />
&nbsp;           Insert Into wp_images<br />
&nbsp;           Values (null, &#8216;</span>.<span class="re0">$db</span>-&gt;<span class="me1">quote</span><span class="br0">&#40;</span><span class="re0">$name</span>, <span class="st0">&#8216;text&#8217;</span><span class="br0">&#41;</span>.<span class="st0">&#8216;, &#8216;</span>.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$db</span>-&gt;<span class="me1">quote</span><span class="br0">&#40;</span><span class="re0">$tn</span>, <span class="st0">&#8216;text&#8217;</span><span class="br0">&#41;</span>.<span class="st0">&#8216;, &#8216;</span>.<span class="re0">$db</span>-&gt;<span class="me1">quote</span><span class="br0">&#40;</span><span class="re0">$url</span>, <span class="st0">&#8216;text&#8217;</span><span class="br0">&#41;</span>.<span class="st0">&#8216;);<br />
}</span></div>
<p>Then I had to add some code to the sidebar.php for my template in WordPress to show the new section &#8220;Pics of Interest&#8221;. As you read this keep in mind this is just a quick beta and I&#8217;ll be doing refactoring later. This is by no means a finished product but it works fine and it&#8217;s a good start for anyone who wants to try it out. This is the new code I added to my <a title="sidebar.php" href="http://www.joeyrivera.com/blog_files/165/sidebar.txt" target="_blank">sidebar.php</a>:</p>
<div class="dean_ch" style="white-space: wrap;">&lt;div <span class="kw2">class</span>=<span class="st0">&quot;block poi&quot;</span>&gt;<br />
&nbsp;       &lt;h3&gt;Pics of Interest&lt;/h3&gt;<br />
&nbsp;       <span class="kw2">&lt;?php</span><br />
&nbsp;               <span class="kw1">require</span> <span class="st0">&#8216;./uploader/lib/DB.php&#8217;</span>;<br />
&nbsp;               DB::<span class="me2">conn</span><span class="br0">&#40;</span><span class="st0">&#8216;live&#8217;</span><span class="br0">&#41;</span>;<br />
&nbsp;               <span class="re0">$db</span> = DB::<span class="me2">getInstance</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp;               <span class="re0">$query</span> = <span class="st0">&#8216;<br />
&nbsp;                       Select image_file, image_thumbnail, image_origin<br />
&nbsp;                       From wp_images<br />
&nbsp;                       Order By image_id desc<br />
&nbsp;                       Limit 6;<br />
&nbsp;                       &#8217;</span>;</p>
<p>&nbsp;               <span class="re0">$rs</span> = <span class="re0">$db</span>-&gt;<span class="me1">query</span><span class="br0">&#40;</span><span class="re0">$query</span><span class="br0">&#41;</span>;<br />
&nbsp;               <span class="kw1">while</span><span class="br0">&#40;</span><span class="re0">$row</span> = <span class="re0">$rs</span>-&gt;<span class="me1">fetchRow</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/print"><span class="kw3">print</span></a> <span class="st0">&#8216;&lt;a href=&quot;/uploader/images/&#8217;</span>.<span class="re0">$row</span><span class="br0">&#91;</span><span class="st0">&#8216;image_file&#8217;</span><span class="br0">&#93;</span>.<span class="st0">&#8216;&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title=&quot;From: &#8216;</span>.<span class="re0">$row</span><span class="br0">&#91;</span><span class="st0">&#8216;image_origin&#8217;</span><span class="br0">&#93;</span>.<span class="st0">&#8216;&quot;&gt;&lt;img<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; src=&quot;/uploader/images/&#8217;</span>.<span class="re0">$row</span><span class="br0">&#91;</span><span class="st0">&#8216;image_thumbnail&#8217;</span><span class="br0">&#93;</span>.<span class="st0">&#8216;&quot; /&gt;&lt;/a&gt;&#8217;</span>;<br />
&nbsp;       <span class="kw2">?&gt;</span><br />
&lt;/div&gt;</div>
<p>The last thing I had to do was to add the style for my images in the styles.css file and I was done. Make sure your images folder has the proper privileges so you can upload an image into it. The next phase will be allowing me to drag files from my local file system into the AIR app so it&#8217;ll upload it to my server. Right now the Uploader only does something when a URL is dropped on it: adds a link if it&#8217;s not a image, adds the image if it&#8217;s an image.</p>
<p>Question, comments, conerns are always welcome!</p>
<p>Edit:</p>
<p><a title="Info about Uploader Phase 1" href="http://www.joeyrivera.com/2008/uploader-phase-1/" target="_self">Uploader Phase 1</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.joeyrivera.com/2008/uploader-phase-2-complete/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AIR widow/app drag, minimize, and close</title>
		<link>http://www.joeyrivera.com/2008/air-widowapp-drag-minimize-and-close/</link>
		<comments>http://www.joeyrivera.com/2008/air-widowapp-drag-minimize-and-close/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 18:44:34 +0000</pubDate>
		<dc:creator>Joey</dc:creator>
				<category><![CDATA[AIR]]></category>

		<guid isPermaLink="false">http://www.joeyrivera.com/?p=119</guid>
		<description><![CDATA[In working on my Uploader tool, I had to do a bit of research on how to drag, minimize, and close an AIR app. Below is the summarized code in case anyone else is wondering how to do this.

import flash.display.Sprite;
import flash.display.MovieClip;
import flash.text.TextField;
import flash.desktop.NativeApplication;
import flash.events.MouseEvent;
public class Main extends Sprite
&#123;
&#160; &#160; &#160; &#160; public function Main&#40;&#41;:void
&#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>In working on my Uploader tool, I had to do a bit of research on how to drag, minimize, and close an AIR app. Below is the summarized code in case anyone else is wondering how to do this.</p>
<div class="dean_ch" style="white-space: wrap;">
<span class="kw3">import</span> flash.<span class="me1">display</span>.<span class="me1">Sprite</span>;<br />
<span class="kw3">import</span> flash.<span class="me1">display</span>.<span class="kw3">MovieClip</span>;<br />
<span class="kw3">import</span> flash.<span class="kw3">text</span>.<span class="kw3">TextField</span>;<br />
<span class="kw3">import</span> flash.<span class="me1">desktop</span>.<span class="me1">NativeApplication</span>;<br />
<span class="kw3">import</span> flash.<span class="me1">events</span>.<span class="me1">MouseEvent</span>;</p>
<p><span class="kw3">public</span> <span class="kw2">class</span> Main <span class="kw3">extends</span> Sprite<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> Main<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// button events</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mc_exit.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">CLICK</span>, exitApp<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mc_minimize.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">CLICK</span>, minimizeApp<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mc_drag.<span class="me1">addEventListener</span><span class="br0">&#40;</span>MouseEvent.<span class="me1">MOUSE_DOWN</span>, dragApp<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> exitApp<span class="br0">&#40;</span>event:MouseEvent<span class="br0">&#41;</span>:<span class="kw3">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NativeApplication.<span class="me1">nativeApplication</span>.<span class="me1">activeWindow</span>.<span class="kw3">close</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> minimizeApp<span class="br0">&#40;</span>event:MouseEvent<span class="br0">&#41;</span>:<span class="kw3">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NativeApplication.<span class="me1">nativeApplication</span>.<span class="me1">activeWindow</span>.<span class="me1">minimize</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> dragApp<span class="br0">&#40;</span>event:MouseEvent<span class="br0">&#41;</span>:<span class="kw3">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NativeApplication.<span class="me1">nativeApplication</span>.<span class="me1">activeWindow</span>.<span class="me1">startMove</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
&nbsp;</div>
<p>Three buttons on the root of the flash file each with a listener that handles an action when the mouse is clicked on it.  The drag button has to use &#8216;MOUSE_DOWN&#8217; instead of &#8216;CLICK&#8217; to work. NativeApplication is the AIR app and it looks to see which window is currently active to send the commands for.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joeyrivera.com/2008/air-widowapp-drag-minimize-and-close/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Uploader Phase 1</title>
		<link>http://www.joeyrivera.com/2008/uploader-phase-1/</link>
		<comments>http://www.joeyrivera.com/2008/uploader-phase-1/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 15:49:47 +0000</pubDate>
		<dc:creator>Joey</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Uploader]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[wordpress tools]]></category>

		<guid isPermaLink="false">http://www.joeyrivera.com/?p=96</guid>
		<description><![CDATA[If you missed the previous post explaining what Uploader is go check it out.
So after having some fun with code I think I&#8217;m close to being done with phase 1.  I currently have a working beta (0.1.0) that I&#8217;m going to share with you all and explain what I&#8217;ve done in case anyone else wants [...]]]></description>
			<content:encoded><![CDATA[<div class="wp-caption alignleft" style="width: 157px"><img title="Uploader screen shot" src="/blog_files/96/uploader_ss.gif" alt="Here is a screen shot of the Uploader 0.1.0" width="147" height="172" /><p class="wp-caption-text">Uploader 0.1.0</p></div>
<p>If you missed the previous post explaining what Uploader is go <a title="About the uploader" href="http://www.joeyrivera.com/2008/uploader-automating-wordpress-links-and-file-uploads/" target="_self">check it out</a>.</p>
<p>So after having some fun with code I think I&#8217;m close to being done with phase 1.  I currently have a working beta (0.1.0) that I&#8217;m going to share with you all and explain what I&#8217;ve done in case anyone else wants to do something similar.  For the most part this was pretty straight forward.  There were a few hiccups here and there that I&#8217;ll try to address in this post. The link to the code will be at the end.</p>
<p> <span id="more-96"></span></p>
<p>First I looked online for some info on Drag/Drop in AIR and I found these two posts that I used for reference:</p>
<ul>
<li><a href="http://www.senocular.com/air/tutorials/dragdropimageviewer/" target="_blank">http://www.senocular.com/air/tutorials/dragdropimageviewer/</a></li>
<li><a href="http://www.mikechambers.com/blog/2007/11/07/air-example-native-drag-and-drop/" target="_blank">http://www.mikechambers.com/blog/2007/11/07/air-example-native-drag-and-drop/</a></li>
</ul>
<p>I should have read the comments in those post since they answer the question of using &#8216;NativeDragManager&#8217; instead of &#8216;DragManager&#8217;.  I had that issue and had to figure out why it wasn&#8217;t working.</p>
<p>This is an AIR app made in Flash.  So far I only have one &#8216;Main&#8217; class taking care of most of the action.  I&#8217;ll clean the code up later and comment it but here&#8217;s the <a title="Main.as file" href="http://www.joeyrivera.com/blog_files/96/com/joeyrivera/uploader/Main.as" target="_blank">class</a> so far. Using the &#8216;NativeDragEvent&#8217;, Uploader waits for something to be dragged over it.  When it does, &#8216;dragEnter&#8217; is called. Usually you can do some validation here to see if this is a file type you want to accept but I just do that later.  Before a file/URL can be dropped you need to call &#8216;NativeDragManager.acceptDragDrop(<em>object</em>)&#8217;. By doing this, you let AIR know that the object is ready to accept the drop.</p>
<p>Once an item is dropped, &#8216;dragDrop&#8217; is called to see if this is a file or a URL.  If URL, &#8216;urlDropped&#8217; is called which creates a listener for the loader var and sends the request to the URL that was dropped on the app.  When the request is complete, &#8216;urlLoaded&#8217; is called.  The reason we are loading the dropped URL is so we can grab the title of that page in between the &lt;title&gt; tag of the html.  This is going to be used as the display name when we insert the new link in WordPress. &#8216;grabTitle&#8217; does a quick substr and when all is done we do one last request.  I had to make sure to remove the listener on &#8216;loader&#8217; for &#8216;urlLoaded&#8217; since later when I make a new listener and request, both the new and old listeners were triggering (so make sure to remove a listener from a loader if you are going to reuse that var with a different event call back).</p>
<p>&#8216;SERVER&#8217; is the constant that needs to by modified to point to the correct PHP page that will insert the link to the WordPress DB.  &#8217;urlLoaded&#8217; finishes by sending two variables to the SERVER page, &#8216;name&#8217; and &#8216;url&#8217;. After the request is loaded, the &#8217;serverUpdated&#8217; function will display if the process was successful or not based on what is returned by the PHP page.</p>
<p>That&#8217;s pretty much it for the AS3 code.  The PHP file is much more light weight.  At first I had PHP request the HTML for the URL and strip out the title but after thinking about it, it makes more sense to put that burden on the client and not the server so I moved the code to Flash.</p>
<p>The <a title="PHP Code file" href="http://www.joeyrivera.com/blog_files/96/file.html" target="_blank">PHP code</a> starts out by checking for the two needed variables &#8216;url&#8217; and &#8216;name&#8217;.  There&#8217;s a tiny bit of validation going on, definitely more to come as well as implementing some security features since at the moment anyone can submit variables to this page if they know the URL.  (<em>Before posting this, I decided to add a quick security check for now which will see if the remote IP address matches a couple different valid IP address &#8211; such as my home or work PC &#8211; and if it does, it will continue executing</em> ) Then we make a DB connection to the WordPress DB. I have a standard DB class I use, just use regular <a title="php.net mysql_connect info" href="http://us2.php.net/mysql_connect" target="_blank">mysql_connect</a> instead (ask if you need help with this). Next is the query to insert the data into the &#8216;wp_links&#8217; table.  I kept the name default during my WordPress install, so the table name might be different for others. And at last, the query is executed and true is returned. The assumption is if we make it down that far everything worked correctly.  Like I said, I need to add more validation and security but that will be later&#8230; maybe phase 2 or 3.</p>
<p>The only issue I&#8217;m having now that I can&#8217;t seem to figure out is where the WordPress DB tracks what category a link is attached to?  When I log into the WordPress admin area and go to manage links, all the links I&#8217;m inserting using this method don&#8217;t show anything under &#8216;Categories&#8217;. I&#8217;m assuming this information isn&#8217;t in the &#8216;wp_links&#8217; table?  If anyone has an answer to this, please let me know.</p>
<p>Here is a <a title="FLA, Main.as, PHP file, and AIR xml file" href="http://www.joeyrivera.com/blog_files/96/Uploader_0.1.0.zip">zip</a> of all the files (FLA, PHP file, Main class, and AIR xml).  Make sure to edit the ActionScript &#8216;SERVER&#8217; const and DB info in the PHP file.</p>
<p>* Quick side note, I need to give credit to my fiance Ashley who created a quick graphic for me to use last night. Visit her <a title="Ashley Fleishel" href="http://www.ashleyfleishel.com" target="_blank">site</a> to see some of her work.</p>
<p>EDIT:</p>
<p>I forgot to mention I made some edits to the Uploader-app.xml file. These settings were to remove the system chrome and make the app window transparent. More information about these settings can be found at <a title="Information about AIR" href="http://help.adobe.com/en_US/AIR/1.5/devappsflash/WS5b3ccc516d4fbf351e63e3d118666ade46-7ff1.html" target="_blank">help.adobe.com</a>.</p>
<p><a title="Uploader Phase 2 done!" href="http://www.joeyrivera.com/2008/uploader-phase-2-complete/" target="_self">Uploader Phase 2 complete</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.joeyrivera.com/2008/uploader-phase-1/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Uploader: Automating WordPress Links and File Uploads</title>
		<link>http://www.joeyrivera.com/2008/uploader-automating-wordpress-links-and-file-uploads/</link>
		<comments>http://www.joeyrivera.com/2008/uploader-automating-wordpress-links-and-file-uploads/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 01:12:41 +0000</pubDate>
		<dc:creator>Joey</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Uploader]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[wordpress links]]></category>

		<guid isPermaLink="false">http://www.joeyrivera.com/?p=93</guid>
		<description><![CDATA[So now that I&#8217;m starting to get my WordPress and new hosting server settled in I&#8217;m trying to think of what I can create to help me automate some tasks. One of the things I know I&#8217;ll be doing quite often is adding new links to the &#8216;Links of Interest&#8217; on the front page.  I&#8217;ll [...]]]></description>
			<content:encoded><![CDATA[<p>So now that I&#8217;m starting to get my WordPress and new hosting server settled in I&#8217;m trying to think of what I can create to help me automate some tasks. One of the things I know I&#8217;ll be doing quite often is adding new links to the &#8216;Links of Interest&#8217; on the front page.  I&#8217;ll also be uploading files/images to use on posts or to share with others but I&#8217;m too lazy to be ftping files constantly. So&#8230; time for a new tool!</p>
<p>The Uploader (yeah I know, I&#8217;m very creative) is going to do all the above for me. This will be a app I can keep running on my desktop somewhere and when I need to upload a file or link I can just drag it over and drop it in. The tool will then figure out what kind of item was dropped in and what to do with it.</p>
<p>Phase 1 will handle the links. The way the tool should work for links is the following.  I visit a page that I find interesting and want to add to the &#8216;Links of Interest&#8217;.  Instead of logging into WordPress to create it, I highlight the link from the address bar of the browser, drag it over to the app, and drop it. Now the app needs to figure out the &lt;title&gt; of that page to use as the name since we need a name and url to create a link. Once it has that, the tool will send the information to a PHP page which will do an insert to the links table in the WordPress DB.  </p>
<p>Phase 2 will deal with images and files. I may break phase 2 into two since I may do some stuff differently with images versus other files.  I&#8217;m thinking I may want to upload images, create a thumbnail, and insert to a DB to display in the front page the same way some people do with their flickr images. Other files I would just upload and store somewhere else.  I&#8217;ll give this more thought when I get to it.</p>
<p>I&#8217;m going to be writing the tool in Flash CS3/AIR with PHP in the backend using the current WordPress MySQL DB.  Stay tuned for updates!</p>
<p>EDIT:</p>
<p><a title="Uploader Phase 1 done" href="http://www.joeyrivera.com/2008/uploader-phase-1/" target="_self">Uploader Phase 1 completed</a> <br />
<a title="Uploader Phase 2 done" href="http://www.joeyrivera.com/2008/uploader-phase-2-complete/" target="_self"> Uploader Phase 2 completed</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.joeyrivera.com/2008/uploader-automating-wordpress-links-and-file-uploads/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
