How to create SWF image library file from pictures and use this image library for new Flash movie

Submitted by eLenka on 13 May, 2011 - 11:34

This sample demonstrates how to save images to single SWF file and how to use this file as a resource in the new Flash movie using SWF Scout.

SWF file with image stored (SWF library):

New SWF that uses previous SWF and manipulates images from attached SWF library:

Source code:

W = 640
H = 480
FPS = 12
 
' // make a SWF library with images

Set Movie = CreateObject("SWFScout.FlashMovie")
Movie.InitLibrary "demo", "demo"
' Movie creating and setting parameters
Movie.BeginMovie 0,0,W,H,1,FPS,6
Movie.Compressed = true
 
For ImageIndex = 1 to 3
 
image = Movie.AddImageFromFilename("NewImage" & CStr(ImageIndex) & ".jpg")
sprite = Movie.AddSprite
currobj = Movie.CurrentObjectID
Movie.SPRITE_PlaceImage Image, Movie.SPRITE_CurrentMaxDepth
Movie.ExportAssets "image" & CStr(ImageIndex), currobj
 
Movie.PlaceSprite Sprite, Movie.CurrentMaxDepth
 
Next
 
Movie.EndMovie
Movie.SaveToFile "MakeImagesLibraryAndMakeSWFUsingThisLibraryFromExtFile_lib.swf"
 
Set Movie = nothing
 
'//////////////////////////
' now create movie that will use produced LIB from SWF
'/////////////////////////

Set Movie = CreateObject("SWFScout.FlashMovie")
Movie.InitLibrary "demo", "demo"
Movie.BeginMovie 0,0,W,H,1,FPS,6
Movie.Compressed = true
 
Movie.AddExternalSWF "MakeImagesLibraryAndMakeSWFUsingThisLibraryFromExtFile_lib.swf", 1, true ' // seimResource = 1

'// now addding actionscript to place images at given X and Y, using their names mcl_image1, mcl_image2 etc
For ImageIndex = 1 to 3
 
' create a movieclip and attach image from library
Movie.AddScript
Movie.SCRIPT_Compile "this.createEmptyMovieClip('mcl_image" & CStr(ImageIndex) & "', _root.getNextHighestDepth()+" & CStr(ImageIndex) & ");attachMovie('image" & CStr(ImageIndex) & "', 'mcl_image" & CStr(ImageIndex) & "', getNextHighestDepth());"
MsgBox Movie.ASCompilerLog
 
 
' place image to X, Y (x = ImageIndex*10, y = ImageIndex * 15)
X = ImageIndex *10
Y = ImageIndex *15
Movie.AddScript
Movie.SCRIPT_Compile "mcl_image"& CStr(ImageIndex) & "._x=" & CStr(X) & ";mcl_image"& CStr(ImageIndex) & "._y=" & CStr(Y) & ";"
Movie.ShowFrame FPS*1 ' show frames for 1 second
Next
 
Movie.EndMovie
 
Movie.SaveToFile "MakeImagesLibraryAndMakeSWFUsingThisLibraryFromExtFile.swf"

 

Download source code: