Today I tried to load a animated loading animation as a gif image into the Flash Player and discovered that he is not able to play them. It only shows the first frame.
My loading.gif:

loading.gif

So how to convert this gif animation into a swf file, which the Flash Player could play? (And of course I only want to use open source tools.) It was very easy:

  • Make sure you have ImageMagick installed.
  • Open a console and go to the directory where the gif file is located:
    convert +adjoin -coalesce loading.gif frame%02d.png
  • Now we have a png for every frame of the gif animation. Why png? Because swfmill does not support gif as file format and png it the only available format with support for transparency.
  • Create a XML file that look similar to this one:
    1. <?xml version="1.0" encoding="utf-8" ?>
    2. <movie width="32" height="32" framerate="25">
    3.         <background color="#ffffff"/>
    4.         <frame>
    5.                 <library>
    6.                         <clip id="frame00" import="frame00.png"/>
    7.                 </library>
    8.                 <place id="frame00" depth="1"/>
    9.         </frame>
    10.         <frame>
    11.                 <library>
    12.                         <clip id="frame01" import="frame01.png"/>
    13.                 </library>
    14.                 <place id="frame01" depth="1"/>
    15.         </frame>
    16.         <frame>
    17.                 <library>
    18.                         <clip id="frame02" import="frame02.png"/>
    19.                 </library>
    20.                 <place id="frame02" depth="1"/>
    21.         </frame>
    22. ….
    23. </movie>
  • Finally merge the single frame images together with swfmill:
    swfmill simple input.xml output.swf
  • That’s all.