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

Submitted by eLenka on 20 April, 2011 - 14:56

Please look through a quick guide for generating SWF flash animation movie using SWF Scout library in ASP ("Hello, World!" example).

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

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

Library has special "GenerateInMemoryFile" property for such purposes. You can set this flag to TRUE and the library will generate and keep SWF flash movie as in-memory stream.

1) Install SWF Scout SDK on your computer and create an "CreateSimpleSWF.asp" file in the notepad.

CreateSimpleSWF.asp will generate SWF file and return it as a stream.

Insert the following code into "CreateSimpleSWF.asp"

<%
 W = 640 ' width
 H = 480 ' height
 Set Movie = CreateObject("SWFScout.FlashMovie")
 Movie.InitLibrary "demo", "demo"
 Movie.BeginMovie 0, 0, W, H, 1, 12, 6
 Movie.Compressed = true
 Movie.GenerateInMemoryFile = True
 Movie.SetBackgroundColor 255, 255, 255 ' set background color to white
 
 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
 
 ' get generated SWF as binary image
 SWFfImage = Movie.BinaryImage
 ' clear the output stream
 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 binary image to the Response output stream 
 response.BinaryWrite SWFImage
 response.End
 ' disconnect from library
 Set Movie = Nothing
%>

 

2) Now use Notepad to create HTML file that will display a flash movie animation, "HelloWorld.html". Insert the following HTML code into "HelloWorld.html":

<HTML>
<HEAD>
<TITLE>Hello, World!</TITLE>
</HEAD>
<BODY bgcolor="#ffffff">
<CENTER>
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 
codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=5,0,0,0"
ID="SWF" WIDTH="100%" HEIGHT="100%" VIEWASTEXT>
<PARAM NAME="movie" VALUE="CreateSimpleSWF.asp">
<PARAM NAME="quality" VALUE="best">
<PARAM NAME="bgcolor" VALUE="#ffffff">
</EMBED>
</OBJECT>
</CENTER>
</BODY>
</HTML>

Place both "CreateSimpleSWF.asp" and "HelloWorld.asp" files into the same folder on web-server. (This folder is C:\Inetpub\wwwroot\ by default in IIS on Windows 2000 and XP)

3) Now open "http://localhost/HelloWorld.asp" (or "http://<your_webserver_name>/HelloWorld.asp") in Internet Explorer browser. You will see the generated flash movie in a browser window:

Flash movie generated by ASP script

Download source code: