Click here to Skip to main content
Click here to Skip to main content

SWFLIB - a free Flash authoring library

, 18 Jul 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
An article on a free Flash authoring library.


This article is about a small SWF authoring library written in C++. It can be used from any desktop application to generate Flash animations at run-time. In this release, the library can generate SWF version 3 movies, without sounds and text. This release has extended SWF tag support to cover buttons, actions, and sprites. Since this is an a experimental project, the future releases will be extended with additional functionality. For now, you are able to generate any kind of animation from the C++ source code and test it in any browser that supports Flash. The goal here is not to chase the latest SWF file format specification, but to enable developers to test this tool in their projects.


Similar SWF authoring tools could be found on the Internet but with different support for generating Flash animations.

Using the code

You can use this library by downloading the SWFLIB project file and recompiling it. The project you use the library in must include the library header files and link to the swflib.lib file. The possible problem would be default project linking to the LIBCD.LIB library in the Project->Settings... and then the Link tab. The solution would be to select Input from the Category combo-box and to write the library name (LIBCD.LIB) in the Ignore section. It has worked for me in the TestProject that can be found in the download section on this page.

Generating a simple Flash movie would look like this:

#include "SWFMovie.h"

SIZE_F movieSize = {400, 400};
int frameRate = 12;
CSWFMovie swfMovie;

// Open new .SWF file
swfMovie.OpenSWFFile("Sample.swf", movieSize, frameRate);

// Define a simple shape
USHORT depth = 1;
RECT_F shapeRect = {0, 0, 200, 200};
CSWFShape shape(nID, shapeRect, depth);
int lineWidth = 2;
SWF_RGBA lineColor = {255, 0, 0, 255};
shape.AddLineStyle(lineWidth, lineColor);
SWF_RGBA fillColor = {0, 0, 255, 255};
shape.AddLineSegment(100, 0);
shape.AddLineSegment(0, 100);
shape.AddLineSegment(-100, 0);
shape.AddLineSegment(0, -100);
swfMovie.AddShape(&shape, shape.m_Depth, true);

// Close .SWF file

Please understand that it is not possible to describe the whole functionality of the SWFLIB library using a single web page. You can find the SWFLIB Programmers Reference document in the download section, with the complete SWFLIB library specification.

Very important note

This library is just a thin wrapper around SWF tags, so don't expect final solutions. You'll have to build them using your mathematical skills and imagination. The animations are all about mathematical transformations, so you need 2D math tricks in order to get interesting effects. But don't be sad, with some practice, you'll make it for sure.

Points of interest

Working on this project was very exciting, and the future releases will increase the functionality of this library. So far, there are no noticed memory leaks, but if you detect one, please report it.


SWFLIB.LIB v1.1, release date - July 4, 2006

  • Buttons
  • SWF 3 Actions
  • Sprites

SWFLIB.LIB v1.0, release date - June 26, 2006

  • Custom shapes
  • Morphing shapes
  • JPEG file support
  • Line and fill style definition
  • Geometrical transformations
  • Color transformations


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior) Elektromehanika d.o.o. Nis
Serbia Serbia
He has a master degree in Computer Science at Faculty of Electronics in Nis (Serbia), and works as a C++/C# application developer for Windows platforms since 2001. He likes traveling, reading and meeting new people and cultures.

Comments and Discussions

GeneralMy vote of 5 PinmemberSXJIAKE25-May-13 4:45 
QuestionCSWFButton Help PinmemberMember 88861093-Oct-12 14:26 
BugRotation Problem!!! PinmemberSimonCommon24-Dec-11 2:22 
GeneralI couldnt add more frame into the swf movie [modified] Pinmemberrootlife4-Nov-09 20:40 
// Movie Params
SIZE_F movie_size = {300.0f, 260.0f};
int framerate = 1;

CSWFMovie m_SWFMovie;
// Create Basic Movie
m_SWFMovie.OpenSWFFile("SWFTest.swf", movie_size, framerate);
// Give it a background colour
SWF_RGB bgColor = {255, 0, 0};

float bmp_width = 256.0f; float bmp_height = 256.0f;

// Define shapes
RECT_F shapeRect = {0.0f, 0.0f, 300.0f, 260.0f};
SWF_RGBA lineColor = {0, 0, 0, 255};
RECT_F bitmapRect = {0.0f, 0.0f, bmp_width, bmp_height}; // size of the bitmap
RECT_F clipRect = shapeRect; // fill the full rectangle
LPTSTR pFileName[4]={ "bm128.jpg", "bm130.jpg" ,"bm129.jpg" ,"bm131.jpg" };

static CSWFBitmap bmp[4]={ CSWFBitmap(1, (UCHAR*)(pFileName[0]) ) ,\
CSWFBitmap(2, (UCHAR*)(pFileName[1]) ),\
CSWFBitmap(3, (UCHAR*)"bm129.jpg" ), \
CSWFBitmap(4, (UCHAR*)(pFileName[3]) ) };
static CSWFShape shape[4]={ CSWFShape (3, shapeRect, 10), CSWFShape (4, shapeRect, 11), \
CSWFShape (5, shapeRect, 12), CSWFShape (6, shapeRect, 13) };
for(int i=0;i<4;i++)
// Define bitmap object
m_SWFMovie.DefineObject(&bmp[i], -1, false);

// Define the rectangle shape
shape[i].AddLineStyle(3, lineColor);
shape[i].AddBitmapFillStyle(bmp[i].m_ID, SWF_FILLSTYLETYPE_BITMAP_0, bitmapRect, clipRect);

pt.x = 0;
pt.y = 0;
shape[i].ChangeStyle(1, 1, 0, &pt);

//Draw out the rectangle
shape[i].AddLineSegment(300, 0);
shape[i].AddLineSegment(0, 260);
shape[i].AddLineSegment(-300, 0);
shape[i].AddLineSegment(0, -260);
m_SWFMovie.DefineObject(&shape[i], shape[i].m_Depth, true);

// Update the frame
// Close .SWF file
the question as follow:
the third and fourth frame is not shown usually.
please help me to find the cause.
thanks for author help
modified on Thursday, November 5, 2009 2:04 AM

GeneralRe: I couldnt add more frame into the swf movie Pinmemberdarkoman5-Nov-09 10:10 
GeneralRe: I couldnt add more frame into the swf movie Pinmemberrootlife8-Nov-09 2:07 
GeneralError while building test app Pinmembersajidadesh12-Jan-09 0:43 
Generalcompiling swflib project Pinmemberxavier6617-Sep-08 3:18 
QuestionHow to transcode flash type to other media type PinmemberMember 30495742-Mar-08 22:10 
QuestionText Tag PinmemberStephen Herd11-Oct-07 15:13 
AnswerRe: Text Tag Pinmemberdarkoman12-Oct-07 3:01 
GeneralRe: Text Tag PinmemberStephen Herd12-Oct-07 3:45 
GeneralI see only the first frame. PinmemberShlomo15-Jul-07 3:55 
GeneralRe: I see only the first frame. Pinmemberdarkoman6-Aug-08 5:39 
QuestionHow can I add an action context ? Pinmembermillion12320-May-07 4:19 
AnswerRe: How can I add an action context ? Pinmemberdarkoman20-May-07 10:11 
GeneralRe: How can I add an action context ? Pinmembermillion12320-May-07 18:46 
GeneralRe: How can I add an action context ? Pinmemberdarkoman20-May-07 20:32 
GeneralRe: How can I add an action context ? Pinmembermillion12321-May-07 4:25 
GeneralRe: How can I add an action context ? Pinmemberdarkoman21-May-07 9:28 
GeneralRe: How can I add an action context ? Pinmembermillion12321-May-07 16:22 
GeneralRe: How can I add an action context ? Pinmemberdarkoman21-May-07 20:36 
GeneralRe: How can I add an action context ? Pinmembermillion12321-May-07 21:43 
Questionthanks for the code; do you want credit on my web page? PinmemberDr. Zarkov24-Apr-07 8:05 
AnswerRe: thanks for the code; do you want credit on my web page? Pinmemberdarkoman24-Apr-07 10:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150302.1 | Last Updated 18 Jul 2006
Article Copyright 2006 by darkoman
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid