Donate to protect them directly or help international organizations.
Working with types in AS3
January 24th, 2008
ActionScript 3 is strong-typed, which is great to detect possible errors at compile-time. Here are a few tips for working with types.
Type wildcard
var someVar:*;
This is not recommended (can cause runtime errors) but is possible. I suggest using a common parent (DisplayObject, for example) whenever possible.
Type checking
if (someVar is MovieClip) {}
This is most useful. Example: getting the list of MovieClip children from a parent MovieClip (you don't want shapes and all). This line might prevent the whole app from blowing up in your face.
Type casting
var item:Object = ComboBox(event.currentTarget).selectedItem;
This will prevent type-mismatch complile errors. The same applies to simple types, such as int and uint.
Previous: Great icons from iconaholic.com Next: AS3 and Runtime Sharing