Tuesday, September 2, 2008

How does Flash Pass Control as it gotoAndPlays frames?

One of the pleasures of working on CLIPS is the chance to work with some top-notch Ontario educators, like Greg Rodrigo of Georgian College. As part of this summer's work, we we trying to figure out how actionscript is executed as control is passed to different frames and the onEnterFrame method is called. Greg created a little test file similar to the following:

Create seven keyframes and put the following code in each frame:
  1. onEnterFrame = function() {
    trace("I am on frame " + _currentframe);
    trace("Frame 1");

  2. gotoAndPlay(4);
    trace("Frame 2");

  3. trace("Frame 3");

  4. trace("Frame 4");

  5. trace("Frame 5");

  6. trace("Frame 6");
    delete onEnterFrame;

  7. stop();
    trace("Frame 7");
So here is what the teacher would ask you to do:
Determine what Flash's output window will contain when this file is tested.
We learned a lot about how Flash operates by trying to make this prediction.

STOP: Try it yourself now.

If that question is too hard or open-ended, here are some other questions that might be simpler:
  1. What will the output be the first time the onEnterFrame method is executed?
  2. Will the first output "Frame 2" occur before or after the first output "Frame 4"?
  3. Why does "I am on frame 5" not appear in the output window? (I am not sure what the answer to this question is, so perhaps it is not simpler.)
Please feel free to leave a comment about the last question.

If you don't feel like typing this in yourself, I have posted the .fla source file.

1 comment:

Ross Isenegger said...

I have posted the contents of the output window in case the answer makes the question more interesting.