If I’m perfectly honest I really can’t stand animated gifs (as a format), simply because the compression is really poor and the resulting filesize is usually huge. Never the less it’s pretty university accepted on the old interwebs, so I thought it might be handy to have a fast and easy way of applying them to Away3d materials.

Dependencies:
My fork of “Flash-Animated-GIF-Library”
https://github.com/peteshand/Flash-Animated-GIF-Library
My fork of “away3d-core-fp11”
https://github.com/peteshand/away3d-core-fp11

First step is to load or embed your gif.
In my case I’m simply going to embed it.

[Embed(source="image.gif", mimeType = "application/octet-stream")]
public static const data:Class;

Next create a new GIFPlayer instance and add a GIFPlayerEvent.COMPLETE event listener

gifPlayer = new GIFPlayer(true);
gifPlayer.addEventListener(GIFPlayerEvent.COMPLETE, OnDecodeComplete);
gifPlayer.loadBytes(new data());

Then all you need to do is create a GifTexture and a GifMaterial and your home free.

var texture:GifTexture = new GifTexture(gifPlayer);
var gifMaterial:GifMaterial = new GifMaterial(texture);

Animated Gif applied to a plane

var geo:PlaneGeometry = new PlaneGeometry(gifPlayer.width, gifPlayer.height, 1, 1, false);
var mesh:Mesh = new Mesh(geo, gifMaterial);
addChild(mesh);

Get Adobe Flash player

Animated Gif applied to a cube

var geo:CubeGeometry = new PlaneGeometry(200,200,200,1,1,1,false);
var mesh:Mesh = new Mesh(geo, gifMaterial);
addChild(mesh);

Get Adobe Flash player

Transparent Gif

Get Adobe Flash player