Daniel's Stuff

I write code

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 :)

50 comments for “TextMate and Flex 2

  1. October 2, 2006 at 1:53 pm

    Hi Daniel,
    cool! I started to do one myself, but Yours is much better!
    I try to come up with some new ideas…
    -karsten

  2. Michael Wei
    October 9, 2006 at 9:26 pm

    Thanks a lot, Daniel, you did a good job!

  3. Francis Fontaine
    October 18, 2006 at 7:18 am

    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?

  4. Dylan
    October 23, 2006 at 8:03 am

    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.

  5. Mathieu
    October 26, 2006 at 5:04 am

    Thanks so much sir

  6. October 31, 2006 at 8:52 am

    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?

  7. October 31, 2006 at 10:36 am

    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!

  8. November 23, 2006 at 3:44 pm

    oh bless you and your fine little tmbundle of joy. people like you make coding worth doing.

  9. Chris Griffith
    November 29, 2006 at 12:08 pm

    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

  10. December 8, 2006 at 11:54 am

    yes! thanks indeed, its a great way to use textmate good job!

  11. February 23, 2007 at 9:38 am

    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

  12. Niket
    February 23, 2007 at 12:18 pm

    Thank! Good Work

  13. karsten
    February 25, 2007 at 3:05 pm

    Nice work, thx!!!
    Any plans to use fcsh?
    I don’t know how to communicate with it, though :(

  14. Ro
    March 19, 2007 at 11:39 am

    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.

  15. morganusvitus
    April 5, 2007 at 7:29 am

    The site looks great ! Thanks for all your help ( past, present and future !)

  16. April 6, 2007 at 11:26 am

    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?

  17. Chris
    April 11, 2007 at 8:13 pm

    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?

  18. Jeff
    April 17, 2007 at 9:38 am

    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.

  19. Josh Chaney
    May 4, 2007 at 2:05 pm

    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?

  20. Bolo
    May 11, 2007 at 1:19 pm

    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

  21. June 2, 2007 at 9:41 pm

    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.

  22. Greg Jorgensen
    June 4, 2007 at 12:58 pm

    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!

  23. August 6, 2007 at 9:39 am

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

  24. August 6, 2007 at 10:26 am

    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).

  25. August 13, 2007 at 3:37 pm

    @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.

  26. August 28, 2007 at 10:35 am

    @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.

  27. Paul McMillan
    August 30, 2007 at 6:04 am

    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

  28. Paul McMillan
    August 31, 2007 at 4:35 am

    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

  29. Hero
    November 8, 2007 at 7:57 am

  30. Halo
    November 12, 2007 at 2:37 pm


    [URL=][/URL]

  31. November 21, 2007 at 11:27 am

    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.

  32. December 3, 2007 at 11:15 am

    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

  33. Mawassuct
    May 14, 2008 at 3:34 pm

    “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

  34. May 23, 2008 at 4:45 pm
  35. May 23, 2008 at 7:20 pm
  36. May 30, 2008 at 2:47 am
  37. Pingback: SOG knives
  38. August 31, 2008 at 7:00 pm

    Hi!,

  39. Edu
    September 7, 2009 at 3:52 am

    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

  40. November 23, 2009 at 11:53 pm

    hi
    http://annlistens.com/ – alprazolam xanax
    Sudden discontinuation may lead to seizures.
    alprazolam mg
    Taking it in the morning will help you all day long.
    xanax online
    Psychological and/or physical dependence can manifest event if Alprazolam is used as recommended making it very difficult to discontinue treatment.

  41. September 19, 2014 at 10:41 am

    This guided tour goes through the historic Fells Point neighborhood where sailors,
    sea captains and immigrants lived in the 18th Century Marityime community.
    Each Dubai Dhow cruise operator has their own choice of caterer (this
    could be a hotel or a restaurant) and different entertainment options, but cruise routes are very similar, unless of course taken in a different location. The Captain Hook dinner Cruise includes: buffet dinner served onboard,
    red and white domestic wine served during dinner, continuous entertainment by
    the ship’s crew, domestic open bar on board, disco music
    for dancing and more.

Leave a Reply

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