Wednesday, July 25, 2007

Emacs modes for Flex

  • Emacs modes for Flex:
    • XML: nXML-mode for Emacs from James Clark Using Emacs for XML documents
    • Actionscript: actionscript-mode.el for editing actionscript files in emacs.
    • At least right now it seems you want this xml mode and this actionscript-mode.el.
    • Then, add
      (setq auto-mode-alist (append (list
       '("\\.as\\'"   . actionscript-mode)
       '("\\.\\(xml\\|xsl\\|rng\\|xhtml\\|mxml\\)\\'" . nxml-mode)
       ;; add more modes here
       ) auto-mode-alist))
      
      ;;
      ;; ------------------ Magic for XML Mode ----------------
      ;;
      
      (setq nxml-mode-hook
          '(lambda ()
       (setq tab-width        2
             indent-tabs-mode nil)
             (set-variable 'nxml-child-indent     2)
             (set-variable 'nxml-attribute-indent 2)
             ))
      
    • You can use M-x customize-group RET nxml-highlighting-faces RET to fix your colors the way you like 'em.
  • Setting up asdoc to work within Flex Builder:
    • First, install ant support (Ant is an offshoot of apache and is like Makefile only more betterer.)
    • Then set up a build.xml in your docs/ directory to build the documentation set.
    • I had to modify mine a bit: I added <property name="Templates.dir" location="${FlexSDK.dir}/asdoc/templates/"/> <arg line='-templates-path ${Templates.dir}'/>
    • I also linked the flex home to a no-funny-characters dir:
          ln -s "/Applications/Applications/Adobe Flex Builder 2" /work/ProgramStores/Flex
         cd /work/ProgramStores/Flex
         ln -s "Flex SDK 2" FlexSDK
      Then I exported the location for the asdoc file:
          export FLEX_HOME=/work/ProgramStores/Flex/FlexSDK
      or else I got the error message:
          Exception in thread "main" java.lang.NoClassDefFoundError: Flex

Labels: , , , , , , ,

Tuesday, July 24, 2007

Adobe Flex and Custom Namespace / manifest.xml

Create a file "manifest.xml" and add the following:
<?xml version="1.0"?>
<?componentpackage>
<?!--
URI http://vizsage.com/vzg
namespace gg
package com. vizsage
-->
<component id="widget1" class="com.vizsage.controls.widget1"/>
<component id="widget2" class="com. vizsage.controls.widget2"/>
<?/componentpackage>
Notes:
  • The class part should give the full path (with / turned into .) to the corresponding .as files.
  • You don't need one <component/> for each .as file, just one for each component.
  • The comment part, like most comments (and many goggles), does nothing: all you need is a <component/> for each widget.
  • You don't have to follow the tld.domain.clevername.widgetname format, but it's what all the cool kids are doing. Just make sure the dotted path matches your files' path.
  • The dotted path and the namespace URL don't have anything to do with each other.
  • In fact, the namespace URL is completely made up: it doesn't have to exist; the compiler doesn't look for it; hell, adobe's URL doesn't even exist. It's just a tag for uniquely identifying a namespace. All that matters is that the namespace in your compiler flags and your mxml files match up.

If you use Flex Builder, go into the library project's properties, into the "Library Compiler" field -- add the namespace and manifest.xml into the respective fields. If you use the standalone package, you'll have to add an option for the Component Compiler

-include-namespaces="http://vizsage.com/vzg"  -namespace "http://vizsage.com/vzg" manifest.xml

  • You need to include the namespace and define it
  • The -namespace flag takes two arguments (a namespace and a manifest.xml)
  • The URI here has to match the ns:URL in your .mxml file.
Now your .mxml files (which can be anywhere, and not in that project) start off like
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:gg="http://vizsage.com/vzg"
layout="absolute" width="100%" height="100%"
viewSourceURL="srcview/index.html">
<?!-- ... your mxml file ... -->
  • Make damn sure the xmlns URI matches what you used before. I spent 30 minutes figuring out that http://www.vizsage.com/vzg and http://vizsage.com/vzg weren't the same thing.
  • In Flex Builder 2, you need to get your project's properties, go into "Flex Build Path", then the "Library Path" pane, and "Add SWC" (the one you built with your custom components).
  • For the command-line tools, add a flag
    -library-path+=/abs/olute/path/to/library.swc
    Make sure that's a += there.
  • Either way, applications (as opposed to libraries) don't need any compiler flags or manifest.xml nothing. The library uniquely identifies itself within a namespace, and provides files in the right .com.foo.bar hierarchy. When your .mxml file (asserts a namespace) and (includes the file) everything turns out right.
For more about namespaces see here, with one caveat: I think you're better off using the -load-config+= trick (to just tack on your changes) than hacking stuff into the main flex-config.xml file.

Labels: , , , , , , , ,

How to use exuberant CTAGS with ActionScript and Flex

How to fix CTAGS to work with ActionScript, from the vim-taglist project:
  • ActionScript Add the following lines to the $HOME/.ctags or $HOME/ctags.conf file:
    --langdef=actionscript
    --langmap=actionscript:.as
    --regex-actionscript=/^[ \t]*[(private| public|static) ( \t)]*function[ \t]+([A-Za-z0-9_]+)[ \t]*\(/\1/f, function, functions/
    --regex-actionscript=/^[ \t]*[(public) ( \t)]*function[ \t]+(set|get) [ \t]+([A-Za-z0-9_]+)[ \t]*\(/\1 \2/p,property, properties/
    --regex-actionscript=/^[ \t]*[(private| public|static) ( \t)]*var[ \t]+([A-Za-z0-9_]+)[ \t]*/\1/v,variable, variables/
    --regex-actionscript=/.*\.prototype \.([A-Za-z0-9 ]+)=([ \t]?)function( [ \t]?)*\(/\1/ f,function, functions/
    --regex-actionscript=/^[ \t]*class[ \t]+([A-Za-z0-9_]+)[ \t]*/\1/c,class, classes/
    
    Add the following lines to the ~/.vimrc or $HOME\_vimrc file:
    " actionscript language
    let tlist_actionscript_settings = 'actionscript;c:class;f:method;p:property;v:variable'
    
I actually just add these lines to my maintenance Makefile:
CTAGLANGS = --langdef=actionscript \
--langmap=actionscript:.as \
--regex-actionscript='/^[ \t]*[(private| public|static) ( \t)]*function[\t]+([A-Za-z0-9_]+)[ \t]*\(/\1/f, function, functions/' \
--regex-actionscript='/^[ \t]*[(public) ( \t)]*function[ \t]+(set|get) [ \t]+([A-Za-z0-9_]+)[ \t]*\(/\1 \2/p,property, properties/' \
--regex-actionscript='/^[ \t]*[(private| public|static) ( \t)]*var[  \t]+([A-Za-z0-9_]+)[\t]*/\1/v,variable, variables/' \
--regex-actionscript='/.*\.prototype \.([A-Za-z0-9 ]+)=([ \t]?)function( [  \t]?)*\(/\1/f,function, functions/' \
--regex-actionscript='/^[ \t]*class[ \t]+([A-Za-z0-9_]+)[ \t]*/\1/c,class, classes/'

.PHONY: ctags
ctags:
-rm -f TAGS
find . -name "*.as" -or -name "*.mxml" | ctags -eL - $(CTAGLANGS)
Take off the -e (ctags -L - $(CTAGLANGS)) if you're one of those vi users (I'm being polite because, after all, it's from them comes this tip)

Labels: , , , , , , , ,