Home

SWF Scout

SWF Scout screenshot (click to enlarge)



SWF Scout ActiveX/NET library

Quick Guide: How to generate a new flash movie using existing flash movie (.SWF) as template from Visual Basic script using SWF Scout library 

You can download the source code of this example here: swfscout_template.zip

See also: Using FLA-based SWF templates

SWF Scout library can be used to load Flash movies (.SWF) files and use them as templates to create new flash movies based on these templates. Our SWF Scout library is capable of replacing of pre-defined text macros (you can define sub-string for replace) and images in Flash movies. Images can be replaced using name of symbol in flash movie.

Almost all SWF flash movies generated by SWF Scout library are supported for use as templates. You can also use flash movies created with another tools, applications or libraries.

This page will teach you to how create new SWF flash animation movie based on existing SWF flash movie template using VBScript and SWF Scout library.

Windows 98/2000/ME/XP have built-in VBScript support and all files with ".VBS" are recognized as VBScript files and can be executed by system.

Creating of new flash movies based on existing flash movies is quite simple: there is a special method for starting flash movie generation based on existing SWF template: BeginMovieFromTemplate (SWFTemplate as string, ResetRules as boolean).

To add a template processing rule for an image please use AddTemplateRule_Image method. To add a template processing rule for a text please use AddTemplateRule_Text

To apply template rules to loaded SWF file please call ProcessTemplateRules method.

At first we will create the flash movie that we will use as template.

1) Install SWF Scout library on your computer

 
2) Run Notepad
 
3) To create SWF flash movie template in VBScript we have to write a very simple script:
  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.SetBackgroundColor 255,255,255
 
 Font = Movie.AddFont( "Tahoma",12,true,false,false,false,0)
 
' create an area for the first image
  ImageShape = Movie.AddShape
  Movie.SHAPE_RoundRect 0, 0, 200, 200, 3
  Movie.SHAPE_SetSolidColor 127,127,127,true, 255
 
  Movie.PlaceShape ImageShape, Movie.CurrentMaxDepth
  Movie.PLACE_Name = "image1" ' set name for shape object where we will place image
 
' create an area for the second image
  ImageShape = Movie.AddShape
  Movie.SHAPE_RoundRect 220, 0, 420, 200, 3
  Movie.SHAPE_SetSolidColor 127,127,127,true, 255
 
  Movie.PlaceShape ImageShape, Movie.CurrentMaxDepth
  Movie.PLACE_Name = "image2" ' set name for shape object where we will place image
 
' create and place text fields
 
 Text= Movie.AddTextEdit ("textbox1", "textbox1: here is some text that can include template variables like <%REPLACEME_1%> and <%REPLACEME_2%>. They will be replaced",127,127,255,255,Font,2, 202, 400, 420)
 Movie.TEXT_ReadOnly= false
 Movie.TEXT_NoSelect= false
 Movie.TEXT_Align = 0 ' staLeft align 
 Movie.TEXT_Multiline = true
 Movie.TEXT_WordWrap = true
 Movie.PlaceText Text,Movie.CurrentMaxDepth
 
 Text= Movie.AddTextEdit ("textbox2", "textbox2: Here is the second text field that contain these template varaibles: <%REPLACEME_1%>, <%REPLACEME_2%>. They will be replaced as well. ",127,200,127,255,Font, 2, 325, 400, 520)
 Movie.TEXT_ReadOnly= false
 Movie.TEXT_NoSelect= false
 Movie.TEXT_Align = 1 ' staRight align 
 Movie.TEXT_Multiline = true
 Movie.TEXT_WordWrap = true
 Movie.PlaceText Text,Movie.CurrentMaxDepth
 
 Movie.EndMovie
 
 Movie.SaveToFile "SampleTemplate.swf"
 
Feel free to copy code from this page, paste into the notepad and save  as a "CreateSWFtemplate.VBS":
 
4) Double-click "CreateSWFTemplate.VBS" file in Explorer or in another file manager and the script will be executed.

This script will generate SampleTemplate.swf file that we will use as template. You can see this flash movie below. Grayed shapes are for images and text fields contain macros like <%REPLACEME_1%> and <%REPLACEME_2%>:

Now we will create the script that will replace grayed shapes in the flash movie above with images and all macros in text will be replaced with the new text.

Here is the Visual Basic script that will load "SampleTemplate.swf" as template and then will process it to create new flash movie:

  Set Movie = CreateObject("SWFScout.FlashMovie")
 
  Movie.InitLibrary "demo","demo"
 
  Movie.BeginMovie 0,0,W,H,1,12,6
 
  Movie.BeginMovieFromTemplate "SampleTemplate.swf",true
 
  Movie.AddTemplateRule_Text "<%REPLACEME_1%>","SUCCESSFULLY REPLACED",true
  Movie.AddTemplateRule_Text "<%REPLACEME_2%>","SUCCESSFULLY REPLACED TOO",true
  Movie.AddTemplateRule_Image "image1","NewImage1.jpg", 0
  Movie.AddTemplateRule_Image "image2","NewImage2.jpg", 0
  i = Movie.ProcessTemplateRules
  
  Movie.EndMovie

  Movie.SaveToFile "ProcessedTemplate.swf"

 

Save this script as "ProcessSWFTemplate.vbs" and run.

Run this script and it will generate "ProcessedTemplate.swf" flash movie:

You can download the source code of this example here: swfscout_template.zip

See also: Using FLA-based SWF templates

<< previous sample   return to the list of samples  view next sample >>


Products  |  Download  |  Purchase  |  Support  |  Contacts  |  Testimonials  |  News |  

ByteScout, 2003-2008. All other company and product names may be trademarks of their respective companies. Privacy Statement