AIR Aliases are awesome, and an Aptana Gotcha, that got me

Adobe AIR is really a lot of fun to work with. I am having a great time learning about it and about more advanced JavaScript development with jQuery.

AIR has this really cool AIR Aliases library that you can include in your HTML to help keep your code less verbose. For example, to create an air window might look something like this:


var myWin = new window.runtime.flash.display.NativeWindow();

But with an AIR Alias, it can be shortened to:


var myWin = new air.NativeWindow();

Or if you are using an Encrypted Local Store:


window.runtime.flash.data.EncryptedLocalStore();

Would become:


air.EncryptedLocalStore();

As you can see, this removes a lot of keystrokes, especially over the course of writing a big application.

Aptana

Aptana is an IDE built on top of Eclipse. It can also run as a plugin for Eclipse. I run it as a plugin. Aptana has support for many languages and frameworks including, HTML, CSS, JavaScript, AIR, jQuery, MooTools, Protoype, PHP, etc. There are a LOT. I have been using Aptana for developing my AIR application.

One of the best parts of using a good IDE is code assist. This is the little feature that shows you tag/code options based on what you have typed in. In CFEclipse it looks like this:

Well, Aptana has code assist for AIR (amongst all of its other languages), and it also had code assist for the AIR Aliases. This is awesome. So without Air Aliases, I would have to use code assist like this:

Which would still save a TON of typing and is awesome. But what was even better is that Aptana supports the AIR Aliases:

The Problem

So one day, I am just sitting around, minding my own business, when all of a sudden, from out of nowhere, like I didn't expect it and suddenly, out-of-the-blue, Eclipse crashed. As you can imagine, I was stunned.

After that, part of code assist stopped working.

When I would try to use code assist from within a <script> block in an HTML file, it would look like this:

The code assist was broken. But only for the AIR Aliases, not for other AIR functionality. I tried everything I could think of, reinstalling Eclipse, reinstalling Aptana, removing the AIR plugin and putting it back. All failed. Then finally, I figured out that resetting the Aptana perspective helped. I got the code assist back.

Then I opened an JavaScript file and began to work. WTF?!?! My code assist was gone again. I closed that file and opened the HTML file again, and it worked fine. Dammit! I had only fixed it for HTML files, not for .js file. And I prefer to work with external JS files.

The Gotcha

So it turns out that I did fix all of the problems, I was just not understanding where Aptana was getting the code assist information from. It turns out that it looks at the files that you are including in your HTML and looks for corresponding Code Assist XML files deep in the bowels of the Eclipse folder structure. Well, since you cannot include JavaScript files in an external JavaScript fiel like you can in an HTML file, the AIR Aliases were not working. Soon after that I realized that if I opened up the HTML file that both:

  • Included the AIRAliases.js file AND
  • Included the External JavaScript file on which I was working

That the AIR Alias code assist would work in the external JavaScript file.

I hope someone finds this post helpful. I wish it had existed for me yesterday when I spent 3 hours working on this.

Comments
andy matthews's Gravatar Jason...

You can actually force code hinting by using the "References" tab:

http://screencast.com/t/llvyqrbWj8P

First click the folder with the plus button (to create a new profile), then you can either click the file button to add new JS files, or you can drag them onto your newly created profile folder.
# Posted By andy matthews | 3/18/09 1:36 PM
Jason Dean's Gravatar @Andy, That's really cool. Thanks for the tip. I will have to try that out.
# Posted By Jason Dean | 3/18/09 1:47 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.1. Contact Blog Owner