Want more features on Pastebin? Sign Up, it's FREE!
Guest

Flash Embed Generator

By: a guest on Feb 23rd, 2012  |  syntax: VisualBasic  |  size: 2.40 KB  |  views: 52  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. On Error Resume Next
  2.         dim fso, write, start, writeTo
  3.  
  4.         ' Where to read from, where to write to
  5.         start = "assets"
  6.         writeTo = "src/Assets.as"
  7.  
  8.         Set fso = CreateObject("Scripting.FileSystemObject")
  9.         Set write = fso.CreateTextFile(writeTo, True)
  10.  
  11.         ' Begin file
  12.         write.WriteLine("package")
  13.         write.WriteLine("{")
  14.         write.WriteLine("       public class Assets")
  15.         write.WriteLine("       {")
  16.  
  17.         ' Read files
  18.         readFolder("")
  19.  
  20.         ' Close
  21.         write.WriteLine("       }")
  22.         write.WriteLine("}")
  23.  
  24.         write.Close
  25.  
  26.         Function readFolder(name)
  27.                 Dim folder, files, folders, list, count, listName, className, extension
  28.                 Set folder = fso.GetFolder(start & "/" & name)
  29.  
  30.                 ' Clean the list name
  31.                 listName = UCase(name)
  32.                 listName = Replace(listName, "/", "_")
  33.                 listName = Replace(listName, "-", "_")
  34.                 listName = Replace(listName, " ", "")
  35.                 list = "                public static const " & listName & ":Array = ["
  36.  
  37.                 count = 0
  38.  
  39.                 ' For every file ...
  40.                 For each file In folder.Files
  41.  
  42.                         ' Clean the file name
  43.                         className = Left(file.Name, Len(file.Name) - 4)
  44.                         className = name & "_" & className
  45.                         className = Replace(className, "/", "_")
  46.                         className = Replace(className, " ", "")
  47.                         className = Replace(className, "-", "_")
  48.                         className = UCase(className)
  49.  
  50.                         ' get the extension
  51.                         extension = Right(file.Name, 3)
  52.                        
  53.                         ' Add it to the list (array of files from this folder)
  54.                         If count = 0 Then
  55.                                 list = list & className
  56.                         Else
  57.                                 list = list & ", " & className
  58.                         End If
  59.  
  60.                         ' Write this to the file
  61.                         If extension = "oel" Or extension = "xml" Then
  62.                                 write.WriteLine("               [Embed(source='../" & start & "/" & name & "/" & file.Name&"', mimeType='application/octet-stream')] public static const " & className & ":Class;")
  63.                         Else
  64.                                 write.WriteLine("               [Embed(source='../" & start & "/" & name & "/" & file.Name&"')] public static const " & className & ":Class;")
  65.                         End If
  66.                         count = count + 1
  67.                 Next
  68.  
  69.                 ' Write the list of files from the folder, if any files exist
  70.                 If count > 1 Then
  71.                         list = list & "];"
  72.                         write.WriteLine(list)
  73.                 End If
  74.  
  75.                 ' Find all the subfolders, and read them
  76.                 For each subfolder in folder.SubFolders
  77.                         write.WriteLine("")
  78.                         write.WriteLine("               /* --- " & subfolder.Name & " --- */")
  79.  
  80.                         ' only add a / if the previous folder exists (not the root folder)
  81.                         If name = "" Then
  82.                                 readFolder(subfolder.Name)
  83.                         Else
  84.                                 readFolder(name&"/"&subfolder.Name)
  85.                         End If
  86.                 Next
  87.  
  88.         End Function
clone this paste RAW Paste Data