Action Instruction Example - "GotoFrame"

This section provides a tutorial example on how to use 'gotoFrame' and 'Play' Action instructions to jump backward in the timeline to creating a loop of frames.

Actions are very useful in creating Flash applications. Let's learn 2 most commonly used action instructions:

With these 2 actions, we can easily build a Flash application that repeat some frames in loop. Here is my example, written in SWFTools script, ping_pong.sc:

#- ping_pong.sc
#- Copyright (c) 2014 by Dr. Herong Yang, herongyang.com
#
.flash bbox=300x100 background=gray fps=6
.box ball color=black fill=yellow width=10 height=10

.frame 1
   .put ball x=0 y=0

.frame 2
   .del ball
   .put ball x=10 y=45

.frame 3
   .del ball
   .put ball x=145 y=20

.frame 4
   .del ball
   .put ball x=280 y=45

.frame 5
   .action:
      gotoFrame(1); // index 1 = #2
      play();
   .end

.end

Notes on this example code:

If we compile the code and dump the SWF file, we will see:

C:\herong>\local\SWFTools\swfc -o ping_pong.swf ping_pong.sc

C:\herong>\local\SWFTools\swfdump --full ping_pong.swf
[HEADER]   File version: 6
[HEADER]   File is zlib compressed. Ratio: 80%
[HEADER]   File size: 174
[HEADER]   Frame rate: 6.000000
[HEADER]   Frame count: 5
[HEADER]   Movie width: 300.00
[HEADER]   Movie height: 100.00
[009]    3 SETBACKGROUNDCOLOR (be/be/be)
[020]   33 DEFINESHAPE3 defines id 0001
            | fillstyles(01)        linestyles(01)
            | 1 ) SOLID ffff00ff    1 ) 0.00 000000ff
            |
            | fill: 01/00 line:01 - moveTo 0.00 0.00
            | fill: 01/00 line:01 - lineTo 10.00 0.00
            | fill: 01/00 line:01 - lineTo 10.00 10.00
            | fill: 01/00 line:01 - lineTo 0.00 10.00
            | fill: 01/00 line:01 - lineTo 0.00 0.00
            |
[028]    7 NAMECHARACTER adds information to id 0001 "ball"
[038]    9 EXPORTASSETS
           exports 0001 as "ball"

[01a]   10 PLACEOBJECT2 places id 0001 at depth 0001 name "ball"
[001]    0 SHOWFRAME 1 (00:00:00,000)

[01c]    2 REMOVEOBJECT2 removes object from depth 0001
[01a]   14 PLACEOBJECT2 places id 0001 at depth 0002 name "ball"
            | Matrix
            | 1.000 0.000  10.00
            | 0.000 1.000  45.00
[001]    0 SHOWFRAME 2 (00:00:00,167)
[01c]    2 REMOVEOBJECT2 removes object from depth 0002
[01a]   15 PLACEOBJECT2 places id 0001 at depth 0003 name "ball"
            | Matrix
            | 1.000 0.000 145.00
            | 0.000 1.000  20.00
[001]    0 SHOWFRAME 3 (00:00:00,333)
[01c]    2 REMOVEOBJECT2 removes object from depth 0003
[01a]   15 PLACEOBJECT2 places id 0001 at depth 0004 name "ball"
            | Matrix
            | 1.000 0.000 280.00
            | 0.000 1.000  45.00
[001]    0 SHOWFRAME 4 (00:00:00,500)
[00c]    7 DOACTION
            (    2 bytes) action: GotoFrame 1
            (    0 bytes) action: Play
            (    0 bytes) action: End
[001]    0 SHOWFRAME 5 (00:00:00,667)
[000]    0 END

Notice that there are 3 Action instructions are embedded in the "DOACTION" tag. Play ping_pong.swf. It should work:

C:\herong>\local\bin\flashplayer_13_sa ping_pong.swf

Table of Contents

 About This Book

 Introduction of Adobe Flash

 Adobe Flash Player Plugin for Firefox

 Adobe Flash Player Plugin for Chrome

 Adobe Flash Player Plugin for Safari

 Adobe Flash Player ActiveX for IE

 Using "object" Elements for Flash Files

 Using "embed" Elements for Flash Files

 "mp3player" - MP3 Music Player

 SWFObject - Hidding "object" behind JavaScript

 Flash Player Projector

 SWFTools - SWF File Manipulation Tools

 SWFC Script to Generate Flash SWF Files

 ActionScript Embedded in SWFC Script

 AS3Compile - ActionScript 3 Compiler

 Adobe Flex SDK 4

 SWF File Structure and Tags

SWF File Processing Rules

 Flash Player Lifecycle - Timeline and Frame Rate

 SWF Tag Process Flow - SHOWFRAME Synchronization

 SWF Player Lifecycle Example

 Showing SWF Tag Details - "swfdump --full"

 Flash Player Supports Dynamic Actions

Action Instruction Example - "GotoFrame"

 Creating Display Objects with Action Instructions

 More Action Instructions and Less SWF Tags

 SWF Files for Video and Audio Streams

 Outdated Tutorials

 References

 Full Version in PDF/EPUB