How to embed animated GIFs into your Flash or AIR app

3 Jan 2010 Ferado

This article is old. I won't even try to convince you it still works. Flash is dead. AIR...I'm not sure. I haven't heard about Adobe AIR in years, nor have I tried to do anything with it.

I’m working on a web page thumbnail generator and a new blog post (a good one this time) about web page thumbnail generation. A topic for another day; however, when making the preloader for it…I don’t like the flash preloaders that you see every where, and I thought giving progress back wouldn’t be worth it because how am I going to know how to calculate the percentage done. You know how it says 60%, 70%, 80% percent in normal preloaders? Well, in this situation it wouldn’t be accurate to do something like that because I’m doing a whole bunch of different calculations, etc.

So what did I do? I thought, “Hey, why not just use an animated gif, like what I see on ajaxload.info?” I get back to coding and I load in my gif right? Wrong.

The Problem

ActionScript 3 (never tried it in ActionScript 2 but I’m assuming it’s not going to work properly either) only loads in the first frame of the gif.

That’s nice, isn’t it? No! My easy solution to my preloader problem turned into a Google session. Not a problem, I’m a professional. At first I had a tough time reading through all the forum posts. But you know what? Perseverance paid off.

The Solution

In walks in, strutting its stuff, AS3GIF.

Nice! Here’s all I had to do to load a gif into my AIR app.

 

DONE! Of course my code is a little bit different because it’s based on how I have my code structured, but this will get you started.

This should work in your air, flash or flex app as long as you’re using ActionScript 3. Feel free to contact me if you’re having any problems with it.