<?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>Jacob Wright - Flex, AIR, PHP, etc. &#187; AIR</title>
	<atom:link href="http://jacwright.com/blog/category/air/feed/" rel="self" type="application/rss+xml" />
	<link>http://jacwright.com/blog</link>
	<description>Flex, AIR, PHP, etc.</description>
	<lastBuildDate>Thu, 29 Jul 2010 15:05:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Using AMF as a file format</title>
		<link>http://jacwright.com/blog/248/using-amf-as-a-file-format/</link>
		<comments>http://jacwright.com/blog/248/using-amf-as-a-file-format/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 20:57:40 +0000</pubDate>
		<dc:creator>Jacob Wright</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Applications]]></category>
		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://jacwright.com/blog/?p=248</guid>
		<description><![CDATA[Flash is a great platform. You can build applications for the browser, the desktop, and&#8230; well, what else is there? When building applications, especially those with a document-based model such as the Aviary apps, Odosketch, My Canvas, ZenStudio, the apps on acrobat.com, and many others, you need a file format for the document or project. [...]]]></description>
			<content:encoded><![CDATA[<p>Flash is a great platform. You can build applications for the browser, the desktop, and&#8230; well, what else is there?</p>
<p>When building applications, especially those with a document-based model such as the <a href="http://aviary.com/">Aviary</a> apps, <a href="http://sketch.odopod.com/">Odosketch</a>, <a href="http://www.mycanvas.com/">My Canvas</a>, <a href="http://zenstudio.zenprint.com/">ZenStudio</a>, the apps on acrobat.com, and many others, you need a file format for the document or project. Or some way to save it.</p>
<h3>What Not To Do</h3>
<p>You don&#8217;t want to save each item into a table in the database. I know a guy&#8230;who had a dream&#8230;that his friend did this. This guy&#8217;s friend in his dream had a table for each item that needed to be stored with foreign keys etc. When a project needed to be loaded, the server-side script did a ton of queries and created a sometimes-quite-large XML structure that it then sent to the Flash app. When saving, this XML was sent back and parsed back into the database with INSERTS and UPDATES.</p>
<p>That does not scale, and none of that data was needed to be pulled up in reports or anything that you might consider useful and require a database for. It was complex, hard to add features, and slow. That is, it would have been had that guy&#8217;s dream friend been real.</p>
<h3>Warmer, warmer</h3>
<p>Saving document/project files to disk is the way to go. You can store metadata about each project or document in a database if you are storing them server-side. If it is an AIR app, give it a unique extension and the user can double-click on the file to open it. If you are AIR only, you can save your file as a SQLite database file. Pretty sweet option, but doesn&#8217;t work for the browser &#8217;cause Flash can&#8217;t do that. The format could be XML like OpenOffice documents and the new MS Office formats. You would need to parse the files in and out and they could get very large, so you&#8217;d want to compress them anyway.</p>
<h3>Hot, burning, you&#8217;re on fire!</h3>
<p>So, XML might be the most portable format, but hey, that&#8217;s what Import/Export dialogs are for, right? We&#8217;re talking about Save/Save As&#8230; :) Enter our new contender, AMF! AMF isn&#8217;t really new, however I haven&#8217;t heard of many people using it as their file format. The cool thing about using AMF is that after you&#8217;ve prepared your objects for it, you could store (in player 10) pieces of your document on the clipboard for copy/paste from one place to another (even after a page refresh or from AIR to browser!). You can do an auto-save of a document or page to the user&#8217;s SharedObject store.</p>
<h3>Preparation and implementation</h3>
<p>To use AMF as the format for you data you&#8217;ll need to prepare your objects sufficiently. Here are a few rules:</p>
<ul>
<li><em><strong>No</strong></em> required parameters in your constructors. When AMF unserializes it has to create those objects and assign the public properties to it. You&#8217;ll get errors otherwise.</li>
<li>Register your classes using <span style="font-family: Monaco, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: normal; font-size: 11px; ">flash.net.registerClassAlias<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px; "> or [RemoteClass(alias="...")]. This will store the registered alias name to map a class to a string for serializing and unserializing.</span></span></li>
<li>Use IExternalizable for more complex items that only need a few properties stored, or for Flash classes that can&#8217;t be stored (e.g. BitmapData). This allows you to get around the constructor parameter issue, but it is more work. :)</li>
<li>Make sure any data you need stored is a public getter/setter or you&#8217;ll have to use IExternalizable. AMF serialization will only store data that is public and read/write. If you think about it, it makes sense.</li>
</ul>
<p>The way to store your document object or project object (or page, or widget, or whatever) to AMF depends on where you are storing it. There are a lot of Flash APIs that use AMF already. If you are storing it to SharedObject, just assign the item to the data property or one of its properties.</p>
<pre>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco;">SharedObject.getLocal(<span style="color: #990000;">"_myProject"</span>).data.project1 = myProject;
</pre>
<p>To send it from one app to another over LocalConection is just as easy.</p>
<pre>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco;"><span style="color: #6699cc;">var</span> conn:LocalConnection = <span style="color: #0033ff;">new</span> LocalConnection();
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco;">conn.send(<span style="color: #990000;">"_connName"</span>, <span style="color: #990000;">"passProject"</span>, myProject);
</pre>
<p>To send it to the server vi Flash Remoting you pass the object as-is the same as with LocalConnection.</p>
<p>If you want to save the project to disk or pass it to the server in a RESTful manner or as a file upload, you&#8217;ll need to serialize it to AMF first. But that is pretty easy. Just remember to compress after you write it and uncompress before you read. This will save a lot of room.</p>
<pre>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco;"><span style="color: #6699cc;">var</span> byteArray:ByteArray = <span style="color: #0033ff;">new</span> ByteArray();
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco;">byteArray.writeObject(myProject);
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco;">byteArray.compress();
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #009900;">// write the bytearray to file or send to server
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #009900;">// or we can pull it back out making a clone! (save as...)
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco;">byteArray.position = 0;
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco;">myProject = byteArray.readObject();
</pre>
<p>Easy cheesy. I will leave it as an exercise to the reader to figure out how to store it to the clipboard for copy/paste.</p>
<p>XML might be an easier format, though more verbose and prone to errors in the creation and parsing. Though it could allow for greater flexibility and accessibility to other programs to read the file.</p>
<p>Let me know if you use AMF for your document/project file storage. I&#8217;d be interested to hear how many people use this method and how well it has worked out for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://jacwright.com/blog/248/using-amf-as-a-file-format/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Would it be bad to leave behind our Flash roots?</title>
		<link>http://jacwright.com/blog/209/would-it-be-bad-to-leave-behind-our-flash-roots/</link>
		<comments>http://jacwright.com/blog/209/would-it-be-bad-to-leave-behind-our-flash-roots/#comments</comments>
		<pubDate>Thu, 14 May 2009 17:02:49 +0000</pubDate>
		<dc:creator>Jacob Wright</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://jacwright.com/blog/?p=209</guid>
		<description><![CDATA[I am working with Tyler on Stealth, our high-performance component framework. After reading this article on performance by Arno Gourdol of Adobe I began wondering if we should leave behind our Flash roots of motion and timeline design by defaulting framerate to 0 in our Stealth-based applications. Framerate makes great sense when doing games or [...]]]></description>
			<content:encoded><![CDATA[<p>I am working with <a href="http://www.xtyler.com/">Tyler</a> on Stealth, our high-performance component framework. After reading <a href="http://arno.org/arnotify/2009/05/writing-well-behaved-efficient-air-applications/" title="Writing well-behaved, efficient, AIR applications">this article</a> on performance by Arno Gourdol of Adobe I began wondering if we should leave behind our Flash roots of motion and timeline design by defaulting framerate to 0 in our Stealth-based applications.</p>
<p>Framerate makes great sense when doing games or timeline based animations, but in applications do we need it? We can update the screen on mouse moves, roll overs, etc. with the MouseEvent.updateAfterEvent instance method. And for transitions and tweening the class could use a Timer for the duration of the animation and again call Timer.updateAfterEvent. Then the screen would only refresh when it needs to. Performance would be greatly increased. Seems like it makes sense. Would this be something to add to Flex? Would it give us the performance we need/want for mobile applications and more responsive desktop applications?</p>
<p>Any foreseeable drawbacks? What do you think?</p>
<p><strong>Update:</strong> I did some testing and it seems that the Timer class is directly influenced by the frameRate. With a frame rate of 0 a timer which should fire immediately (set to 0ms) doesn&#8217;t fire for 20 seconds! With the frame rate a 0.1 it happens at about 2 seconds, a frame rate of 1 is about 145 ms and a frame rate of anything over 4 seems to be around the same (10ms &#8211; 30ms probably depending on what the OS is currently doing).</p>
<p>MouseEvent updating and such happen as they should however, so as long as you start of with a frame rate of 4 so that the app can initialize visually, you could drop it down to 0 until a tween is needed and then bump it up to 4 for the duration of the tween. The rest of the visual changes can respond to mouse events (resize, click, rollover, etc). Or leaving it at 4 frames a second probably isn&#8217;t too bad on CPU, either way, you&#8217;d have to call updateAfterEvent when needed.</p>
]]></content:encoded>
			<wfw:commentRss>http://jacwright.com/blog/209/would-it-be-bad-to-leave-behind-our-flash-roots/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Layered Content, 2 Parts</title>
		<link>http://jacwright.com/blog/86/layered-content-2-parts/</link>
		<comments>http://jacwright.com/blog/86/layered-content-2-parts/#comments</comments>
		<pubDate>Tue, 08 Jul 2008 23:41:39 +0000</pubDate>
		<dc:creator>Jacob Wright</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Applications]]></category>
		<category><![CDATA[Layered Content]]></category>

		<guid isPermaLink="false">http://jacwright.com/blog/?p=86</guid>
		<description><![CDATA[I&#8217;ve had some time between jobs recently and been working on Layered Content. Layered Content is a website management system or web content management system (CMS). I&#8217;ve had a lot of fun over the past two years using it, architecting it, and planning it out. When I started I was determined to make a usable [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had some time between jobs recently and been working on Layered Content. Layered Content is a website management system or web content management system (CMS). I&#8217;ve had a lot of fun over the past two years using it, architecting it, and planning it out. When I started I was determined to make a usable CMS, one that didn&#8217;t require training courses to use, one that wasn&#8217;t too simple that you couldn&#8217;t make the website you wanted. A big challenge, but one I felt needed to finally be addressed by somebody.</p>
<p>There have been a couple versions, the first was completely web-based using Ajax, the second a mix of Ajax and Flex. Both of these versions were browser based. Both of these versions had limitations and issues <em>because</em> they were browser based. Enter <em>final version</em>.</p>
<p>The final version will be in 2 parts, a server part and a client part. The server part will be a RESTful webservice using Atom Publishing Protocol, the same protocol Google uses for its Google App Data services. This allows other applications to hook into the CMS and export data and make changes with the appropriate permissions. It could even allow for mashups. I&#8217;m certainly interested to see what people will do with it.</p>
<p>The client part will be created using Adobe Integrated Runtime (AIR). This multi-platform (i.e. runs on Windows, Mac, and Linux) will give people the benefits of a browser-based admin along with the benefits of the desktop. I&#8217;ll have one browser to deal with and will be able to easily allow in-page editing. The javascript used will be much smaller and easier to deal with since I&#8217;m not worrying about cross-browser compatibility. And I&#8217;ll be able to add features such as drag-and-drop or client-side caching of the data in a local database.</p>
<p>I&#8217;ve almost got the server component done. It will be called Layered Content Server. Layered Content Client will run off of a server instance and together they&#8217;ll make Layered Content, a usable &#8212; as in easy to use while not limiting functionality and features &#8212; CMS.</p>
<p>You can learn more about the architectural decisions behind Layered Content which will allow it to be easier to use and still quite functional at the <a href="http://layeredcontent.org/wiki/index.php/Layered_Content">wiki</a>. I&#8217;ll be asking for help once I get a pre-alpha version out so keep an eye out for it.</p>
]]></content:encoded>
			<wfw:commentRss>http://jacwright.com/blog/86/layered-content-2-parts/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>AIR ActiveRecord is Open Source</title>
		<link>http://jacwright.com/blog/79/air-activerecord-is-open-source/</link>
		<comments>http://jacwright.com/blog/79/air-activerecord-is-open-source/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 03:22:13 +0000</pubDate>
		<dc:creator>Jacob Wright</dc:creator>
				<category><![CDATA[AIR]]></category>

		<guid isPermaLink="false">http://jacwright.com/blog/?p=79</guid>
		<description><![CDATA[I wrote about an Active Record implementation for the Adobe Integrated Runtime using it's SQLite database functionality. I put up all the code on Google Code under the name AIR Active Record. Please check it out, let me know of bugs or features, or better yet, submit fixes and add-ons. If you're interested in being [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote about an <a title="AIR Active Record" href="http://jacwright.com/blog/55/air-active-record/">Active Record</a> implementation for the Adobe Integrated Runtime using it's SQLite database functionality. I put up all the code on Google Code under the name <a href="http://code.google.com/p/air-activerecord/">AIR Active Record</a>. Please check it out, let me know of bugs or features, or better yet, submit fixes and add-ons. If you're interested in being an active developer on it let me know.</p>
<p><strong>Update:</strong></p>
<p>To use the ActiveRecord (sorry for the lack of documentation), you need to extend it with a class for each table you'll use. For example, if I wanted an employee table I would create an Employee class like this:</p>
<div class="code">
<div class="syntax_hilite">
<div id="actionscript-5">
<div class="actionscript">package<br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flight.<span style="color: #006600;">db</span>.<span style="color: #006600;">activeRecord</span>.<span style="color: #006600;">ActiveRecord</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>RelatedTo<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">"tasks"</span>, className=<span style="color: #ff0000;">"Task"</span>, multiple<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">dynamic</span> <span style="color: #000000; font-weight: bold;">class</span> Employee <span style="color: #0066CC;">extends</span> ActiveRecord<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">name</span>:<span style="color: #0066CC;">String</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">position</span>:<span style="color: #0066CC;">String</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> hireDate:<span style="color: #0066CC;">Date</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> salary:<span style="color: #0066CC;">Number</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> created:<span style="color: #0066CC;">Date</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> modified:<span style="color: #0066CC;">Date</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></div>
<div class="code">
<div class="syntax_hilite">
<div id="actionscript-6">
<div class="actionscript">package<br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flight.<span style="color: #006600;">db</span>.<span style="color: #006600;">activeRecord</span>.<span style="color: #006600;">ActiveRecord</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>RelatedTo<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">"employee"</span>, className=<span style="color: #ff0000;">"Employee"</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">dynamic</span> <span style="color: #000000; font-weight: bold;">class</span> Task <span style="color: #0066CC;">extends</span> ActiveRecord<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> employeeId:uint;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> todo:<span style="color: #0066CC;">String</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> created:<span style="color: #0066CC;">Date</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> modified:<span style="color: #0066CC;">Date</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Task<span style="color: #66cc66;">&#40;</span>todo:<span style="color: #0066CC;">String</span> = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">todo</span> = todo;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></div>
<p>In the metadata, the <strong>name</strong> is the property name which will be auto-generated and auto-populated (when you access it) for the relation. The className is the full class path (e.g. com.foo.Bar). multiple is a flag that specifies whether it's a one-to-many relationship. You can have many-to-many relationships as well.</p>
<p>If you aren't creating the database yourself there is a handy-dandy feature which will do it for you off of code introspection. Many-to-many is not supported for creation this way unless you have a class for that join table and run it on that.</p>
<div class="code">
<div class="syntax_hilite">
<div id="actionscript-7">
<div class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> employee:Employee = <span style="color: #000000; font-weight: bold;">new</span> Employee<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
TableCreator.<span style="color: #006600;">updateTable</span><span style="color: #66cc66;">&#40;</span>employee<span style="color: #66cc66;">&#41;</span>;</div>
</div>
</div>
<p></div>
<p>This will create the table if it doesn't exist, but it is also useful for updating the table if you've added new properties to the class. (right now it doesn't delete columns if you remove properties)</p>
<p>Then, you use it. You'll need to look at the code comments, or maybe generate the AS3 docs off of it to see all you can do, but this is some of what you can do (let's say you have an Employee class and a Task class):</p>
<div class="code">
<div class="syntax_hilite">
<div id="actionscript-8">
<div class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> employee = <span style="color: #000000; font-weight: bold;">new</span> Employee<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
employee.<span style="color: #006600;">loadBy</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"username = ?"</span>, <span style="color: #ff0000;">"bobTheBuilder"</span><span style="color: #66cc66;">&#41;</span>;</p>
<p><span style="color: #808080; font-style: italic;">// accessing tasks will autoload them from the database</span><br />
<span style="color: #b1b100;">for</span> each <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> task:Task <span style="color: #b1b100;">in</span> employee.<span style="color: #006600;">tasks</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>task<span style="color: #66cc66;">&#41;</span>;</p>
<p>task = <span style="color: #000000; font-weight: bold;">new</span> Task<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Call your mother"</span><span style="color: #66cc66;">&#41;</span>;<br />
employee.<span style="color: #006600;">task</span>.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>task<span style="color: #66cc66;">&#41;</span>;<br />
employee.<span style="color: #006600;">saveTasks</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</p>
<p>employee.<span style="color: #006600;">firstName</span> = <span style="color: #ff0000;">"Bobby"</span>;<br />
employee.<span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</p>
<p><span style="color: #000000; font-weight: bold;">var</span> employee2:Employee = <span style="color: #000000; font-weight: bold;">new</span> Employee<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
employee2.<span style="color: #006600;">firstName</span> = <span style="color: #ff0000;">"Sue"</span>;<br />
....<br />
<span style="color: #006600;">employee2</span>.<span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>employee2.<span style="color: #006600;">id</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// new id </span></div>
</div>
</div>
<p></div>
<p>Pretty cool stuff. Maybe someone should document it! :D Anyone interested in figuring out and documenting super-cool code, please apply!</p>
]]></content:encoded>
			<wfw:commentRss>http://jacwright.com/blog/79/air-activerecord-is-open-source/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>AIR Project Tracker (timer, task-list)</title>
		<link>http://jacwright.com/blog/62/air-project-tracker-timer-task-list/</link>
		<comments>http://jacwright.com/blog/62/air-project-tracker-timer-task-list/#comments</comments>
		<pubDate>Sat, 12 Jan 2008 17:44:38 +0000</pubDate>
		<dc:creator>Jacob Wright</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://jacwright.com/blog/62/air-project-tracker-timer-task-list/</guid>
		<description><![CDATA[I wrote a project timer awhile ago. After I had done that (in Flash 8) I needed a task list that could be split up by client and project, so I combined the old time and a new task list into what I called creatively the Project Tracker. I've been using it since Apollo preview [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote a project timer awhile ago. After I had done that (in Flash 8) I needed a task list that could be split up by client and project, so I combined the old time and a new task list into what I called creatively the Project Tracker. I've been using it since Apollo preview release. I just added a new feature for myself that rounds the times to the nearest half-hour or hour if desired (since that's how my company bills clients), and I thought that I'd share it. It allows you to keep track of time spent on tasks, project, and clients as well as let's you check off any of them when complete. You can also store notes about each of them.</p>
<p>It doesn't use any AIR specific features, just SharedObject, but I sure like to have it as a desktop application rather than in the browser. I always close browser versions on accident.</p>
<p>This application is provided as-is with no documentation, support, or guarantee of anything. Hope you find it useful. You can view <a href="/projectTracker/ProjectTracker.html" target="_blank">Project Tracker</a> in your web browser before you download it.</p>
<p><strong>Update:</strong> Republished for the AIR 1.0 release and updated badge install.<br />
<strong>Update 2:</strong> Found and fixed the problem reported in comments. Using a relative path in the badge installer for AIR apps results in some of the errors reported.</p>
<p><script src="/projectTracker/AC_RunActiveContent.js" type="text/javascript"></script><br />
<script src="/projectTracker/showBadge.js" type="text/javascript"></script><br />
<script src="/projectTracker/InstallBadge.js" type="text/javascript"></script></p>
<p><noscript><br />
<table id="messageTable">
<tr>
<td>
	This application requires the following be installed:</p>
<ol>
<li><a href="http://adobe.com/go/getair/">Adobe&#174; AIR&#8482; Runtime</a></li>
<li><a href="http://jacwright.com/projectTracker/ProjectTracker.air">Project Tracker</a></li>
</ol>
<p>	Please click on each link in the order above to complete the installation process.
	</td>
</tr>
</table>
<p></noscript></p>
]]></content:encoded>
			<wfw:commentRss>http://jacwright.com/blog/62/air-project-tracker-timer-task-list/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>Idea for an AIR App</title>
		<link>http://jacwright.com/blog/61/idea-for-an-air-app/</link>
		<comments>http://jacwright.com/blog/61/idea-for-an-air-app/#comments</comments>
		<pubDate>Thu, 10 Jan 2008 18:50:19 +0000</pubDate>
		<dc:creator>Jacob Wright</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://jacwright.com/blog/61/idea-for-an-air-app/</guid>
		<description><![CDATA[I'm working on a library to give rich text or WYSIWYG functionality to an AIR HTMLLoader. It's coming along nicely thus far. I have all the keyboard shortcuts happening and the HTML is being replaced by the appropriate stuff (e.g. bold fixes webkit's &#60;span class="Apple-blah blah" style="font-weight: bold"&#62; to just &#60;b&#62;). I've got undo/redo in [...]]]></description>
			<content:encoded><![CDATA[<p>I'm working on a library to give rich text or WYSIWYG functionality to an AIR HTMLLoader. It's coming along nicely thus far. I have all the keyboard shortcuts happening and the HTML is being replaced by the appropriate stuff (e.g. bold fixes webkit's &lt;span class="Apple-blah blah" style="font-weight: bold"&gt; to just &lt;b&gt;). I've got undo/redo in place even with typing and deleting etc.</p>
<p>So I was thinking, it would be cool to write a <a href="http://docbook.org">DocBook</a> editor in AIR. It might be the first DocBook authoring tool that looked nice. :) DocBook is an XML format for books or documentation. I won't go into why it's so great, but you can check it out yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://jacwright.com/blog/61/idea-for-an-air-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using MXML for AIR NativeMenus</title>
		<link>http://jacwright.com/blog/59/using-mxml-for-air-nativemenus/</link>
		<comments>http://jacwright.com/blog/59/using-mxml-for-air-nativemenus/#comments</comments>
		<pubDate>Tue, 08 Jan 2008 03:35:25 +0000</pubDate>
		<dc:creator>Jacob Wright</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://jacwright.com/blog/59/mxml-for-air-nativemenus/</guid>
		<description><![CDATA[NativeMenus for AIR have been somewhat of a pain since each item in a menu can take 3-4 lines of code or more to write once you add the listener, the key shortcuts, etc. Then when you've got 20 items or so you have an unreadable unmanageable mess to deal with. Very unFlexy. So I [...]]]></description>
			<content:encoded><![CDATA[<p>NativeMenus for AIR have been somewhat of a pain since each item in a menu can take 3-4 lines of code or more to write once you add the listener, the key shortcuts, etc. Then when you've got 20 items or so you have an unreadable unmanageable mess to deal with. Very unFlexy. So I set about making it work in MXML with the advantages of readability, conciseness, and don't forget bindability. This makes it a much cleaner solution than a <a href="http://blog.everythingflex.com/2007/10/18/air-contextwindow/">component</a> which creates a commonly used menu or using <a href="http://frishy.blogspot.com/2007/12/making-flex-menus-easier.html">XML data providers</a> to define the menus.</p>
<p>First I created a Menu class which extends NativeMenu. Because of the way MXML works we will need to set our menu's items in one go rather than using the <code>addItem</code> and <code>addItemAt</code> methods. So I created an <code>items</code> setter to complement the <code>items</code> getter which is part of NativeMenu.</p>
<div class="code">
<div class="syntax_hilite">
<div id="actionscript-17">
<div class="actionscript"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> items<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span>numItems<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; removeItemAt<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #b1b100;">for</span> each <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> item:NativeMenuItem <span style="color: #b1b100;">in</span> value<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; addItem<span style="color: #66cc66;">&#40;</span>item<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></div>
<p>I want all of the MXML tags under my &lt;Menu&gt; tag to be the MenuItems, so in order to tell the compiler where those go I also added a metadata tag at the top of my class.</p>
<div class="code">
<div class="syntax_hilite">
<div id="actionscript-18">
<div class="actionscript"><span style="color: #66cc66;">&#91;</span>DefaultProperty<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"items"</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span></div>
</div>
</div>
<p></div>
<p>Now moving on to the items themselves I created a MenuItem class. I wanted some more magic here since this is where all the hassle goes. First thing I wanted to do was to make a simple way to define the key shortcut. In code you have to add a <code>keyEquivalent</code> letter and a <code>keyEquivalentModifiers</code> entry for each modifier key. Way too complex for MXML. So I created a getter/setter called <code>shortcut</code> that parsed a string and added the pieces for you. Now I could have shortcuts that looked like "Ctrl+P" and "Cmd+Shift+F" in the MXML. Very readable. Much better. (I also set Cmd to Ctrl when on Windows since Mac Cmd shortcuts are usually the same as Windows Ctrl.)</p>
<div class="code">
<div class="syntax_hilite">
<div id="actionscript-19">
<div class="actionscript"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> shortcut<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!keyEquivalent &amp;&amp; !keyEquivalentModifiers.<span style="color: #0066CC;">length</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #ff0000;">""</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> shortcut:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">""</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>keyEquivalentModifiers.<span style="color: #0066CC;">indexOf</span><span style="color: #66cc66;">&#40;</span>Keyboard.<span style="color: #006600;">COMMAND</span><span style="color: #66cc66;">&#41;</span> != -<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; shortcut += <span style="color: #ff0000;">"Cmd+"</span>;<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>keyEquivalentModifiers.<span style="color: #0066CC;">indexOf</span><span style="color: #66cc66;">&#40;</span>Keyboard.<span style="color: #0066CC;">CONTROL</span><span style="color: #66cc66;">&#41;</span> != -<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; shortcut += <span style="color: #ff0000;">"Ctrl+"</span>;<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>keyEquivalentModifiers.<span style="color: #0066CC;">indexOf</span><span style="color: #66cc66;">&#40;</span>Keyboard.<span style="color: #006600;">ALTERNATE</span><span style="color: #66cc66;">&#41;</span> != -<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; shortcut += <span style="color: #ff0000;">"Alt+"</span>;<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>keyEquivalentModifiers.<span style="color: #0066CC;">indexOf</span><span style="color: #66cc66;">&#40;</span>Keyboard.<span style="color: #006600;">SHIFT</span><span style="color: #66cc66;">&#41;</span> != -<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; shortcut += <span style="color: #ff0000;">"Shift+"</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; shortcut += keyEquivalent;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> shortcut;<br />
<span style="color: #66cc66;">&#125;</span></p>
<p><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> shortcut<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> keys:<span style="color: #0066CC;">Array</span> = value.<span style="color: #0066CC;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"+"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> mods:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> theKey:<span style="color: #0066CC;">String</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">os</span>:<span style="color: #0066CC;">String</span> = <span style="color: #0066CC;">Capabilities</span>.<span style="color: #0066CC;">os</span>.<span style="color: #0066CC;">substr</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">for</span> each <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">key</span>:<span style="color: #0066CC;">String</span> <span style="color: #b1b100;">in</span> keys<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">key</span> == <span style="color: #ff0000;">"cmd"</span> &amp;&amp; <span style="color: #0066CC;">os</span> == <span style="color: #ff0000;">"mac"</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mods.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>Keyboard.<span style="color: #006600;">COMMAND</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">key</span> == <span style="color: #ff0000;">"cmd"</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mods.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>Keyboard.<span style="color: #0066CC;">CONTROL</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">key</span> == <span style="color: #ff0000;">"ctrl"</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mods.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>Keyboard.<span style="color: #0066CC;">CONTROL</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">key</span> == <span style="color: #ff0000;">"alt"</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mods.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>Keyboard.<span style="color: #006600;">ALTERNATE</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">key</span> == <span style="color: #ff0000;">"shift"</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mods.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>Keyboard.<span style="color: #006600;">SHIFT</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!theKey<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; theKey = <span style="color: #0066CC;">key</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#40;</span>value + <span style="color: #ff0000;">" is an invalid menu shortcut"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; keyEquivalentModifiers = mods;<br />
&nbsp; &nbsp; keyEquivalent = theKey;<br />
<span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></div>
<p>Next I tackled submenus. I created a getter/setter called <code>items</code> (same as the menu now) which let you specify your submenu's items directly underneath the parent item. I figured it's not a common use-case to add listeners on the submenu itself. I also added the metadata to make MXML items inside of a MenuItem map to the "items" property.</p>
<div class="code">
<div class="syntax_hilite">
<div id="actionscript-20">
<div class="actionscript"><span style="color: #66cc66;">&#91;</span>DefaultProperty<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"items"</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MenuItem <span style="color: #0066CC;">extends</span> NativeMenuItem<br />
<span style="color: #66cc66;">&#123;</span><br />
...<br />
...<br />
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> items<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Array</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>submenu<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> submenu.<span style="color: #006600;">items</span>;<br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;<br />
<span style="color: #66cc66;">&#125;</span></p>
<p><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> items<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; submenu = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Menu</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">Menu</span><span style="color: #66cc66;">&#40;</span>submenu<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">items</span> = value;<br />
<span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></div>
<p>Now our items can have their subitems directly under them in the MXML.</p>
<p>Finally I looked at adding support for the mnemonicIndex property to get set. For those of you who don't know what this is, it tells AIR which letter in the menu to underline and allow a key-stroke to select it (I believe it is a Windows feature, but may be supported on Mac as well....somehow). Very important for accessibility. So I figured I'll just have an underscore denote which letter should be, such as "_File" would say that "F" is the mnemonic letter.</p>
<div class="code">
<div class="syntax_hilite">
<div id="actionscript-21">
<div class="actionscript"><span style="color: #0066CC;">public</span> override <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> label<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">index</span>:<span style="color: #0066CC;">int</span> = value.<span style="color: #0066CC;">indexOf</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"_"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">index</span> != -<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; mnemonicIndex = <span style="color: #0066CC;">index</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; value = value.<span style="color: #0066CC;">substring</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#41;</span> + value.<span style="color: #0066CC;">substring</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">index</span> + <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">super</span>.<span style="color: #006600;">label</span> = value;<br />
<span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></div>
<p>Nicely done. We now have our label set and our mnemonic letter specified with just the label property, and this lends itself to setting the mnemonic letter separately for other languages as it is part of the label text.</p>
<p>I quickly added a MenuSeparator which just extended NativeMenuItem and set the isSeparator value in the constructor to true. This was for readability in the MXML.</p>
<p>The last thing I wanted to do is to add support for menu differences between Ma, Windows and Linux. This was a last minute idea because menus can look differently, behave differently, or have different shortcuts between the two systems. So I added a property to MenuItem called "os" which should be a string of "mac", "win", "lin" or a combination of them such as "win/lin". Then I added to the Menu items setter code that would skip over adding items which were set for an OS that was not the current one. This allows two items with the same name to be specified but with different shortcuts, or two submenus that are different on different OSes.</p>
<p>Now I could define menus in MXML like this:</p>
<div class="code">
<div class="syntax_hilite">
<div id="xml-22">
<div class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ui</span>:Menu <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"mainMenu"</span><span style="font-weight: bold; color: black;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ui</span>:MenuItem <span style="color: #000066;">label</span>=<span style="color: #ff0000;">"_File"</span><span style="font-weight: bold; color: black;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ui</span>:MenuItem <span style="color: #000066;">label</span>=<span style="color: #ff0000;">"_New"</span> <span style="color: #000066;">shortcut</span>=<span style="color: #ff0000;">"Cmd+N"</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">"newDocument()"</span><span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ui</span>:MenuItem <span style="color: #000066;">label</span>=<span style="color: #ff0000;">"_Open"</span> <span style="color: #000066;">shortcut</span>=<span style="color: #ff0000;">"Cmd+O"</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">"openDocument()"</span><span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ui</span>:MenuSeparator<span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ui</span>:MenuItem <span style="color: #000066;">label</span>=<span style="color: #ff0000;">"_Close"</span> <span style="color: #000066;">shortcut</span>=<span style="color: #ff0000;">"Cmd+W"</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">"closeDocument()"</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">"{document != null}"</span> <span style="color: #000066;">os</span>=<span style="color: #ff0000;">"mac"</span><span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ui</span>:MenuItem <span style="color: #000066;">label</span>=<span style="color: #ff0000;">"_Close"</span> <span style="color: #000066;">shortcut</span>=<span style="color: #ff0000;">"Ctrl+F4"</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">"closeDocument()"</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">"{document != null}"</span> <span style="color: #000066;">os</span>=<span style="color: #ff0000;">"win"</span><span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ui</span>:MenuSeparator<span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ui</span>:MenuItem <span style="color: #000066;">label</span>=<span style="color: #ff0000;">"_Save"</span> <span style="color: #000066;">shortcut</span>=<span style="color: #ff0000;">"Cmd+S"</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">"saveDocument()"</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">"{document != null}"</span><span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ui</span>:MenuItem <span style="color: #000066;">label</span>=<span style="color: #ff0000;">"Save _As"</span> <span style="color: #000066;">shortcut</span>=<span style="color: #ff0000;">"Cmd+Shift+S"</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">"saveAsDocument()"</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">"{document != null}"</span><span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ui</span>:MenuItem <span style="color: #000066;">label</span>=<span style="color: #ff0000;">"E_xit"</span> <span style="color: #000066;">shortcut</span>=<span style="color: #ff0000;">"Cmd+Q"</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">"close()"</span> <span style="color: #000066;">os</span>=<span style="color: #ff0000;">"mac"</span><span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ui</span>:MenuItem <span style="color: #000066;">label</span>=<span style="color: #ff0000;">"E_xit"</span> <span style="color: #000066;">shortcut</span>=<span style="color: #ff0000;">"Alt+F4"</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">"close()"</span> <span style="color: #000066;">os</span>=<span style="color: #ff0000;">"win"</span><span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ui</span>:MenuItem<span style="font-weight: bold; color: black;">&gt;</span></span><br />
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ui</span>:Menu<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</div>
</div>
<p></div>
<p>The final result was:</p>
<div class="code">
<div class="syntax_hilite">
<div id="actionscript-23">
<div class="actionscript"><span style="color: #66cc66;">&#91;</span>DefaultProperty<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"items"</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> <span style="color: #0066CC;">Menu</span> <span style="color: #0066CC;">extends</span> NativeMenu<br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> items<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span>numItems<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; removeItemAt<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">os</span>:<span style="color: #0066CC;">String</span> = <span style="color: #0066CC;">Capabilities</span>.<span style="color: #0066CC;">os</span>.<span style="color: #0066CC;">substring</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> each <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> item:NativeMenuItem <span style="color: #b1b100;">in</span> value<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>item is MenuItem &amp;&amp; MenuItem<span style="color: #66cc66;">&#40;</span>item<span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">os</span> &amp;&amp; MenuItem<span style="color: #66cc66;">&#40;</span>item<span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">os</span>.<span style="color: #0066CC;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">indexOf</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">os</span><span style="color: #66cc66;">&#41;</span> == -<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">continue</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addItem<span style="color: #66cc66;">&#40;</span>item<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></p>
<p>------</p>
<p><span style="color: #66cc66;">&#91;</span>DefaultProperty<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"items"</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MenuItem <span style="color: #0066CC;">extends</span> NativeMenuItem<br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">os</span>:<span style="color: #0066CC;">String</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MenuItem<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> override <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> label<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">index</span>:<span style="color: #0066CC;">int</span> = value.<span style="color: #0066CC;">indexOf</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"_"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">index</span> != -<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mnemonicIndex = <span style="color: #0066CC;">index</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value = value.<span style="color: #0066CC;">substring</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#41;</span> + value.<span style="color: #0066CC;">substring</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">index</span> + <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span>.<span style="color: #006600;">label</span> = value;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> items<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Array</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>submenu<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> submenu.<span style="color: #006600;">items</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> items<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; submenu = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Menu</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">Menu</span><span style="color: #66cc66;">&#40;</span>submenu<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">items</span> = value;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> shortcut<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!keyEquivalent &amp;&amp; !keyEquivalentModifiers.<span style="color: #0066CC;">length</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #ff0000;">""</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> shortcut:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">""</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>keyEquivalentModifiers.<span style="color: #0066CC;">indexOf</span><span style="color: #66cc66;">&#40;</span>Keyboard.<span style="color: #006600;">COMMAND</span><span style="color: #66cc66;">&#41;</span> != -<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shortcut += <span style="color: #ff0000;">"Cmd+"</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>keyEquivalentModifiers.<span style="color: #0066CC;">indexOf</span><span style="color: #66cc66;">&#40;</span>Keyboard.<span style="color: #0066CC;">CONTROL</span><span style="color: #66cc66;">&#41;</span> != -<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shortcut += <span style="color: #ff0000;">"Ctrl+"</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>keyEquivalentModifiers.<span style="color: #0066CC;">indexOf</span><span style="color: #66cc66;">&#40;</span>Keyboard.<span style="color: #006600;">ALTERNATE</span><span style="color: #66cc66;">&#41;</span> != -<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shortcut += <span style="color: #ff0000;">"Alt+"</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>keyEquivalentModifiers.<span style="color: #0066CC;">indexOf</span><span style="color: #66cc66;">&#40;</span>Keyboard.<span style="color: #006600;">SHIFT</span><span style="color: #66cc66;">&#41;</span> != -<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shortcut += <span style="color: #ff0000;">"Shift+"</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; shortcut += keyEquivalent;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> shortcut;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> shortcut<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> keys:<span style="color: #0066CC;">Array</span> = value.<span style="color: #0066CC;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"+"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> mods:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> theKey:<span style="color: #0066CC;">String</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">os</span>:<span style="color: #0066CC;">String</span> = <span style="color: #0066CC;">Capabilities</span>.<span style="color: #0066CC;">os</span>.<span style="color: #0066CC;">substr</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">toLowerCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> each <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">key</span>:<span style="color: #0066CC;">String</span> <span style="color: #b1b100;">in</span> keys<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">key</span> == <span style="color: #ff0000;">"cmd"</span> &amp;&amp; <span style="color: #0066CC;">os</span> == <span style="color: #ff0000;">"mac"</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mods.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>Keyboard.<span style="color: #006600;">COMMAND</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">key</span> == <span style="color: #ff0000;">"cmd"</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mods.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>Keyboard.<span style="color: #0066CC;">CONTROL</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">key</span> == <span style="color: #ff0000;">"ctrl"</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mods.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>Keyboard.<span style="color: #0066CC;">CONTROL</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">key</span> == <span style="color: #ff0000;">"alt"</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mods.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>Keyboard.<span style="color: #006600;">ALTERNATE</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">key</span> == <span style="color: #ff0000;">"shift"</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mods.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>Keyboard.<span style="color: #006600;">SHIFT</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!theKey<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; theKey = <span style="color: #0066CC;">key</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#40;</span>value + <span style="color: #ff0000;">" is an invalid menu shortcut"</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; keyEquivalentModifiers = mods;<br />
&nbsp; &nbsp; &nbsp; &nbsp; keyEquivalent = theKey;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></p>
<p>-----</p>
<p><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MenuSeparator <span style="color: #0066CC;">extends</span> NativeMenuItem<br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MenuSeparator<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div>
</div>
</div>
<p></div>
<p>Enjoy!</p>
<p><strong>Update:</strong> I've put my <a href="http://code.google.com/p/jacwright/source/browse/#svn/trunk/flash/jac_air/src/jac/ui">code libraries</a> up on Google Code. You can find the classes there. Following is an example app with a simple menu.</p>
<div class="code">
<div class="syntax_hilite">
<div id="xml-24">
<div class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;</span>?xml <span style="color: #000066;">version</span>=<span style="color: #ff0000;">"1.0"</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">"utf-8"</span>?<span style="font-weight: bold; color: black;">&gt;</span></span><br />
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;mx</span>:WindowedApplication<br />
&nbsp; &nbsp; <span style="color: #000066;">applicationComplete</span>=<span style="color: #ff0000;">"initMenu()"</span><br />
&nbsp; &nbsp; xmlns:<span style="color: #000066;">mx</span>=<span style="color: #ff0000;">"http://www.adobe.com/2006/mxml"</span><br />
&nbsp; &nbsp; xmlns:<span style="color: #000066;">ui</span>=<span style="color: #ff0000;">"jac.ui.*"</span><span style="font-weight: bold; color: black;">&gt;</span></span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;mx</span>:Script<span style="font-weight: bold; color: black;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;![CDATA[<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; import jac.ui.Menus;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; private function initMenu():void<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // utility to help merge the menu with Mac OS X's native menu<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // and to decide between the main menu on mac or window menu on<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // windows.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Menus.initMainMenu(mainMenu, stage.nativeWindow)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; ]]&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/mx</span>:Script<span style="font-weight: bold; color: black;">&gt;</span></span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ui</span>:Menu <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"mainMenu"</span><span style="font-weight: bold; color: black;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ui</span>:MenuItem <span style="color: #000066;">label</span>=<span style="color: #ff0000;">"_File"</span><span style="font-weight: bold; color: black;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ui</span>:MenuItem <span style="color: #000066;">label</span>=<span style="color: #ff0000;">"_New"</span> <span style="color: #000066;">shortcut</span>=<span style="color: #ff0000;">"Cmd+N"</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">"trace('New')"</span><span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ui</span>:MenuItem <span style="color: #000066;">label</span>=<span style="color: #ff0000;">"_Open"</span> <span style="color: #000066;">shortcut</span>=<span style="color: #ff0000;">"Cmd+O"</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">"trace('Open')"</span><span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ui</span>:MenuSeparator<span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ui</span>:MenuItem <span style="color: #000066;">label</span>=<span style="color: #ff0000;">"_Save"</span> <span style="color: #000066;">shortcut</span>=<span style="color: #ff0000;">"Cmd+S"</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">"trace('Save')"</span><span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ui</span>:MenuItem <span style="color: #000066;">label</span>=<span style="color: #ff0000;">"Save _As"</span> <span style="color: #000066;">shortcut</span>=<span style="color: #ff0000;">"Cmd+Shift+S"</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">"trace('Save As')"</span><span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ui</span>:MenuSeparator<span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ui</span>:MenuItem <span style="color: #000066;">label</span>=<span style="color: #ff0000;">"_Close"</span> <span style="color: #000066;">shortcut</span>=<span style="color: #ff0000;">"Cmd+W"</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">"trace('Close');stage.nativeWindow.close()"</span> <span style="color: #000066;">os</span>=<span style="color: #ff0000;">"mac"</span><span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ui</span>:MenuItem <span style="color: #000066;">label</span>=<span style="color: #ff0000;">"_Close"</span> <span style="color: #000066;">shortcut</span>=<span style="color: #ff0000;">"Ctrl+F4"</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">"trace('Close');stage.nativeWindow.close()"</span> <span style="color: #000066;">os</span>=<span style="color: #ff0000;">"win"</span><span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ui</span>:MenuItem <span style="color: #000066;">label</span>=<span style="color: #ff0000;">"E_xit"</span> <span style="color: #000066;">shortcut</span>=<span style="color: #ff0000;">"Cmd+Q"</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">"trace('Exit');nativeApplication.exit()"</span> <span style="color: #000066;">os</span>=<span style="color: #ff0000;">"mac"</span><span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ui</span>:MenuItem <span style="color: #000066;">label</span>=<span style="color: #ff0000;">"E_xit"</span> <span style="color: #000066;">shortcut</span>=<span style="color: #ff0000;">"Alt+F4"</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">"trace('Exit');nativeApplication.exit()"</span> <span style="color: #000066;">os</span>=<span style="color: #ff0000;">"win"</span><span style="font-weight: bold; color: black;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ui</span>:MenuItem<span style="font-weight: bold; color: black;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ui</span>:Menu<span style="font-weight: bold; color: black;">&gt;</span></span><br />
&nbsp; &nbsp; <br />
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/mx</span>:WindowedApplication<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</div>
</div>
<p></div>
]]></content:encoded>
			<wfw:commentRss>http://jacwright.com/blog/59/using-mxml-for-air-nativemenus/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>AIR Active Record</title>
		<link>http://jacwright.com/blog/55/air-active-record/</link>
		<comments>http://jacwright.com/blog/55/air-active-record/#comments</comments>
		<pubDate>Wed, 19 Dec 2007 18:32:01 +0000</pubDate>
		<dc:creator>Jacob Wright</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://jacwright.com/blog/55/air-active-record/</guid>
		<description><![CDATA[I've been working with AIR quite a bit since my side project is in AIR. I thought it would be pretty cool to create an active record implementation in AIR since I've got one on the server side. I have to use synchronous database connections for it so that everytime I access an object's related [...]]]></description>
			<content:encoded><![CDATA[<p>I've been working with AIR quite a bit since my side project is in AIR. I thought it would be pretty cool to create an active record implementation in AIR since I've got one on the server side.</p>
<p>I have to use synchronous database connections for it so that everytime I access an object's related properties I don't have to use a callback, though it could be refactored to do that. Not my idea of fun though, and after an excellent presentation by Jason Williams, "Working with Persistent Data in AIR," where he showed how fast it was to retrieve data from an AIR database I figured it would be just fine.</p>
<p>Currently I don't have metadata allowing you to define how every property maps to a field in the database, nor do I have many "special case" hooks for this and that. I figured that any AIR app you write will be using a fresh database and not a legacy system. How many desktop apps using a SQLite database will you be updating with AIR and using the same database file? Maybe I'm wrong, but I don't think so.</p>
<p>I also added a piece that you can run which will create and update database tables based off the ActiveRecord object's properties. So you have a nice update mechanism for the database when you update your app using the updater api.</p>
<p>I'll be open-sourcing the code when I have time (isn't that always the case), but you can <a href='http://jacwright.com/blog/wp-content/uploads/2007/12/activerecord.zip' title='Active Record zip files'>get the code now</a>, test it out, and let me know what enhancements you'd like to see. Sorry, no documentation currently. If I like the ideas or they're requested enough I'll be sure to add them in. :)</p>
<p>Oh, and when you unzip it you'll see "flight" is the package <a href="http://xtyler.com">Tyler</a> (my twin) and I are using for our projects. It started when he and <a href="http://flashextensions.com">Rob Taylor</a> started a component set in AS2 under the name but AS3 and Flex 2 came out and they never finished. Maybe an AS3 set will happen someday.</p>
<p><strong>Update:</strong> <a title="AIR Active Record is Open Sourced" href="http://jacwright.com/blog/79/air-activerecord-is-open-source/">AIR Active Record is open sourced</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jacwright.com/blog/55/air-active-record/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>
