AS3 PNG to SWF Animation Generator
REM ## this little animation generator (DOS and AS3, uses Flex SDK for compiling SWF) is something I did while working on a large project that required me to grab pieces of video and recreate the animations. I ran the AVIs through an AVI to PNG app, using a rate of anywhere from 20 to 70 screens per seconds, then threw them into here for a quick animation. While this isn't going to produce any kind of beautiful vector animation, it is useful for those times when you have to resort to something like PNGs for a quick animation. You can also use JPGs with this script, although to use SWFs you have to alter it a little. You need the free Greensock tweening engine placed in the /com folder, as well as a path to the Flex 3.2 open source SDK in order to use this generator. Your pngs should reside in the /pngs folder, and you'll have to adjust the paths that are marked by Important!! below. This script will use the foldername the .bat is executed in as the name of the actionscript class as well as the SWF file - do NOT use any dashes or underscores in this name. By Stacey Tipton Reiman www.akwebgenius.com/blog ##
@echo off
setlocal ENABLEDELAYEDEXPANSION
REM slideshow settings are here:
rem time1 is the fade in time
set time1=0.1
rem time2 this is the slide length time
set time2=.04
rem time3 this is the fade out time
set time3=0.1
set fadeout=no
REM Important!! Change the path to your actual path, using FORWARD / slashes - don't include actual folder name
set path1=C:/path_to_your_folder/
REM Important!! Change the path to your actual path, using BACKWARD \ slashes - don't include actual folder name
set path2=C:\path_to_your_folder\
if exist pngs_to_swf.bat del pngs_to_swf.bat
for %%* in (.) do (
@echo %%~n* this is your current directory, which we will use as a variable
set myvar=%%~n*
)
if exist !myvar!.as del !myvar!.as
if exist !myvar!.swf del !myvar!.swf
set fileoutta=!myvar!.as
pause
echo package >> !fileoutta!
echo { >> !fileoutta!
echo import flash.display.Sprite; >> !fileoutta!
echo import flash.display.Bitmap; >> !fileoutta!
echo import flash.display.*; >> !fileoutta!
echo import flash.filters.*; >> !fileoutta!
echo import flash.events.Event; >> !fileoutta!
echo import flash.text.*; >> !fileoutta!
echo import flash.utils.getDefinitionByName; >> !fileoutta!
echo import flash.display.MovieClip; >> !fileoutta!
echo import com.greensock.easing.*; >> !fileoutta!
echo import com.greensock.*; >> !fileoutta!
echo import com.greensock.TweenMax; >> !fileoutta!
echo import com.greensock.TweenLite; >> !fileoutta!
echo import com.greensock.TimelineMax; >> !fileoutta!
echo import com.greensock.events.TweenEvent; >> !fileoutta!
echo import events.VariableHolder; >> !fileoutta!
echo import events.ListensForEvent; >> !fileoutta!
echo public class !myvar! extends Sprite >> !fileoutta!
echo { >> !fileoutta!
)
FOR /F "tokens=1,2 delims=." %%A in ( 'dir pngs\ /O:N /L /B /N *.png') do (
set /A Cnt+=1
set county=!Cnt!
set pic=%%A
set /a N+=1
REM Important!! Change the path1 variable above to your actual path, assuming also you have a /pngs folder containing your images
echo [Embed^(source="!path1!!myvar!/pngs/!pic!.png"^)]>> !fileoutta!
echo public var Picture!N!:Class; >> !fileoutta!
)
echo public function !myvar!^(^) >> !fileoutta!
echo { >> !fileoutta!
FOR /F "tokens=1,2 delims=." %%A in ( 'dir pngs\ /O:N /L /B /N *.png') do (
set /a V+=1
set /a Z+=1
set pic=%%A
echo var pic!V!:Bitmap = new Picture!V!^(^); >> !fileoutta!
echo addChild^(pic!V!^); >> !fileoutta!
echo pic!V!.width = 640 >> !fileoutta!
echo pic!V!.height = 480 >> !fileoutta!
echo pic!V!.x = 0 >> !fileoutta!
echo pic!V!.y = 0 >> !fileoutta!
echo pic!V!.alpha = 1; >> !fileoutta!
)
echo var timeline:TimelineMax = new TimelineMax^({repeat:0, paused:false, autoRemoveChildren:true, onComplete:removeAll}^); >> !fileoutta!
echo var tween:TweenMax = null; >> !fileoutta!
echo timeline.insertMultiple^( TweenMax.allFrom^([>> !fileoutta!
FOR /F "tokens=1,2 delims=." %%A in ( 'dir pngs\ /O:N /L /B /N *.png') do (
set pic=%%A
set /a X+=1
if !X! lss !county! echo/|set /p=pic!X!,>> !fileoutta!
if !X! equ !county! echo/|set /p=pic!X!>> !fileoutta!
)
echo ], !time1!, {autoAlpha:0, delay:0}, !time2!^), !time3!^);>> !fileoutta!
echo function removeAll^(^):void >> !fileoutta!
echo { >> !fileoutta!
FOR /F "tokens=1,2 delims=." %%A in ( 'dir pngs\ /O:N /L /B /N *.png') do (
if fadeout==yes (
set pic=%%A
set /a T+=1
echo removeChild^(pic!T!^); >> !fileoutta!
)
)
echo } >> !fileoutta!
echo } >> !fileoutta!
echo } >> !fileoutta!
echo } >> !fileoutta!
pause
set masterf=pngs_to_swf.bat
REM IMPORTANT!! path2 variable above needs to be changed to match your Adobe Flex 3.2 sdk bin!
echo cd C:\Program Files ^(x86^)\Adobe\Flex Builder 3\sdks\3.2.0\bin\ >> !masterf!
for /f "tokens=1,2 delims=." %%a in ( 'dir /O:N /L /B /N /a-d *."as"') do (
@echo off
echo mxmlc -default-size=640,480 -optimize=false -debug=false -default-background-color=^#000000 !path2!!myvar!\!myvar!.as >> !masterf!
)
if exist pngs_to_swf.bat call pngs_to_swf.bat
cls
endlocal
pause
via [DOS] AS3 PNG to SWF Animation Generator – Pastebin.com.
