Jon Aquino's Mental Garden

Engineering beautiful software jon aquino labs | personal blog

Friday, June 22, 2007

ActionScript for JavaScript (and Java) Programmers

Tips for JavaScript programmers working on an ActionScript (Flash) project:
  • ActionScript is like JavaScript but adds Java-like classes, interfaces, and packages (namespaces).
  • Most of your code should live outside of the Flash IDE. The only things in the IDE should be graphics received from designers. Convert those graphics into MovieClips and link them to classes that live outside of the IDE.
  • See that timeline across the top? You don't need it - you're writing your code outside of the IDE.
  • MovieClip is a poor name - it should probably be called Panel or Graphic. Every graphic that can be manipulated by ActionScript is a MovieClip.
  • MovieClip objects can define an onEnterFrame() function that is called 12 times a second. Avoid using it - it can slow down your program.
  • Use createMovieClip and createTextField to create new graphics and text programmatically. Use attachMovieClip to grab a graphic from the .fla (i.e. a graphic from your designer).
  • To modify a graphic received from your designer (e.g. to set its instance-variable name), drag it from the Library to the Stage. Afterwards, you can delete it from the Stage - changes are always made to the "master" copy in the Library.
  • Use the Select Unused Items menu item to find graphics in the .fla that aren't being used. Delete them.
  • Use folders (in the "Library") to group related graphics. The IDE won't organize them for you - it doesn't show which graphics depend on which. Use folders to make up for this. For example, in my _PlayButton folder I have graphics named PlayButton, _Play, Button, Button (Hover), and PlayPauseIcon - all used for the Play button.
  • Since you are doing all your ActionScript programming outside of the IDE (right?), you can use your favorite text editor. I prefer jEdit; Flash-specific text editors include SePy and FlashDevelop.
  • Spend an evening skimming the solutions in ActionScript Cookbook. You can read this online at O'Reilly Safari.
  • Delegate and EventDispatcher are handy classes.
  • XRay is a kind of Firebug for Flash, letting you browse the Flash embed at runtime, even while it is running in a browser. Drag it into the IDE. It will add 30kb to your Flash embed. (You can remove it later).
  • You probably want to stick with ActionScript 2 for now, as ActionScript 3 requires Flash 9.
  • In the Flash IDE, open the Movie Explorer window to see what the .fla file contains
  • Use AsUnit to do unit testing.
  • Have two directories: src and lib. src contains your stuff: com/example/...; lib contains 3rd-party stuff: org/bigcrunch/ToolTip, etc. You'll need to add classpaths for these two directories.
  • Don't be surprised if you discover many annoying things about Flash, the Flash IDE, and ActionScript.

0 Comments:

Post a Comment

<< Home