Home > Uncategorized > Working with types in AS3

Working with types in AS3

January 24th, 2008 Leave a comment Go to comments

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.

Tags: ,
  1. No comments yet.
  1. No trackbacks yet.