Tuesday 2007/04/24
3:16 PM

Categories: Flash/Actionscript, TextMate

Enabling Actionscript Help in TextMate

(Update 2007-06-15): James's comment below reminded me of something I found while tinkering with this further: if you set the TMFLASHHELP variable with a full path including your hard drive the third slash in asd.rb is usually unnecessary. I've noted this below.

(Update 2007-05-17): It appears that this may not work with some versions of the asd.rb file, leading to the error described by Aaron in the comments section. I've added my version of asd.rb below)

For AS2 projects I've relied on the excellent Flash help file utility XASH. However, since XASH doesn't support AS3 yet, I revisited the help utility in the TextMate Actionscript bundle to see if I could get it to work. As I understand it, the bundle help scripts read the contents of the help_toc.xml file that sits with the Flash help html pages. It then renders a list of the matches to your selected word to a screen, which when clicked should bring up the web page for that match. Unfortunately,Sometimes this doesn't quite work out of the box. Two simple modifications are needed to get this to work Here's what I tried:

1) The shell variable TMFLASHHELP needs to point to /Volumes[Hard Drive Name]/Library/Application Support/Adobe/Flash CS3/en/Configuration/HelpPanel/Help/ActionScriptLangRefV3. You define this in TextMate > Preferences > Shell Variables. Originally I was setting this to //Library/Application Support... but this necessitated the change to asd.rb detailed below. Note that if you want to get this to work for AS2, you can point TMFLASHHELP to //Users/Shared/Library/Application Support/Macromedia/Flash 8/en/Configuration/HelpPanel/Help/ActionScriptLangRef.

The change below is no longer needed if you use a full path with your hard drive volume included for TMFLASHHELP.

2) The file asd.rb needs to be modified. The file is located in /Applications/TextMate.app/Contents/SharedSupport/Bundles/ActionScript.tmbundle/Support/Tools/asd.rb. To open it you'll need to right-click on the TextMate app, and select "Show Package Contents". Within that window browse to the Actionscript.tmbundle, and again right-click and show the package contents. My copy of asd.rb looks like this:

CODE:
  1. #!/usr/bin/env ruby
  2. #
  3. # Ale Muñoz <ale@bomberstudios.com> - 2006-11-25
  4. # Feel free to use and improve...
  5.  
  6. require "#{ENV["TMSUPPORTPATH"]}/lib/webpreview"
  7. require "rexml/document"
  8.  
  9. WORD    = ENV['TMCURRENTWORD']
  10. HELPDIR  = ENV['TMFLASHHELP']
  11. HELPTOC  = 'helptoc.xml'
  12.  
  13. # Help dir not set?
  14. if !HELPDIR
  15.     puts htmlhead(
  16.         :title => "Error!",
  17.         :subtitle => "Find in ActionScript Dictionary"
  18.     )
  19.     puts <<HEREDOC
  20.     <h1>Search failed for #{WORD}</h1>
  21.     <p>In order for this command to work TextMate needs to know where to find the ActionScript Dictionary index file. This is set in <strong>Preferences> Advanced> Shell Variables</strong>.</p>
  22.     <p>Click <strong>+</strong> and name the variable <code>TMFLASHHELP</code> with value of the path to the directory containing the helptoc.xml file on your system.</p>
  23.     <p>Macromedia have made this tricky and the files arent always in the same place.</p>
  24.     <p>Try clicking the following links:
  25.     <ul>
  26.     <li><a href="txmt://open?url=file:///Users/Shared/Library/Application Support/Macromedia/Flash 8/en/Configuration/HelpPanel/Help/ActionScriptLangRef/helptoc.xml">//Users/Shared/Library/Application Support/Macromedia/Flash 8/en/Configuration/HelpPanel/Help/ActionScriptLangRef</a></li>
  27.     <li><a href="txmt://open?url=file:///Library/Application Support/Adobe/Flash CS3/en/Configuration/HelpPanel/Help/ActionScriptLangRefV3/helptoc.xml">//Library/Application Support/Adobe/Flash CS3/en/Configuration/HelpPanel/Help/ActionScriptLangRefV3</a></li>
  28.     <li><a href="txmt://open?url=file:///Users/Shared/Library/Application Support/Macromedia/Flash MX 2004/en/Configuration/HelpPanel/Help/ActionScriptLangRef/helptoc.xml">//Users/Shared/Library/Application Support/Macromedia/Flash MX 2004/en/Configuration/HelpPanel/Help/ActionScriptLangRef</a></li>
  29.     <li><a href="txmt://open?url=file:///Applications/Macromedia Flash MX 2004/First Run/HelpPanel/Help/ActionScriptDictionary">/Applications/Macromedia Flash MX 2004/First Run/HelpPanel/Help/ActionScriptDictionary</a></li>
  30.     </ul>
  31.     <p>If any of the links work (TextMate will open the helptoc.xml file) then copy and paste the link, omitting the /helptoc.xml on the end, to the path of the shell variable.
  32. HEREDOC
  33.     htmlfooter
  34. else
  35.  
  36.     # Open TOC...
  37.     toclines = IO.readlines(HELPDIR + "/" + HELPTOC)
  38.  
  39.     # ...find matching lines...
  40.     searchresults = []
  41.     toclines.each do |line|
  42.         searchresults <<line.strip if line[/name=\"#{WORD}/]
  43.     end
  44.     puts htmlhead( :title => "Documentation for ‘#{WORD}", :subtitle => "ActionScript Dictionary" )
  45.     # ...parse results for links...
  46.     links = []
  47.     puts "<ul>"
  48.     searchresults.each do |line|
  49.         xmlline = REXML::Document.new(line)
  50.         puts "<li><a href=\"tm-file:///#{HELPDIR}/#{xmlline.root.attributes['href']}\">#{xmlline.root.attributes['name']}</a></li>"
  51.     end
  52.     puts "</ul>"
  53.  
  54.     # ...or display error if no matches
  55.     puts "No results :(" if searchresults.size == 0
  56.  
  57.     htmlfooter
  58.  
  59. end

Once you have asd.rb open, you need to make one small change. Line 52 builds the url(s) to the help file html page(s). Add an extra slash to the "tm-file:" prefix. It should now read "tm-file:///" instead of "tm-file://". Without this fix, you'll get a listing of matches to your selected word, but the link won't work.

Save asd.rb, rRestart TextMate, and you should now be able to highlight a word in your code and hit control-H to look for that word in the Flash help files. For example, try highlighting "MovieClip". You should get a listing for both the MovieClip class, and the MovieClip() constructor.

One quirk of the bundle's reliance on the help_toc.xml file is that the words show up twice in the xml, and thus you'll see the listing of matches to your word twice. Still, it's a small price to pay for a quicker help lookup than the IDE's sluggish help panel.


Responses


aaron

Wednesday 2007/05/16 5:44 PM

hey there, any idea shy I get this error? 2007-05-17 07:43:05.193 defaults[4384] The domain/default pair of (com.macromates.textmate.actionscript, FlashDocumentationPath) does not exist /Applications/TextMate.app/Contents/SharedSupport/Bundles/ActionScript.tmbundle/Support/Tools/asd.rb:31: undefined local variable or method `help_dir' for main:Object (NameError)


ds

Thursday 2007/05/17 9:05 AM

I haven’t seen that error before, but it looks like the asd.rb script can’t find the directory for the help TOC. I would check the path set in TMFLASHHELP and see if it a) exists, and b) points correctly to a directory that contains the help_toc.xml file. The path I set points to the default location for English, but if you installed Flash in a custom directory or with a different language pref you may need to alter the path.


James

Friday 2007/06/15 1:18 AM

Hi, I’m using Textmate 1.5.5(1383) and getting AS2 help. I didn’t have to change “tm-file://” to “tm-file:///”. The link works for me without any problems. I did have to set the TMFLASHHELP variable.


ds

Friday 2007/06/15 8:20 AM

After tinkering with this for a while I found that fully qualifying the TMFLASHHELP to include the volume name (/Volumes[Hard Drive Name]/Library/Application Support ….) seems to negate the need for the third slash. It is something I still recommend that people try – I’ve run into three installs that didn’t work until I did this.


robert

Tuesday 2008/07/22 7:50 PM

This is cool, big help to have help docs like in flash IDE and Flex Builder. Does anyone know if a code hint is built in for textmate?


ds

Thursday 2008/07/24 4:12 PM

There’s no code hinting built-in for Flash in TextMate. You get lots of snippets and of course the text string autocompletion works pretty well. I’ve switched over to FDT for large-scale projects because it handles project-wide hinting and refactoring so well. Although from a pure text editing standpoint TextMate is still more efficient, so I use it for quick editing tasks.


andré felipe

Sunday 2009/01/25 4:03 PM

Does anyone knows how to have the help access (ctrl+h) work with CS4??

I switched over CS4 and uninstalled CS3 and it stop working. Obviously I tried to change the path to many places, but no success.


ds

Sunday 2009/01/25 4:11 PM

André: Unfortunately I haven’t upgraded to CS4 yet – I’ll have to update this when I do.


micmac

Monday 2009/02/09 6:24 PM

andré: CS4 doesn’t replace the help files (ActionScriptLangRefV3) erased by the CS3 uninstaller. But it is downloadable at http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3.zip Just place it anywhere and change the TMFLASHHELP path.


ds

Monday 2009/02/09 6:27 PM

micmac: Thanks for posting that link.


micmac

Monday 2009/02/09 6:37 PM


andré felipe

Thursday 2009/02/12 3:25 PM

great micmac, thanks

still I couldn’t make it work, maybe my actionscript bundle is somewhat corrupt. I trying a few things but still no success

If you know any way to do a “master” restore on the application let me know

best!


Nicholas

Sunday 2011/02/06 1:31 AM

So for Textmate Version 1.5.10 (1616) and Flash CS5 I couldn’t get this to work at all, so I just created one of the old paths that it already looks for from CS3 and put mimac’s first docs link content into it and now it finally works.


ds

Monday 2011/02/07 1:17 PM

Nicolas: Good to know. I’ve long since stopped working in TextMate for Actionscript (now using FDT). I still use it for general HTML/CSS/PHP development, though, because the core editing features are so good.


Leave a Response