More Action Instructions and Less SWF Tags

This section provides a tutorial example that uses action instructions to do almost everything without using SWF definition tags and display list control tags.

If love script programing, we can use more action instructions and less SWF tags. Here is another SWFTools script example, ping_pong_enhanced.sc:

#- ping_pong_enhanced.sc
#- Copyright (c) 2014 by Dr. Herong Yang, herongyang.com
#
.flash bbox=300x100 background=gray fps=6

.frame 1
   .action:
      this.n = 0;
      createTextField("caption", 0, 10, 75, 100, 20);

      createEmptyMovieClip("ball", 1);
      ball.beginFill(0xFFFF00);
      ball.moveTo(0, 0);
      ball.lineTo(10, 0);
      ball.lineTo(10, 10);
      ball.lineTo(0, 10);
      ball.lineTo(0, 0);
      ball.endFill();
   .end

.frame 2
   .action:
      _root.n = this.n + 1; // _root = this
      caption.text = "Loop: "+this.n;
      ball._x=10;
      ball._y=45;
   .end

.frame 3
   .action:
      ball._x=145;
      ball._y=20;
   .end

.frame 4
   .action:
      ball._x=280;
      ball._y=45;
   .end

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

.end

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

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

C:\herong>\local\SWFTools\swfdump --full ping_pong_enhanced.swf
[HEADER]    File version: 6
[HEADER]    File is zlib compressed. Ratio: 51%
[HEADER]    File size: 653
[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)
[00c]351 DOACTION
         (91 bytes) action: Constantpool(10 entries) String:"this"
         String:"n" String:"caption" String:"createTextField" 
         String:"ball" String:"createEmptyMovieClip" 
         String:"beginFill" String:"moveTo" String:"lineTo" 
         String:"endFill"
         ( 2 bytes) action: Push Lookup:0 ("this")
         ( 0 bytes) action: GetVariable
         ( 7 bytes) action: Push Lookup:1 ("n") int:0
         ( 0 bytes) action: SetMember
         (34 bytes) action: Push int:20 int:100 int:75 int:10 
         int:0 Lookup:2 ("caption") int:6 Lookup:3 ("createTextField")
         ( 0 bytes) action: CallFunction
         ( 0 bytes) action: Pop
         (14 bytes) action: Push int:1 Lookup:4 ("ball") int:2 
         Lookup:5 ("createEmptyMovieClip")
         ( 0 bytes) action: CallFunction
         ( 0 bytes) action: Pop
         (12 bytes) action: Push int:16776960 int:1 Lookup:4 ("ball")

         ( 0 bytes) action: GetVariable
         ( 2 bytes) action: Push Lookup:6 ("beginFill")
         ( 0 bytes) action: CallMethod
         ( 0 bytes) action: Pop
         (17 bytes) action: Push int:0 int:0 int:2 Lookup:4 ("ball")
         ( 0 bytes) action: GetVariable
         ( 2 bytes) action: Push Lookup:7 ("moveTo")
         ( 0 bytes) action: CallMethod
         ( 0 bytes) action: Pop
         (17 bytes) action: Push int:0 int:10 int:2 Lookup:4 ("ball")

         ( 0 bytes) action: GetVariable
         ( 2 bytes) action: Push Lookup:8 ("lineTo")
         ( 0 bytes) action: CallMethod
         ( 0 bytes) action: Pop
         (17 bytes) action: Push int:10 int:10 int:2 Lookup:4 ("ball")
         ( 0 bytes) action: GetVariable
         ( 2 bytes) action: Push Lookup:8 ("lineTo")
         ( 0 bytes) action: CallMethod
         ( 0 bytes) action: Pop
         (17 bytes) action: Push int:10 int:0 int:2 Lookup:4 ("ball")

         ( 0 bytes) action: GetVariable
         ( 2 bytes) action: Push Lookup:8 ("lineTo")
         ( 0 bytes) action: CallMethod
         ( 0 bytes) action: Pop
         (17 bytes) action: Push int:0 int:0 int:2 Lookup:4 ("ball")
         ( 0 bytes) action: GetVariable
         ( 2 bytes) action: Push Lookup:8 ("lineTo")
         ( 0 bytes) action: CallMethod
         ( 0 bytes) action: Pop
         ( 7 bytes) action: Push int:0 Lookup:4 ("ball")
         ( 0 bytes) action: GetVariable
         ( 2 bytes) action: Push Lookup:9 ("endFill")
         ( 0 bytes) action: CallMethod
         ( 0 bytes) action: Pop
         ( 0 bytes) action: End
[001]  0 SHOWFRAME 1 (00:00:00,000)
[00c]138 DOACTION
         (46 bytes) action: Constantpool(9 entries) String:"_root" 
         String:"n" String:"this" String:"caption" String:"text" 
         String:"Loop: " String:"ball" String:"_x" String:"_y"
         ( 2 bytes) action: Push Lookup:0 ("_root")
         ( 0 bytes) action: GetVariable
         ( 4 bytes) action: Push Lookup:1 ("n") Lookup:2 ("this")
         ( 0 bytes) action: GetVariable
         ( 2 bytes) action: Push Lookup:1 ("n")
         ( 0 bytes) action: GetMember
         ( 5 bytes) action: Push int:1
         ( 0 bytes) action: Add2
         ( 0 bytes) action: SetMember
         ( 2 bytes) action: Push Lookup:3 ("caption")
         ( 0 bytes) action: GetVariable
         ( 6 bytes) action: Push Lookup:4 ("text") 
         Lookup:5 ("Loop: ") Lookup:2 ("this")
         ( 0 bytes) action: GetVariable
         ( 2 bytes) action: Push Lookup:1 ("n")
         ( 0 bytes) action: GetMember
         ( 0 bytes) action: Add2
         ( 0 bytes) action: SetMember
         ( 2 bytes) action: Push Lookup:6 ("ball")
         ( 0 bytes) action: GetVariable
         ( 7 bytes) action: Push Lookup:7 ("_x") int:10
         ( 0 bytes) action: SetMember
         ( 2 bytes) action: Push Lookup:6 ("ball")
         ( 0 bytes) action: GetVariable
         ( 7 bytes) action: Push Lookup:8 ("_y") int:45
         ( 0 bytes) action: SetMember
         ( 0 bytes) action: End
[001]  0 SHOWFRAME 2 (00:00:00,167)
[00c] 51 DOACTION
         (13 bytes) action: Constantpool(3 entries) String:"ball" 
         String:"_x" String:"_y"
         ( 2 bytes) action: Push Lookup:0 ("ball")
         ( 0 bytes) action: GetVariable
         ( 7 bytes) action: Push Lookup:1 ("_x") int:145
         ( 0 bytes) action: SetMember
         ( 2 bytes) action: Push Lookup:0 ("ball")
         ( 0 bytes) action: GetVariable
         ( 7 bytes) action: Push Lookup:2 ("_y") int:20
         ( 0 bytes) action: SetMember
         ( 0 bytes) action: End
[001]  0 SHOWFRAME 3 (00:00:00,333)
[00c] 51 DOACTION
         (13 bytes) action: Constantpool(3 entries) String:"ball" 
         String:"_x" String:"_y"
         ( 2 bytes) action: Push Lookup:0 ("ball")
         ( 0 bytes) action: GetVariable
         ( 7 bytes) action: Push Lookup:1 ("_x") int:280
         ( 0 bytes) action: SetMember
         ( 2 bytes) action: Push Lookup:0 ("ball")
         ( 0 bytes) action: GetVariable
         ( 7 bytes) action: Push Lookup:2 ("_y") int:45
         ( 0 bytes) action: SetMember
         ( 0 bytes) action: End
[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

As you can see the entire SWF application is done by action instructions. There is no definition tags, display list contract tags and other control tags. See the following high level dump:

C:\herong>\local\SWFTools\swfdump ping_pong_enhanced.swf
[HEADER]        File version: 6
[HEADER]        File is zlib compressed. Ratio: 51%
[HEADER]        File size: 653
[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)
[00c]       351 DOACTION
[001]         0 SHOWFRAME 1 (00:00:00,000)
[00c]       138 DOACTION
[001]         0 SHOWFRAME 2 (00:00:00,167)
[00c]        51 DOACTION
[001]         0 SHOWFRAME 3 (00:00:00,333)
[00c]        51 DOACTION
[001]         0 SHOWFRAME 4 (00:00:00,500)
[00c]         7 DOACTION
[001]         0 SHOWFRAME 5 (00:00:00,667)
[000]         0 END

Play ping_pong_enhanced.swf. It works nicely:

C:\herong>\local\bin\flashplayer_13_sa ping_pong_enhanced.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