The movieclip Datatype

Again let’s revisit another esoteric topic, having mastered the fundamentals of ActionScript. In Chapter 13, we learned that movie clips behave, for the most part, exactly like objects. However, movie clips are not just another class—they are their own distinct datatype. Gary Grossman, the creator of ActionScript, explains the difference between the internal implementation of the movieclip and object datatypes as follows:

Movie clips are implemented separately from objects internally in the Player, although both manifest almost identically in ActionScript. The primary difference lies in the way that they are allocated and deallocated. Regular objects are reference-counted and garbage-collected, whereas the lifetime of movie clips is timeline-controlled or explicitly controlled with the duplicateMovieClip( ) and removeMovieClip( ) functions.

If you declare an array using x = new Array( ) and then set x = null, ActionScript will immediately detect that there are no remaining references to the Array object (i.e., no variables referring to it), and garbage-collect it (i.e., free the memory it used). Periodic mark-and-sweep garbage collection eliminates objects containing circular references. (That is, advanced techniques are used to ensure that memory is freed when two unused objects refer to each other.)

Movie clips don’t behave the same way. They come into and go out of existence depending on the placement of objects on the timeline. If they are created dynamically ...

Get ActionScript: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.