ActionScript: Useful Bits #1


Posted:   |  More posts about ActionScript3

I'm rather new to ActionScript3 (and AIR) though I've done a lot of Javascript in the past. In fact, I'm so new I wasn't aware until a week ago that ActionScript had evolved so much since I first checked it out when AIR was in its first beta. I was impressed to see that it is now a "real" language. Anyway, following are some random notes covering useful features I've stumbled over, as a reference for myself.

String Operations

The String class is okay, but still feels a bit clunky (compared to strings in Python) for your basic wet work. There are a few utility routines buried in different places that look useful.

Package mx.utils.StringUtil has a few goodies, including:

  • restrict() to strip out unwanted characters (could also use a regex)
  • substitute() does what it says, like %s in C and various techniques in Python
  • trim() removes leading and trailing whitespace. What, they couldn't put this in the base class?!

Debugging

  • mx.utils.ObjectUtil.toString() gives a great debug dump of any object, and the class has a bunch of other useful functions like dateCompare() and copy() and clone() (though it's unclear to me what's different about the latter two).
  • flash.utils.describeType() barfs back an XML representation of an object, with signatures for all methods, properties, etc.
  • flash.utils also has getDefinitionByName() for retrieving classes by name and getQualifiedClassName() for retrieving names (String) of classes.
Comments powered by Disqus