Click here to Skip to main content
15,920,513 members
Articles / Desktop Programming / MFC
Article

SWFLIB - a free Flash authoring library

Rate me:
Please Sign up or sign in to vote.
4.75/5 (26 votes)
18 Jul 2006CPOL2 min read 170.6K   6.5K   93   50
An article on a free Flash authoring library.

Introduction

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.

Background

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 nID = 1;
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.AddSolidFillStyle(fillColor);
shape.AddLineSegment(100, 0);
shape.AddLineSegment(0, 100);
shape.AddLineSegment(-100, 0);
shape.AddLineSegment(0, -100);
swfMovie.AddShape(&shape, shape.m_Depth, true);
swfMovie.ShowFrame();

// Close .SWF file
swfMovie.CloseSWFFile();

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.

History

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

License

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


Written By
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

 
GeneralRe: How can I add an action context ? Pin
million12321-May-07 15:22
million12321-May-07 15:22 
GeneralRe: How can I add an action context ? Pin
darkoman21-May-07 19:36
darkoman21-May-07 19:36 
GeneralRe: How can I add an action context ? Pin
million12321-May-07 20:43
million12321-May-07 20:43 
Questionthanks for the code; do you want credit on my web page? Pin
Dr. Zarkov24-Apr-07 7:05
Dr. Zarkov24-Apr-07 7:05 
AnswerRe: thanks for the code; do you want credit on my web page? Pin
darkoman24-Apr-07 9:44
darkoman24-Apr-07 9:44 
GeneralRe: thanks for the code; do you want credit on my web page? Pin
Dr. Zarkov4-May-07 7:47
Dr. Zarkov4-May-07 7:47 
AnswerRe: thanks for the code; do you want credit on my web page? Pin
darkoman5-May-07 2:42
darkoman5-May-07 2:42 
QuestionBitmap animation won't update second frame Pin
sfaul20-Apr-07 5:58
sfaul20-Apr-07 5:58 
Hi all,
If anyone has used this file to create a bitmap (jpeg) animation, maybe you can help me. I have two jpegs and I want to create a 2 frame animation. I follow the authors instructions and the first frame turns out correct (except for image is flipped).

However, in the second frame the bitmap is not updated. A second frame IS being produced because if I move the rectangle shape that shows up in the animation, but the image filling the rectangle remains the same. I have followed the authors instructions and order but I can't find where I'm going wrong. I've tried using the same shape, updating the shape, using arrays of bitmaps etc, but have been unable to have the 2nd image appear on the 2nd frame.

Any help would be appreciated.
Regards,
Stephen Faul


Here follows the code used....

	// Movie Params<br />
	SIZE_F movie_size = {200.0f, 120.0f};<br />
	int framerate = 1;<br />
	POINT_F pt;<br />
	CSWFMovie m_SWFMovie;<br />
<br />
	// Create Basic Movie<br />
	m_SWFMovie.OpenSWFFile("C:\\TEMP\\SWFTest.swf", movie_size, framerate);<br />
	// Give it a background colour<br />
	SWF_RGB bgColor = {255, 0, 0};<br />
	m_SWFMovie.SetBackgroundColor(bgColor);<br />
<br />
	float bmp_width = 800.0f; float bmp_height = 533.0f;<br />
<br />
	// Define shapes<br />
	RECT_F shapeRect = {0.0f, 0.0f, 200.0f, 120.0f};<br />
	SWF_RGBA lineColor = {0, 0, 0, 255};<br />
	RECT_F bitmapRect = {0.0f, 0.0f, bmp_width, bmp_height}; // size of the bitmap<br />
	RECT_F clipRect = shapeRect; // fill the full rectangle<br />
<br />
<br />
<br />
<br />
	// Define bitmap object<br />
	CSWFBitmap bmp(1, "C:\\TEMP\\ron40002.jpg");<br />
	m_SWFMovie.DefineObject(&bmp, -1, false);<br />
<br />
        // Define the rectangle shape<br />
	CSWFShape shape(3, shapeRect, 1);<br />
	shape.AddLineStyle(3, lineColor);<br />
	shape.AddBitmapFillStyle(bmp.m_ID, SWF_FILLSTYLETYPE_BITMAP_0, bitmapRect, clipRect);<br />
<br />
	pt.x = 0;<br />
	pt.y = 0;<br />
	shape.ChangeStyle(1, 1, 0, &pt);<br />
	<br />
	//Draw out the rectangle<br />
	shape.AddLineSegment(200, 0);<br />
	shape.AddLineSegment(0, 120);<br />
	shape.AddLineSegment(-200, 0);<br />
	shape.AddLineSegment(0, -120);<br />
	m_SWFMovie.DefineObject(&shape, shape.m_ID, true);<br />
<br />
	// Update the frame<br />
	m_SWFMovie.ShowFrame();<br />
<br />
	/////////////////////////////<br />
	// First Frame Done and Works<br />
	/////////////////////////////<br />
<br />
<br />
<br />
<br />
        // 2nd bitmap<br />
	CSWFBitmap bmp2(2, "C:\\TEMP\\ron40006.jpg");<br />
	m_SWFMovie.DefineObject(&bmp2, -1, false);<br />
<br />
	// Define the rectangle shape<br />
	CSWFShape shape2(4, shapeRect, 1);<br />
	shape.AddLineStyle(3, lineColor);<br />
	shape.AddBitmapFillStyle(bmp2.m_ID, SWF_FILLSTYLETYPE_BITMAP_0, bitmapRect, clipRect);<br />
<br />
	pt.x = 0;<br />
	pt.y = 0;<br />
	shape2.ChangeStyle(1, 1, 0, &pt);<br />
	<br />
	//Draw out the rectangle<br />
	shape2.AddLineSegment(200, 0);<br />
	shape2.AddLineSegment(0, 120);<br />
	shape2.AddLineSegment(-200, 0);<br />
	shape2.AddLineSegment(0, -120);<br />
	m_SWFMovie.DefineObject(&shape2, shape2.m_ID, true);<br />
<br />
	// Update the frame<br />
	m_SWFMovie.ShowFrame();<br />
<br />
	// Close .SWF file<br />
	m_SWFMovie.CloseSWFFile();<br />

AnswerRe: Bitmap animation won't update second frame Pin
RonaldY6-May-08 21:27
RonaldY6-May-08 21:27 
AnswerRe: Bitmap animation won't update second frame Pin
darkoman6-Aug-08 4:33
darkoman6-Aug-08 4:33 
QuestionCan Scale(...) work beyond 1.0 (100%) ? Pin
gordon8819-Nov-06 14:30
professionalgordon8819-Nov-06 14:30 
AnswerRe: Can Scale(...) work beyond 1.0 (100%) ? Pin
darkoman19-Nov-06 19:49
darkoman19-Nov-06 19:49 
GeneralRe: Can Scale(...) work beyond 1.0 (100%) ? Pin
gordon8827-Nov-06 12:10
professionalgordon8827-Nov-06 12:10 
GeneralI can't add two key frame to the swf movie Pin
winart16-Jul-06 18:36
winart16-Jul-06 18:36 
GeneralRe: I can't add two key frame to the swf movie Pin
darkoman23-Jul-06 22:35
darkoman23-Jul-06 22:35 
GeneralType Issues Pin
rssmsvc7-Jul-06 16:36
rssmsvc7-Jul-06 16:36 
GeneralWhy reinvent the wheel Pin
skycoder4-Jul-06 0:53
skycoder4-Jul-06 0:53 
GeneralRe: Why reinvent the wheel Pin
darkoman4-Jul-06 1:35
darkoman4-Jul-06 1:35 
GeneralRe: Why reinvent the wheel Pin
skycoder4-Jul-06 5:18
skycoder4-Jul-06 5:18 
GeneralRe: Why reinvent the wheel-think again... Pin
Homero De la Garza30-Jul-06 18:11
Homero De la Garza30-Jul-06 18:11 
GeneralRe: Why reinvent the wheel-think again... Pin
skycoder30-Jul-06 20:22
skycoder30-Jul-06 20:22 
GeneralMy apologies too... Pin
Homero De la Garza31-Jul-06 8:40
Homero De la Garza31-Jul-06 8:40 
GeneralRe: My apologies too... Pin
skycoder31-Jul-06 20:40
skycoder31-Jul-06 20:40 
Generalirrlicht Pin
Homero De la Garza2-Aug-06 15:15
Homero De la Garza2-Aug-06 15:15 
QuestionCan you explain more how to fill with bitmaps ? Pin
Thierry Maurel1-Jul-06 6:58
Thierry Maurel1-Jul-06 6:58 

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

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