Using animating gifs in Flex and Flash

Using animating gifs in Flex and Flash

Hey geeks,

Today I will show you how to load animated gifs into your flash movie or flex application. To my and maybe also to your suprise Flash and Flex does not have this function natively. To extend your application with this feature you must download an extern library.  I used AS3GIF which is a free library that works great for me. It also includes a GIF encoder which allows you to frame by frame animations from a movieclip for instance.

You can download the source of this project right here

Howto:

After you have downloaded the library, and extracted to your root folder of your project, you import it to enable this library into your project

import org.bytearray.gif.*;
import org.bytearray.gif.player.GIFPlayer;

Next you create an instance of the GIFPlayer Class and set the url of the animated gif and you added to the stage.

var gif:GIFPlayer =new GIFPlayer();
gif.load(new URLRequest("ajax-loader.gif"));
uic.addChild(gif);

That’s it folks! It is that easy to use animated GIF’s in flex or flash. When you want to load gifs into flex you have to add the gif instance to an UIComponent. Because flash has no actual stage instance…

Have fun coding and experimenting

Lode

Btw: Thanks to thibault.imbert for this great library, check various of other library he’s made at this url


Also interesting reads:
  1. Google Maps API for Flex & Flash
  2. Getting started with Adobe Flex (Flash Builder)
  3. IPinfodb ActionScript 3.0 API
  4. Custom Mousecursors using ActionScript 3
  5. ShapesAnimation class GiveAway

About the Author

Lode is a Creative-Geek with passion for Graphic design , he is also into the web programming "stuff" like Adobe Flash,air and Flex . Lode loves to learn and loves to share knowledge with others.Follow Lode on http://twitter.com/stealfish