TextMate and Flex 2

I’ve been having a bit of a play with Adobe’s Flex 2 command line compiler. After doing a quick search around the net I found a couple of hints for using it with TextMate. Unfortunately none of them did quite what I wanted, so I built my own. Hopefully it will be useful for others 🙂

TextMate bundle for Flex 2 coding

It adds a new language type for mxml files, a few snippets with mx as the tab trigger and a build command bound to Command-B.  By default it looks for your Flex install in the following places

  1. ~/Flex
  2. ~/flex_sdk_2
  3. /Developer/SDKs/Flex
  4. /Developer/SDKs/flex_sdk_2
  5. /Developer/Applications/Flex
  6. /Developer/Applications/flex_sdk_2
  7. /Applications/Flex
  8. /Applications/flex_sdk_2

Any errors or warnings are displayed in the output window and a click will take you to where the problem is.

Once your Flex app is building successfully it will be opened in Safari, or if you have a script called deploy in the same folder as your mxml file it will be executed instead.

Enjoy 🙂

Join the Conversation

50 Comments

  1. Woa what a nice thing! it rocks!!!!

    But I add this trick to bind at Command-Enter for quick export 🙂
    I was wondering for two things…
    Since you can validate mxml, is it possible to make a quick validate syntax bind at Shift-Control-v just like in php (the result show in tooltip)
    And would it be possible to build the flex app in a different folder than the mxml file?

  2. This is really, really fantastic. Have you contacted Allan Odgaard about merging this with future releases of TextMate? Thank you for sharing — maybe a Mac version of Flex Builder isn’t so important any more.

  3. Daniel,

    Great stuff! I just installed it but I’m getting an error when I try to build. I press command-b and get the following error message:

    Unable to access jarfile /lib/mxmlc.jar

    I have put the flex_sdk_2 folder in my home directory. The file I’m testing is in ~/Projects/flex/hello.mxml

    I can successfully build it from the command line:

    ~/flex_sdk_2/bin/mxmlc ~/Projects/flex/hello.mxml

    This produces hello.swf

    Any ideas?

  4. Dude this is awesome, thanks.

    I have a question about compile time, I have the beta of Flex Builder for the mac and it compiles projects in a couple of seconds while the SDK takes 10-30 seconds which is a looooooooooong time when debugging.

    I know the first time Flex Builder compiles it also takes a while but then uses some kind of caching. Do you know if there’s a way to speed up the SDK compile time?

    thanks again!

  5. Jeff-

    I ran into the same issue. I opened the bundle in Textmate and edited the Build Project Command section. You should see on line 10, “dirs = [”

    I removed the default paths, and inserted my own, “/Applications/Adobe\ Flex\ Builder\ 2\ Beta/Flex\ SDK\ 2/”0.

    Unfortunately, I get a Exception in thread “main” java.lang.NoClassDefFoundError: Flex error. Ugh

    Chris

  6. Here’s a patch to the BuildProject.tmCommand file, which lets it know about the default install paths for the Flex Builder 2 product and lets the user override with a shell environment variable:

    $FLEX_HOME = ENV[“FLEX_HOME”] || “”
    unless File.directory?($FLEX_HOME) then
    dirs = [
    “~/Flex”, “~/flex_sdk_2”,
    “/Developer/SDKs/Flex”, “/Developer/SDKs/flex_sdk_2”,
    “/Developer/Applications/Flex”, “/Developer/Applications/flex_sdk_2”,
    “/Applications/Adobe Flex Builder 2/Flex SDK 2/”,
    “/Applications/Adobe Flex Builder 2 Plug-in/Flex SDK 2/”,
    “/Applications/Flex”, “/Applications/flex_sdk_2”
    ]

    dirs.each do
    |dir|

    if File.directory?(dir)
    $FLEX_HOME = dir
    break
    end
    end
    end

  7. What’s up, D. Fantastic plug in for textmate. However, there is still one issue that hinders me from leaving the Eclipse IDE all together, and that is the matter of linking external libraries. I write a toolset if you will of actions that i use over and over again, and link them externally to whatever project I am working on at the time so I don’t have to continuously rewrite them. In Eclipse, it’s just a simple matter of linking it to the project. However in textmate I have yet to find this crucial ability. Of course there are less elegant ways of getting around this, but I just wanted to post this in the hopes that you have been thinking about it as well. Thanks in advance, dude.

    R.

  8. I have downloaded and installed to Textmate, then manually added in Andrew Shebanow patch. I am still getting NoClassDefFoundErrors

    Exception in thread “main” java.lang.NoClassDefFoundError: Flex

    I have $FLEX_HOME pointing to my extracted SDK and $FLEX_HOME/bin is on my $PATH. Any ideas?

  9. I stumbled across this posting in my search for a free alternative to Flex Builder. Thanks to Textmate and this fantastic bundle I’m well on my way to producing some introductory Flex apps without having to make a $500 investment up front. The snippets included have already helped in streamlining production and I’m looking for even more help by introducing autocomplete functionality. I have an XSD file to pull from and was wondering if anyone knows if there’s a way to incorporate this into Textmate for code hinting MXML files. Any ideas?

  10. There’s a bug in this: when your Flex SDK is in a home dir, and you are using something like “~/Flex” to point at it, the script doesn’t do path-expansion and it can’t find the SDK. The fix is easy though… at the top of the code (line 10) replace this block:

    dirs.each do
    |dir|

    if File.directory?(dir)
    $FLEX_HOME = dir
    break
    end
    end

    with this:

    dirs.each do |dir|
    fulldir = File.expand_path(dir)
    if File.directory?(fulldir)
    $FLEX_HOME = fulldir
    break
    end
    end

    and the “Build” command should work fine.

  11. For some reason, when I compile my test.mxml app with the Textmate bundle, my HTTPService request in my app is never going out. But if I compile it manually from the command line like this ( from the flex2 bin dir ): ./mxmlc ~/Desktop/test.mxml, the HTTPService works fine.. what’s wrong here?

  12. I patch my bundle but always same error
    “Exception in thread “main” java.lang.NoClassDefFoundError: Flex”

    dirs = [
    “~/Flex”, “~/flex_sdk_2”,
    “/Developer/SDKs/Flex”, “/Developer/SDKs/flex_sdk_2”,
    “/Developer/Applications/Flex”, “/Developer/Applications/flex_sdk_2”,
    “/Applications/Adobe Flex Builder 2/Flex SDK 2/”,
    “/Applications/Adobe Flex Builder 2 Plug-in/Flex SDK 2/”,
    “/Applications/Flex”, “/Applications/flex_sdk_2”
    ]

    dirs.each do
    |dir|

    fulldir = File.expand_path(dir)
    if File.directory?(fulldir)
    $FLEX_HOME = fulldir
    break
    end
    end

  13. I’ve tried the above fixes, but I’m still getting the same error as Bolo. The rest of this bundle work really great–thanks for the effort you’ve put into it.

    If anyone found a fix to the proble of not finding the Flex class, I’d love to hear about it.

  14. I was getting the “Exception in thread “main” java.lang.NoClassDefFoundError: Flex” error. I have Flex Builder 2 installed under Applications.

    I found that I could compile my mxml file with the mxmlc compiler in the Flex SDK 2/bin folder, so I munged the Flex bundle like this (hard-coding the path to my Flex install):

    #MXMLC=”java #{VMARGS} -jar #{$FLEX_HOME}/lib/mxmlc.jar”
    MXMLC=”/Applications/Adobe\\ Flex\\ Builder/Flex\\ SDK\\ 2/bin/mxmlc”

    I’m not a Ruby guru, there’s probably some cleaner way to do this. The double-backslashes are needed to escape the spaces in the pathname for the shell.

    Works for me!

  15. excellent work. I am having the same problem as Josh Chaney above, my HTTPService requests are throwing errors. any idea why this would be?

  16. actually, I just noticed that it’s outputting to the same direcotry as the mxml flle…would you know how tochange the output path? (I’d just like to change it to ‘bin’ which is in the same directory that the swf is currently being outputted to).

  17. @Alastair

    The reason that the Flex Builder seems to compile the applications faster than the SDK is because the Builder will compile the project every time you save your MXML file. Then when you hit run, it just loads the already compiled SWF.

  18. @Steve Ametjan

    It may also be the fact that Flex Builder is Java-powered, so the overhead of firing off the compiler (which is Java-based as well) may be reduced (and in fact, on Windows at least, it doesn’t spawn a separate process) inside of FB, while the command-line builds/tearsdown a full process (including Java runtime) each time.

  19. Hey,

    Good work; been trying out TextMate with Ruby/Rails recently and seems a good tool, this looks nice too.

    However, I had the same no class def found error and so changed the top of the script to the following, following a previous comment that didn’t work for me as written:

    #!/usr/bin/env ruby

    $FLEX_HOME = “/Applications/Adobe\\ Flex\\ Builder\\ 2/Flex\\ SDK\\ 2″

    VMARGS=”-Dapplication.home=#{$FLEX_HOME} -Xmx384m -Dsun.io.useCanonCaches=false”

    MXMLC=”#{$FLEX_HOME}/bin/mxmlc”

    Cheers,
    Paul

  20. Hi,

    One thing; if I want to use scripting in the MXML file; as this has to go in a CDATA section, there is none of the formatting you would find in a normal action script file in TextMate. Is there an easy way to combine the formatting so the code in the CDATA section looks like action script and not just a normal CDATA section? This would make things much clearer in the MXML file.

    Obvioulsy I could just move most of the action script to a separate AS file but it would be nice to have the best of both worlds 🙂

    Cheers,
    Paul

  21. Dan, this is an awesome little bundle. Flex Builder runs butt-slow, and it’s great to be able to use TextMate instead.

    @Jeff – thanks a bunch! I couldn’t get it to work without your path fix. Now I can build away.

  22. The JVM startup time is part of the performance hit with compiling with mxmlc, but the biggest issue is that by default mxmlc doesn’t use incremental compilation, and instead tries to recompile every source file in the entire project. Turning on incremental compile usually boosts performance considerably. There’s also the compiler shell which lets you keep building targets over and over from within the same JVM that keeps running.

    http://livedocs.adobe.com/flex/201/html/compilers_123_30.html
    http://labs.adobe.com/wiki/index.php/Flex_Compiler_Shell

  23. “Do you think what we’re doing is wrong?”
    “Of course it’s wrong! It’s illegal!”
    “I’ve never done anything illegal before.”
    “I thought you said you were an accountant!”

    —————————————————————————————————-
    http://bookercaseyww.easyjournal.com

  24. Pingback: SOG knives
  25. Hi Daniel,

    I was using another TM bundle (feel ashamed) and recently discovered yours which is much better. I have a few suggestions / questions to you which I hope you could answer:

    1) Would be cool if you add a new environment variable where to add compiler specific parameters such as target-player, library-path, … Furthermore, maybe just a custom mxmlc args variable or so.

    2) Would be nice to have a build&run command

    3) There’s an issue with directory names with spaces (fcsh won’t work). I have a workaround which consists on cancelling the build, then launch fcsh from project’s directory (manually), and run the first mxmlc command manually just using relative files such as mxmlc -o=MyApp.swf MyApp.as. From this point every build command will work (since compile 1 is used). Would be possible to kind of automate that? Force terminal launch under project’s directory?

    thanks a lot for your excellent work!

    Cheers,
    Edu

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.