June 20th 2011

Create Flex 4.5.* API docs for offline view on Mac OS X

Even today it seems to be difficult to find a downloadable version of the Flex 4.5 SDK API docs. However, it turned out that it is not that difficult to create a local copy of the API docs using ant.

All you need is a copy of a Flex 4.5 SDKant and a bit of courage to deal with the Terminal.

If you are not in a do-it-yourself kind of mood, you can download the Flex 4.5.1 API docs.

Basic Setup

First of all, if you haven’t already, grab a copy of the Flex 4.5 SDK and unzip it.

To install the sdk for use in Adobe Flash Builder, move the sdk folder to the sdks folder of your Flash Builder installation …

… and rename it to something more meaningful like 4.5.0.

Open the Terminal application (using Spotlight or whatever you prefer). In the Terminal window type: cd followed by a blank space.

Next, open the 4.5.0 folder, drag the asdoc folder to the Terminal and hit Return.

Now that we are in the right place, we are ready to build the docs. Type the following command in the terminal window:

ant -DFLEX_HOME=../ -lib ../ant/lib/flexTasks.jar -f build.xml

Please note that the process to build the API docs takes some time (almost 7 minutes on my MBP).

If you get an error like:

-bash: ant: command not found

you need to install ant first. The easiest way to get ant running on your Mac is to install Xcode.

Upon a sucessful build you will notice a new folder called asdoc-output within your sdk folder.

Double click the all-classes.html file to open it in the browser.

That’s it, create a bookmark for the page and you’re ready to browse the API docs …

OR you make your Flex developer life even easier and read on …

Advanced Setup using Quicksilver

Quicksilver is an excellent alternative to Mac OS X builtin Spotlight feature. Basically it does the same as Spotlight, but one of the additional features of Quicksilver is the ability to index HTML links within files.

As you might guess, this comes in very handy to have the API docs at your fingertips.

Obviously you need to install Quicksilver.Some introductory information about Quicksilver is available here.

Next, we need to convert the relative links in all-classes.htmlto absolute file links that open in the browser.Meaning links like this one …

<a title="mx.containers.Accordion" href="mx/containers/Accordion.html">Accordion</a>

… should look like this.

<a title="mx.containers.Accordion" href="file:///Applications/Adobe%20Flash%20Builder%204.5/sdks/4.5.0/asdoc-output/mx/containers/Accordion.html">Accordion</a>

I created a Perl script to do this …

#!/usr/bin/perl -w
use strict;
use File::Basename;
my $FILE = $ARGV[0];
my ($FILENAME, $PATH, $SUFFIX) = fileparse($FILE, qr/\.[^.]*/);
exit 0 if $SUFFIX !~ m/\.html/;
exit 0 unless( -r $FILE &amp;&amp; -w _ &amp;&amp; -f _ );
my $FILE_PATH_PREFIX = 'file://';
my $CLASS_LINKS_REGEX = qr/href="(.+\.(html|css))"/;
my @NEW_LINES = ();
$PATH =~ s/\s/%20/g;
open(FILE, "+&lt; $FILE") or die "can't open $FILE: $!";
while (defined(my $line = ) ) {
    if ($line =~ m/$CLASS_LINKS_REGEX/ ) {
	    my $org = $1;
	    my $new = $FILE_PATH_PREFIX.$PATH.$1;
     	    $line =~ s/$org/$new/;
     push(@NEW_LINES, $line);
open(FILE, "&gt; $FILE") or die "can't open $FILE: $!";

… and packed it as an Automator application:

Drop your all-classes.html file on the application and you’re done.

Now we need to tell Quicksilver to index the file with its content:Open the Quicksilver preferences and select Catalog.

Select the Custom section, add a new File & Folder Scanner

… and select your prepared all-classes.html file.

To include the HTML links in the index, open the info (marked green ) drawer, select HTML Links from the Include Contents drop-down menu and hit the refresh button (marked red).

You should notice a markable increase of the indexed elements for your all-classes.html entry.

Here we go – the API docs at your fingertips. Open Quicksilver and type, for example, Accord. Select the Accordion entry and you get the API for the Accordion class.

I hope everything went well. If not, please leave a comment so that I can try to assist.

Leave a Reply