The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 2 of 2

Thread: A gotoAndStop() Revelation/Explanation [on Flash Frames]

  1. #1

    A gotoAndStop() Revelation/Explanation [on Flash Frames]

    I was curious to how gotoAndStop really functioned, so I ran a few tests. Results are highlighted for easy skim reading.

    On each frame, I placed a trace statement, saying which frame is currently displaying.

    Then, I messed around putting different kinds of code on frame 1.

    Example #1
    Code:
    stop();
    gotoAndStop(5);
    trace("I'm still on frame 1, dude!");
    Output
    Code:
    I'm still on frame 1, dude!
    Frame 5, and feeling jive!
    Now, logically, you should jump to frame 5 before you enter frame 1, but alas, Flash is not as logical.

    First, Flash finishes whatever code it needs on frame 1 (or the frame that called the gotoAndStop()
    Then, Flash jumps to whatever frame you told it to go to



    This got me thinking... What would Flash do if you told it to go to a certain frame, but since it will finish running all functions for that frame, what if in the rest of that code, you told it to go elsewhere?

    Example #2
    Code:
    stop();
    gotoAndStop(5);
    gotoAndStop(3);
    trace("I'm still on frame 1, dude!");
    Output
    Code:
    I'm still on frame 1, dude!
    Frame 3, baby yeah!
    If Flash gets more than one "go to frame xx" on each frame, it only jumps to the last frame it was instructed to go to.


    If anyone has ever decompiled a SWF (I haven't yet, but it is covered in a very interesting gotoAndLearn tutorial ), you will notice that all the Flash compiler does is add functions to specific frames using the not so commontly known "addFrameScript" function. For example, the above code I wrote would automatically compile to (comments added by me):
    Code:
    package HelloWorld_fla
    {
    
       import flash.display.*;
       
       public class MainTimeline extends MovieClip
       {
          public function MainTimeline()
          {
             addFrameScript(0, frame1); //Remember that really begins numbering at 0, so frame 1 is 0 etc.
             addFrameScript(1, frame2);
             addFrameScript(2, frame3);
             addFrameScript(3, frame4);
             addFrameScript(4, frame5);
          }
    
          function frame1()
          {
             stop();
             gotoAndStop(5);
             gotoAndStop(3);
             trace("I'm still on frame 1, dude!");
          }
    
          function frame2()
          {
             trace("Terrible frame 2...");
          }
    
          function frame3()
          {
             trace("Frame 3, baby yeah!");
          }
    
          function frame4()
          {
             trace("Have I been on this frame b4?");
          }
    
          function frame5()
          {
             trace("Frame 5, and feeling jive!");
          }
             
    }

    I hope this research has helped someone out there understand the illogical logic of AS3.

    Does anyone else have any comments or thoughts they have noticed regarding the frame system of Flash?

  2. #2
    Note that there were a lot of changes between Flash Player 9 and Flash Player 10, so depending on the publish target, some of these results may vary.

    Additionally, frame scripts behave differently than other scripts. Specifically, frame scripts are not allowed to change their own frames before they, themselves, complete. This is contrary to AS2. Other scripts, however, can control timelines and have those frames change before they themselves change.

    Some more info on addFrameScript can also be found in the AS3 tip of the day thread.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012