How to create flash movie using SWF Scout library and ASP.NET (on ASP.NET web-server)

Submitted by eLenka on 20 April, 2011 - 15:17

This is a step by step tutorial how to create SWF flash animation using SWF Scout library  in ASP.NET environment ("Hello, World!" example). 

IMPORTANT NOTE: To use SWF Scout library on web-server you should have additional "Web License" (see Purchase page)

SWF Scout library is capable of generating in-memory SWF files so file needn't to be stored as a file on hard drive and can be streamed right into the browser window. 

There is a special "GenerateInMemoryFile" property for such purposes. Set this property to TRUE and the library will generate and keep your SWF as in-memory stream without using of any temporary files.

1) Install SWF Scout SDK on your computer and run Visual Studio.NET

2) Go to File menu and select New Project:

New project menu

 

Select ASP.NET Web Application project type and click OK

ASP.NET new project wizard

 

3) Visual Studio.NET will create new empty ASP.NET project. Double-click on the empty space of the form:

New blank project generated by ASP.NET

 

This will open source code editor window on procedure handling Page_Load event. We will place our code for  SWF flash animation generation into this procedure:

Page load handler procedure generated by ASP.NET IDE

 

4) Use the following code for procedure (you can simply copy and paste this code from this page into ASP.NET source code editor window):

        'Put user code to initialize the page here
        Dim Movie
        Dim Size As Long
        Dim MemoryImage As System.Array
        Movie = CreateObject("SWFScout.FlashMovie")
        Movie.InitLibrary("demo", "demo")
        Movie.BeginMovie(0, 0, 640, 480, 1, 12, 6)
        Movie.Compressed = True
        Movie.GenerateInMemoryFile = True
        Movie.SetBackgroundColor(255, 255, 255) ' set background color to white
        Dim Font As Long
        Font = Movie.AddFont("Arial", 18, True, False, False, False, 0) ' add font
        ' create and place text
        Dim Text As Long
        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
        Dim Shape As Long
        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
 
        ' get size of generated in-memory SWF file
        Size = Movie.BinaryImageSize
        ' create new buffer with size equal to generated SWF file
        Dim Buffer(CInt(Size)) As Byte
        ' get in-memory swf file as byte stream
        MemoryImage = Movie.BinaryImage
        ' copy byte stream into buffer
        Array.Copy(MemoryImage, Buffer, Size)
        ' clear http output
        Response.Clear()
        ' set the content type to SWF
        Response.ContentType = "application/x-shockwave-flash"
        ' add content type header 
        Response.AddHeader("Content-Type", "application/x-shockwave-flash")
        ' set the content disposition
        Response.AddHeader("Content-Disposition", "inline;filename=shapes.swf")
        ' write the buffer with swf file to the output
        Response.BinaryWrite(Buffer)
        Response.End()
        ' disconnect from library
        Movie = Nothing

 

5) Now run ASP.NET project using Debug | Start command:

Start project menu

 

Visual Studio.NET will run ASP.NET project on web-server and you will see Internet Explorer window with generated SWF flash animation:

SWF flash movie generated by ASP.NET application

 

Download source code: