Using PNG images with alpha-layer transparency in Flash movies produced with SWF Scout library

Submitted by eLenka on 13 May, 2011 - 12:14

This sample shows how to use semi-transparent PNG images (with alpha layer) in flash movies produced with SWF Scout SDK.

Produced flash movie (png_transparency_sample.swf)

Source code:

W = 640 ' width
H = 480 ' height
Set Movie = CreateObject("SWFScout.FlashMovie")
Set ImageLdr = CreateObject ("SWFScoutImgAddon.ImageLoader")
 
Movie.InitLibrary "demo", "demo"
 
Movie.BeginMovie 0, 0, W, H, 1, 12, 8
 
Font = Movie.AddFont("Arial", 18, True, False, False, False, 0) ' add font
' create and place text
Text = Movie.AddText("PNG with transparency Sample", 0, 0, 0, 255, Font, 50, 130, 380, 200)
Movie.PlaceText Text, Movie.CurrentMaxDepth ' place text into current depth

 
ImageLdr.ConnectToSWFLibrary (Movie)
Image = ImageLdr.AddImageFromFileNameEx ("TransparentPNG.png")
 
ImageLdr.DisconnectFromSWFLibrary
 
Movie.IMAGE_ConvertToJPEG 75 ' force use of JPEG compression for image so decrease final swf file size up to 5 times

' add image
Shape = Movie.AddShape ' add new shape
Movie.SHAPE_Rectangle 0, 0, 188, 170 ' draw rectangle
Movie.SHAPE_SetImageFill Image, 1 ' set image fill for shape, 1=sfimFit mode
Movie.PlaceShape Shape, Movie.CurrentMaxDepth ' place shape into max depth in sprite

Movie.ShowFrame 1 ' show 10 frames

Movie.EndMovie ' end movie generation

Movie.SaveToFile "png_transparency_sample.swf"
 
' disconnect from library
Set Movie = Nothing

 

Download source code (including source PNG and final SWF files):