@echo off
REM DOS Batch SWF Compiler Script created by Stacey Tipton Reiman, Anchorage, Alaska, 2011. 
REM http://www.homeschoolspanishonline.com
REM mspanish@zoho.com
REM This file have saved me many hours of work, and I hope you find it helpful in your own projects!

REM Please note the sections titled REM 1, REM 2, REM 3, and REM 4: these are areas you MUST customize for this script to work on your own computer!
setlocal ENABLEDELAYEDEXPANSION

for %%* in (.) do  (
@echo %%~n* this is your current directory, which we will use as a variable
set myvar=%%~n*

)
REM Here we create a directory for the UTF-8 Converted files, necessary for international characters
if exist word_scripts_sp_au_utf8 del word_scripts_sp_au_utf8

REM Here we create the directory for the AS3 class files before converting to UTF-8
if exist word_scripts_sp_au del word_scripts_sp_au
mkdir word_scripts_sp_au

FOR /F "tokens=1,2 delims=_" %%A in (glossary/glossary.txt) do (

REM These commands below deal with accent marks, and may be unnecessary for your purposes. You can certainly edit out the below items, or add your own changes.
set spanishfile=%%A
set spanishword=%%A
set spanishwordy=%%A
set englishword=%%B
set spanishaccent=%%A
set spanishnodash=%%A
set english=%%B
set englishnodash=%%B
set spanishaccent=!spanishaccent:-= !

set spanishword=!spanishword:=e!
set spanishword=!spanishword:=a!
set spanishword=!spanishword:=i!
set spanishword=!spanishword:=o!
set spanishword=!spanishword:=u!
set spanishword=!spanishword:=n!

set spanishwordy=!spanishwordy:=e!
set spanishwordy=!spanishwordy:=a!
set spanishwordy=!spanishwordy:=i!
set spanishwordy=!spanishwordy:=o!
set spanishwordy=!spanishwordy:=u!
set spanishwordy=!spanishwordy:=n!
set spanishwordy=!spanishwordy:=!
set spanishwordy=!spanishwordy:?=!
set spanishwordy=!spanishwordy:,=!
REM set spanishword=!spanishword:-= !
set spanishwordy2=!spanishwordy!
set spanishwordy2=!spanishwordy2:-=1!


REM Create Spanish Word Class Files with Embedded Audio
set fileoutta=!spanishwordy2!.as

REM 1 #############################################################################

REM This is where you will add your OWN AS3 Class Template to create your custom SWFs

REM 1 #############################################################################

echo package >> !fileoutta! 
echo { >> !fileoutta! 
echo import flash.display.Sprite; >> !fileoutta! 
echo import flash.display.*;   >> !fileoutta! 
echo import flash.filters.*;   >> !fileoutta! 
echo import flash.text.*; >> !fileoutta! 
echo import flash.utils.getDefinitionByName; >> !fileoutta! 
echo import flash.display.MovieClip; >> !fileoutta! 
echo import flash.events.MouseEvent; >> !fileoutta! 
echo import flash.media.Sound; >> !fileoutta! 
echo import flash.media.SoundChannel; >> !fileoutta! 
echo import flash.text.TextFormat; >> !fileoutta! 
echo import flash.text.AntiAliasType; >> !fileoutta! 

echo     public class !spanishwordy2! extends Sprite >> !fileoutta! 
echo     { >> !fileoutta! 
REM 2 #############################################################################

REM Here you'll need to edit the paths below to reflect your own files for the .mp3, .swf or other image files, and the font

REM 2 #############################################################################
echo         [Embed^(source="C:/Users/You/Desktop/!myvar!/sound/!spanishwordy!.mp3"^)] >> !fileoutta! 
echo         public var soundClass:Class; >> !fileoutta! 
echo         [Embed^(source="C:/Users/You/Desktop/!myvar!/images/!spanishwordy!.swf"^)] >> !fileoutta! 
echo         public var Picture:Class; >> !fileoutta! 
echo         [Embed^(source="C:/Users/You/Desktop/!myvar!/images/audio.swf"^)] >> !fileoutta! 
echo         public var AudioBtn:Class; >> !fileoutta! 

echo 		[Embed^(mimeType="application/x-font", unicodeRange='U+0061-U+007A,U+00E1-U+00E1,U+00E9-U+00E9,U+00ED-U+00ED,U+00F1-U+00F1,U+003F-U+003F,U+00FA-U+00FA,U+00E1-U+00E1,U+00F3-U+00F3,U+00BF-U+00BF,U+00A1-U+00A1', source="C:/Users/You/Desktop/BradBunR.ttf",fontName="Brady"^)] >> !fileoutta! 
echo private var terminatorFontClass:Class; >> !fileoutta! 

echo         public function !spanishwordy2!^(^) >> !fileoutta! 
echo         { >> !fileoutta! 
echo             var sndChannel:SoundChannel; >> !fileoutta! 
echo             var smallSound:Sound = new soundClass^(^) as Sound; >> !fileoutta! 
REM echo             smallSound.play^(^); >> !fileoutta! 

echo var pic:Sprite = new Picture^(^); >> !fileoutta! 
echo var pic2:Sprite = new Picture^(^); >> !fileoutta! 
echo var audio1:Sprite = new AudioBtn^(^); >> !fileoutta! 
echo var square:Sprite = new Sprite^(^); >> !fileoutta! 
echo addChild^(square^); >> !fileoutta! 
echo square.graphics.drawRect^(0,0,500,350^); >> !fileoutta! 
echo square.x = 0; >> !fileoutta! 
echo square.y = 2; >> !fileoutta! 

echo var filter:GlowFilter = new GlowFilter;  >> !fileoutta! 
echo filter.color = 0xFF0000;  >> !fileoutta! 
echo filter.blurX = 5;  >> !fileoutta! 
echo filter.blurY = 5; >> !fileoutta! 

echo var filter1:GlowFilter = new GlowFilter;  >> !fileoutta! 
echo filter1.color = 0xFFFF00;  >> !fileoutta! 
echo filter1.blurX = 5;  >> !fileoutta! 
echo filter1.blurY = 5; >> !fileoutta! 

echo var str:String = new String^("!spanishaccent!"^); >> !fileoutta! 
echo 			var __text_tf:TextField = new TextField^(^),__format:TextFormat = new TextFormat^(^); >> !fileoutta! 
echo __format.font="Brady"; >> !fileoutta! 
rem echo __format.size=100; >> !fileoutta! 
echo if ^(str.length ^<= 9^) { >> !fileoutta!
echo __format.size = 70; >> !fileoutta! 
rem echo __text_tf.defaultTextFormat = __format; >> !fileoutta! 
echo } else if ^(str.length ^>= 14 ^&^& str.length ^<= 22^) { >> !fileoutta! 
echo __format.size = 50; >> !fileoutta! 
echo __text_tf.defaultTextFormat = __format; >> !fileoutta! 
echo } else if ^(str.length ^>= 28 ^&^& str.length ^<= 48^) { >> !fileoutta! 
echo __format.size = 40; >> !fileoutta! 
echo __text_tf.defaultTextFormat = __format; >> !fileoutta! 
echo }
echo } else { >> !fileoutta! 
echo __format.size = 50; >> !fileoutta! 
echo } >> !fileoutta! 

echo __format.letterSpacing=6; >> !fileoutta! 
echo __format.align = TextFormatAlign.CENTER; >> !fileoutta! 
echo __text_tf.width=500; >> !fileoutta! 
echo __text_tf.embedFonts = true; >> !fileoutta! 
echo __text_tf.wordWrap = true; >> !fileoutta! 
echo __text_tf.defaultTextFormat = __format; >> !fileoutta! 
echo __text_tf.autoSize="center"; >> !fileoutta! 
echo __text_tf.text = str; >> !fileoutta! 


echo square.addChild^(__text_tf^); >> !fileoutta! 
echo square.addChild^(audio1^); >> !fileoutta! 
echo audio1.y = 10;  >> !fileoutta! 
echo audio1.x = 10;   >> !fileoutta! 
echo audio1.scaleY = .5; >> !fileoutta! 
echo audio1.scaleX = .5; >> !fileoutta! 

echo audio1.addEventListener^(MouseEvent.CLICK, onPressHandler^);>> !fileoutta! 
echo audio1.addEventListener^(MouseEvent.ROLL_OUT, onReleaseHandler^);>> !fileoutta! 
echo audio1.addEventListener^(MouseEvent.ROLL_OVER, onHoverHandler^);>> !fileoutta! 
echo audio1.addEventListener^(MouseEvent.MOUSE_UP, onOutHandler^);>> !fileoutta! 

echo audio1.buttonMode = true;>> !fileoutta! 
echo audio1.useHandCursor = true;>> !fileoutta! 
echo audio1.filters = null; >> !fileoutta! 

echo function onPressHandler^(event:MouseEvent^):void{>> !fileoutta! 
echo  sndChannel = smallSound.play^(^); >> !fileoutta! 
echo audio1.filters = ^[filter^];  >> !fileoutta! 
echo }>> !fileoutta! 

echo function onHoverHandler^(event:MouseEvent^):void{>> !fileoutta! 
echo audio1.filters = ^[filter1^];  >> !fileoutta! 
echo }>> !fileoutta! 

echo function onReleaseHandler^(event:MouseEvent^):void{>> !fileoutta! 
echo  sndChannel.stop^(^); >> !fileoutta!
echo audio1.filters = null; >> !fileoutta! 
echo } >> !fileoutta! 

echo function onOutHandler^(event:MouseEvent^):void{>> !fileoutta! 
echo audio1.filters = null; >> !fileoutta! 
echo } >> !fileoutta! 

echo __text_tf.y = -10;  >> !fileoutta! 

 echo var ratio:Number;  >> !fileoutta! 
 echo var wide:Number;   >> !fileoutta! 
 echo var targetWidth:Number = 400;  >> !fileoutta! 
 echo var targetHeight:Number = 250;  >> !fileoutta! 

 echo if ^(pic.width ^< targetWidth^) {  >> !fileoutta! 
 echo ratio = targetWidth / pic.width;  >> !fileoutta! 
 echo pic.width  = targetWidth;  >> !fileoutta! 
 echo pic.height *= ratio;  >> !fileoutta! 
 echo wide = pic.width*ratio; >> !fileoutta! 
 echo } >> !fileoutta! 
 echo if ^(pic.height ^< targetHeight^) {  >> !fileoutta! 
 echo ratio = targetHeight / pic.height;  >> !fileoutta! 
 echo pic.width  *= ratio;  >> !fileoutta! 
 echo pic.height  = targetHeight;  >> !fileoutta! 
 echo wide = pic.width*ratio; >> !fileoutta! 
 echo } >> !fileoutta! 
 echo if ^(pic.width ^> targetWidth^) {  >> !fileoutta! 
 echo ratio = targetWidth / pic.width;  >> !fileoutta! 
 echo pic.width  *= ratio;  >> !fileoutta! 
 echo pic.height *= ratio;  >> !fileoutta! 
 echo wide = pic.width*ratio; >> !fileoutta! 
 echo } >> !fileoutta! 
 echo if ^(pic.height ^> targetHeight^) {  >> !fileoutta! 
 echo ratio = targetHeight / pic.height;  >> !fileoutta! 
 echo pic.width  *= ratio;  >> !fileoutta! 
 echo pic.height *= ratio;  >> !fileoutta! 
 echo wide = pic.width*ratio; >> !fileoutta! 
 echo } >> !fileoutta! 
 echo pic.y = 110;  >> !fileoutta!    
 echo pic.x = 250 - wide/2 ;     >> !fileoutta!  
 echo pic.scaleX = pic.scaleY;  >> !fileoutta! 
 echo square.addChild^(pic^);  >> !fileoutta!   

echo } >> !fileoutta! 
echo }  >> !fileoutta! 
echo }  >> !fileoutta! 

REM #############################################################################

REM END of your AS3 Class Template Code

REM #############################################################################

move "!fileoutta!"  word_scripts_sp_au
echo !spanishword! this is the word you have used as your File, Sound, and Image

)

REM call utf_convert.bat
echo.
echo STOP here to do the UTF-8 conversions
echo this is necessary for any non English characters
echo.   
echo INSTRUCTIONS:
echo.
echo 1- Click on the UTF_CONVERT.bat and let it run 
echo 2- Then click on UTF_CLICK_TO_CONVERT.BAT 
echo.
echo The UTF-8 files have now been created
echo Now hit any key to resume the DOS process
pause
REM call utf_click_to_convert.bat
REM echo your actionscript files should be UTF-8 and ready for SWF'ing now!!

echo Your working folder name is: !myvar!
REM Spanish Words with Embedded Audio SWF File Creation
if exist words_to_swf3.bat del words_to_swf3.bat
set masterf=words_to_swf3.bat

REM 3 #############################################################################

REM Here you'll need to edit the path below to reflect your own Flex SDK Compiler

REM 3 #############################################################################
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 word_scripts_sp_au_utf8\ /O:N /L /B /N  *.as')  do (  
@echo off

REM 4 #############################################################################

REM Here you can edit the Flex Compiler options

REM 4 #############################################################################
echo mxmlc -default-size=500,350 -optimize=true -debug=false -default-background-color=^#FFFFFF C:\Users\You\Desktop\!myvar!\word_scripts_sp_au_utf8\%%A.as >> !masterf! 
)

move "words_to_swf3.bat" word_scripts_sp_au_utf8

cd word_scripts_sp_au_utf8

if exist words_to_swf3.bat call words_to_swf3.bat

)
pause

cls
endlocal