Thanks to Nick, we discovered an error in the document classes that accompany the source code for Chapter 3. The error has been corrected, and the archive has been replaced. This has nothing to do with the book, so this only applies to those early coders who downloaded the Chapter 3 source archive prior to January 12, 2008.
We introduce syntax and concepts early on in a way that allows us to focus closely on the topics themselves, without having to dive immediately into classes. We then use classes more and more as we progress through the chapters.
However, if you already have some experience with classes (or want to start pushing yourself to this ideal early on), we also provide a second copy of all the timeline examples, using document classes instead. This way you can experiment with both approaches and pick the style that suites you best at the outset of the book.
So, none of the timeline examples were affected and, if you only need to think about this if you downloaded the Chapter 3 archive before January 12th.
Thanks Nick!
Print This Post

































Can a person mix a document class with timeline AS3 code in the same Flash Movie?
Thanks.
While it is possible, it’s not recommended. There’s no all-encompassing reason that says it can’t be done, but it’s confusing at best and disastrous at worst. Mixing the two realms can also cause problems that aren’t always easily identifiable. Consider this simple example.
FLA
DOCUMENT CLASS “Main”
import flash.display.MovieClip;
public class Main extends MovieClip {
public function Main() {
trace(”document class”);
}
}
}
The above will work. However, if you do nothing more than change the document class to extend Sprite, instead of MovieClip, you will see this error:
Why? Because the document class takes precedence and Sprites have no frames. As a result, the timeline frame script can’t be added. That’s not clear, however, for a few reasons. First, addFrameScript() is undocumented, so it’s hard to figure out what’s going on. Second, tracing the parent of both the timeline and document class reveals “[object Stage]” in both cases, indicating that they are siblings. So why does the document class require frames?
In overly simplified terms, the document class “replaces the timeline” and the timeline script is being added to the “frame script of the document class.” Even as I write this I cringe at the effectiveness and accuracy of that description, but even the awkwardness of describing what’s going on emphasizes the point. Whenever possible, don’t mix the timeline and document class.