I spotted this article describing how to make Ubuntu send mailto: links through Gmail. It’s not wrong exactly, but I wanted to improve upon it a little. I have my own version which requires no external files, and all it needs is that you send your mailto: links through this command…

sh -c "firefox 'https://mail.google.com/mail?view=cm&tf=0&to='$(echo \"\$1\" | sed -e 's/mailto:\(\/\/\)\?//' -e 's/\?/\&/' -e 's/\&subject=/\&su=/I')" custom-mailto-launcher "%s"

On Ubuntu, go to System -> Preferences -> Preferred Applications, change your mail reader to “Custom”, then put this line in. If you use another version of Linux, you’ll have to figure that part out yourself. Keep in mind %s is the variable and firefox is the default browser in my example.

Mine removes the “mailto” part a little better, and makes a hacky attempt to parse the subject/cc/bcc arguments these links sometimes have. Most importantly though, it’s a one-step process.

Debugging Flash on Linux

February 27th, 2007

While the standalone Flash Player on Linux is pretty good, but it kept crashing on me the other day when I tried to use fdb with it. I thought up another solution, and it works surprisingly well. It uses wine with the Windows version of the standalone player as an alternative player for Linux.

First, make sure wine is installed. If you’re using Ubuntu, you’ll need to enable the community maintained (universe) repository in Synaptic in order for it to become available. You should already have the Flex SDK, if not I have more on this in my guide to Flash development on Linux. Create a file called gflashplayer in Flex’s bin folder unless it already exists. If that’s the case then it’s probably your regular debug player. Rename the old one flashplayer-debug and then create the empty file gflashplayer. Open gflashplayer as a text file and write this…

#!/bin/sh
USEWINE=true
if $USEWINE; then
wine $(dirname "$0")/../player/debug/SAFlashPlayer.exe $*
else
$(dirname "$0")/flashplayer-debug $*
fi

Now whenever gflashplayer is run, it will redirect it to the wine-powered instance of SAFlashPlayer.exe. It works for debugging too, at least on my computer (Ubuntu 6.10, wine 0.9.30-0). You may need to configure wine first, try typing winecfg in the terminal and adjust the settings.

I still like the Linux version better, but it’s good to have the alternative ready when you need it. If you want to switch back, change USEWINE=true to USEWINE=false. You’ll need to have the Linux debug player (available here) named flashplayer-debug and located in Flex’s bin folder.

Update: How strange, the wine-powered standalone player is the most stable Flash player I’ve used yet. On Windows it would occasionally be unable to connect to the debugger until I restarted Eclipse, usually related to having to many players open at the same time. On Linux it will crash unexpectedly. Now I can have a dozen debuggers open at the same time with no crashes yet.

This guide isn’t particularly definitive, mostly because right now all the tools needed lack real cohesiveness, paticularly on Unix. This is simply how I pulled everything together to make things work using freely available software.

Step 1: Get Eclipse

Download Eclipse. Put it somewhere. If you’re using Linux, install using it using your favorite package management software. This guide will probably only work if you use 3.2 or above. (NOTE: If you use Ubuntu for this, then at the time of this writing Eclipse 3.2 is only in the “universe” repository, you can enable “universe” using Synaptic)

Step 2: Pull Flex together

Download the Flex 2 SDK. You’ll probably need to sign up for an account. Extract it. Download the Flex Ant Tasks and extract flexTasks.jar (in lib) to lib in your Flex directory.

You’ll need to set up the standalone player so you can debug your swf files. This varies between Operating Systems…

  • Linux: Download the Linux Flash Players and extract the debug player (in standalone/debugger/flashplayer.tar.gz) to bin in your Flex folder. Rename the the debug player (which is named flashplayer) to gflashplayer. You can also install the debug plugin for browsers if you’d like.
  • Windows: Run SAFlashPlayer.exe (in your Flex directory, under player/debug/) and it will register itself as the debug player. There’s also two installers for debug plugin if you care to install them too.
  • OSX: Use SAFlashPlayer.dmg (in your Flex directory under player/debug/) to install the debug player. There’s an installer for debug plugin there too.

Step 3: Create a project

Create a general project in Eclipse and put various Actionscript-related files there. Create a file called build.xml. This will be your Ant build file, and what you’ll use to compile your project. There’s more details on Ant here. Here’s a sample…

<project name="sample" basedir="." default="build">

<property name="FLEX_HOME" value="/path/to/flex"/>
<taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/lib/flexTasks.jar" />
<target name="build" description="Build">

<mxmlc file="example.as" output="bin/example.swf" use-network="false" compiler.optimize="true">

<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<source-path path-element="${FLEX_HOME}/frameworks"/>
<source-path path-element="/path/to/as3-library"/>

</mxmlc>

</target>

</project>

The taskdef entry and the FLEX_HOME variable need to be there in order to use the mxmlc task to compile swf files. On Linux the property use-network="false" mysteriously allows the compiled swf to access files on your computer, without it an error is thrown when you try to access a file

Step 4: Syntax Highlighting (optional)

There is no free Actionscript 3 syntax highlighter, and the only one for Actionscript 2 is poor (sorry guys). Luckily Actionscript resembles heavily resembles Java. Simply associate .as files with the Java Editor in Eclipse (Window->Preferences, then General->Editors->File Associations) and hope nobody notices.

  • To change the formatting (particularly tab width) go to the Formatter (Java->Code Style->Formatter) and toy with the settings until it looks like your preferred coding style.
  • To change the colors go to the Syntax Coloring section (Java->Editor->Syntax Coloring)
  • To prevent Java from making suggestions, go to auto-activation (Java->Editor->Content Assist) and remove any characters in the “Auto activation triggers for Java” section.

Step 5: Compilation

Open the Ant viewer in Eclipse (Window->Show View->Ant) and drag your build.xml file to it. Use it to run build files.

Step 6: Debugging Preparation

You’ll need another target in your build.xml used for creating a secondary swf for debugging.

<mxmlc file="example.as" output="bin/example-debug.swf" use-network="false" incremental="true" debug="true">

Run this target whenever you want to update the debug version of your swf. The debug="true" property needs to be there in order for it to work. Make sure the output/swf file has a different name than your optimized build since this version is purely for debugging and will be slower.

Step 7: Debugging

Open the External Tools window in Eclipse (Run->External Tools->External Tools…). Select “Program” and create a new configuration. Set “Location” to the location of fdb, the Flash debugger (it’s in your Flex directory, under bin). The working directory should be the location of your compiled swf files. The only argument should be the file name of the swf file you’ll be debugging.

Run the external tool configuration you just created (there’s a button for it on the toolbar) whenever you want to debug the swf. When you do a console will open up, and the debugger will start. The Flash Player window will open, but it will remain frozen until you type “continue” in the Eclipse console. All output (trace) will appear in the console. If you familiarize yourself with fdb you can make use of many more features. To stop debugging, type “exit” in the console or just close the player window and terminate fdb.

Javascript is Very Fast?

January 10th, 2007

Apparently my previous post was premature. My world has shattered and I have discovered the single most impressive example of Javascript. Ever. Considering that just this morning the very same event took place (but with Flash) this is one hell of a day.

It’s an emulator. In Javascript. Take a deep breath and let that sink in.

I really wish this guy would switch to Flash. I programmed in Javascript in the old days and it’s really no good for certain things. What those “things” are is vauge, but basically, writing emulators is one of those things. In any case, Flash got there first and FC64 is cooler.