How to create Flash movie using SWF Scout SDK and Visual C++

Submitted by eLenka on 7 July, 2011 - 13:03

This tutorial will teach you how to create simple SWF flash movie animation in VC++ using SWF Scout SDK.

1) Install SWF Scout library on your computer and run Visual C++
2) Select the "New.." command from "File" menu to run :

3)The New Project Wizard dialog will appear on the screen. Select "Win32 Console Application" project type and enter "HelloWorld" as the Project name:

4) The wizard will ask what kind of Console Application you want to create. Select A "Hello, World!" application and click Finish:

VC++ will show the summary information for a new project. Click OK:

Visual C++ will generate the application code for simple console application.

Source code editor window will appear. To edit main() function just open the class tree on the left and double click on HelloWorld Classes > Globals > main (int argc, char* argv[1]):

VC++ will open main() function: 

5) To use SWF Scout from VC++ application, you have to tell the compiler to import type library information into the project.

To import the type library just add #import compiler directive after #include directive:

#import "SWFScout.tlb"
using namespace SWFScout;

and then HelloWorld.cpp will look like this:

6) The code snippet that will generate SWF flash animation should be placed to the main() function body.

// HelloWorld.cpp : Defines the entry point for the console application.
//
 
#include "stdafx.h"
 
#import "SWFScout.tlb"
using namespace SWFScout;
 
int main(int argc, char* argv[])
{
       // initialize OLE
       HRESULT hr = CoInitialize(NULL);
 
       // check for errors
       if (FAILED(hr)) {
       MessageBox(0,"OLE initialization errp","error",MB_OK);
       return -1;
       }
       // declare SWFScout object
       IFlashMovie* Movie = NULL;
       long Shape, Font, Text;
       CLSID clsid;
 
       // get inuque ID for IFlashMovie interface
       hr = CLSIDFromProgID(OLESTR("SWFScout.FlashMovie"), &clsid);
       // check for errors
       if (FAILED(hr)) {
       MessageBox(0,"Can't get CLSID for interface","error",MB_OK);
       goto Uninit;
       };
       // create FlashMovie object
       hr = CoCreateInstance(clsid, NULL, CLSCTX_ALL,__uuidof(IFlashMovie), (LPVOID*)&Movie);
       // check for errors
       if (FAILED(hr)) {
       MessageBox(0,"Can't create Movie object","error",MB_OK);
       goto Uninit;
       }
 
       // initialize library
       Movie->InitLibrary("demo", "demo");
       // start movie generation
       Movie->BeginMovie(0,0,640,480, 1, 12,6);
       // start document generation
 
       Font = Movie->AddFont("Arial", 18, true, false, false, false, 0); // add font
       // create and place text
       Text = Movie->AddText("Hello, World!", 0, 0, 0, 255, Font, 0, 100, 250, 160);
       Movie->PlaceText(Text, Movie->CurrentMaxDepth); // place text into current depth
       Movie->PLACE_FadeOut(0.5); // fade out text
       Shape = Movie->AddShape(); // add new shape
       Movie->SHAPE_Rectangle (0, 140, 150, 285); // draw rectangle
       Movie->SHAPE_SetSolidColor(50, 255, 50, true, 255); // set solid fill for shape
 
       Movie->PlaceShape(Shape, Movie->CurrentMaxDepth); // place shape into current depth
       Movie->ShowFrame(10); // show 10 frames
       Movie->EndMovie(); // end movie generation
       Movie->SaveToFile("c:\\Shapes.swf"); // save generated SWF into file
 
       // disconnect from library
       Movie->Release();
       // uninitialize OLE libraries
       Uninit:
       CoUninitialize();
       return 0;
}

This code will generate SWF flash animation file that will be saved as c:\shapes.swf file.

Hint - you can simply copy and paste the code from the sample above into VC++ code editor window:
 

7) Run the application by pressing F5 (or use Build > Debug > Go).
VC++ will compile and run "Hello, World!" application. It will generate Shapes.swf file on C:\ disk

You can view generated flash file (.SWF) using Internet Explorer or another application for playing flash animations.
 

 

Download source code: