
After working with the GIF format in ActionScript 3 since a few days, I wanted to be able to load animated GIF's into the player which is not possible for the moment. If you load a GIF file with the flash.display.Loader class you will only get the first frame of the animation.
With this new GIFPlayer class, everything is handled, I have added some methods as you would call on a traditional flash.display.MovieClip
To load an animated GIF you would do :
// we create the GIFPlayer, it plays automatically by default
var myGIFPlayer:GIFPlayer = new GIFPlayer();
// we show it
addChild ( myGIFPlayer );
// we load a gif file
myGIFPlayer.load ( new URLRequest ("animation.gif") );
// you can also load any valid GIF stream (ByteArray) with the loadBytes method (version 0.2)
myGIFPlayer.loadBytes ( gifStream );
// listen for the IOErrorEvent.IO_ERROR event, dispatched when the GIF fails to load
myGIFPlayer.addEventListener ( IOErrorEvent.IO_ERROR, onIOError );
// listen for the GIFPlayerEvent.COMPLETE event, dispatched when GIF is loaded
myGIFPlayer.addEventListener ( GIFPlayerEvent.COMPLETE, onCompleteGIFLoad );
// listen for the FrameEvent.FRAME_RENDERED event, dispatched when a GIF frame is rendered on screen
myGIFPlayer.addEventListener ( FrameEvent.FRAME_RENDERED, onFrameRendered );
// listen for the FileTypeEvent.INVALID event, dispatched when an invalid file is loaded
myGIFPlayer.addEventListener ( FileTypeEvent.INVALID, onInvalidFileLoaded );
// get total frames
myGIFPlayer.totalFrames;
// standard methods
myGIFPlayer.play();
myGIFPlayer.stop();
myGIFPlayer.gotoAndStop(3);
myGIFPlayer.gotoAndPlay(3);
Please test it, and let me know if you got good results. Please don't load huge GIF files, some optimization will be done for this one in the following days.
Online Demo :
Projects using GIFPlayer Class :
Piterwilson did a funny experiment with this and the GIFAnimation Encoder class.
This work is licensed under a Creative Commons Attribution 3.0 License.
Sources and documentation available at http://code.google.com/p/as3gif/
Comments (111)
Very nice. Will be very interesting for TagLoops. Expecting the code
j’obtient cette erreur quand j’essaye d’uploader un gif:
Error #2044: IOErrorEvent non pris en charge : text=Error #2038: Erreur d’E/S de fichier.
at decoder_fla::MainTimeline/decoder_fla::frame1()
en tout cas bravo !
on en revait en 1999!
salut bigop,
peux tu m’envoyer le GIF que tu as tenté d’uploader sur thibault {at} bytearray.org
merci
bigop > I was dreaming on that too in 1999
Thibault> Really nothing … but why not disable all the button while uploading/loading the file ?
Tek > Yes, I will post a new version with new features, I’ll do that at the same time
My GIF uploaded & displayed ok, but for some reason when I pressed the play button it went to the next frame and stopped rather than playing straight through. To make it animate I had to keep hammering the button! Is this a bug?
Great work btw!
Also, another GIF I loaded had some areas go transparent – perhaps inter-frame compression doesn’t work properly?
Hi lain,
concerning the GIF which was not playing, it is a bug I have fixed in the online version and downloadable sources, can you try downloading the sources again and tell me ?
can you give me a link to that gif ? tks
concerning the transparent areas, I have noticed that issue and I will fix that
cheers
Hi, Thibault.
I expierenced the transparent area problem, too. And I found that this is caused by GIFs those are frame differenc optimized.
You can get the GIF from the following link.
http://www.webreference.com/dev/gifanim/index.html
best regards
Hi Han,
great, thank you very much for the link !
cheers
this one has some transparent areas:
http://www.jasoncoleman.com/Media/Images/hellsyeah.gif
good luck fixing this one – animated gifs rock! (probably should be supported natively right?)
hi lain,
thanks for the link !
currently working on another project, but will get back to it for sure
I heard that they were talking about adding it in the player but Macromedia didn’t have the rights to add it.
i need it
Just a quick note on an issue that happened to me, its a bit silly but it should be noted in case it happens to someone else:
For the gif playback to be accurate the movie must have a framerate that is as fast as the animated gif.
My animated gif wasnt playing at the right speed, then in noticed i had my movie at 5fps (douh!) when the gif needed 12fps. The sample source available here, has 12fps which might not be enough if your animated gif runs faster than that.
Keep up the excellent work.
Hi
I cannot download the zip file. Link is broken.
Thanks again !
Hi Gill,
sorry link has been fixed
cheers
Hi Thibault,
sorry for my bad English.
Your code is very useful for me. Thanks a lot!
I found a bug. As I know every frame in GIF has only part of image. You should merge it with the first frame. The code is:
GIFPlayer.as:
private function onTime ( pEvt:TimerEvent ) :void
{
……
//It was
//bOutput.bitmapData = aFrames[ iIndex ];
//Should replace
bOutput.bitmapData = aFrames[ 0 ];
bOutput.bitmapData.draw(aFrames[ iIndex ]);
………..
}
Hi Sergei,
Nice one ! This is nice, it fixes the interframe problem
Thanks a lot !
Hi again Thibault,
)
my previous code was not so good
I updated it.
This one works fine:
private function onTime ( pEvt:TimerEvent ) :void
{
……
//It was
//bOutput.bitmapData = aFrames[ iIndex ];
//Should replace
if (iIndex == 0)
bOutput.bitmapData = (aFrames[ 0 ] as BitmapData).clone();
bOutput.bitmapData.draw(aFrames[ iIndex ]);
………..
}
Good luck!
I updated source code
Thank you Sergei
If you got Flash, why on earth would you need and animated gif?
Hi noone,
just an old skool geeky experiment
Some applications could take advantage of it
cheers
le estoy muy agradecido por estos avances
After ripping my hair of a thousand times trying to solve this interframe issue I seem to have noticed why its not behaving correctly. it seems the Frame Object for each frame didn’t include the Dispose value individually. Each frame of an animated gif have there own disposal values. so after cramming a new value into that class along with changes to the imagereader I no longer have transparency and disappearing issues! Simply put you need to retrieve and store each disposal value into there respective frames. being able to display animated gifs correctly is an asset for Galleries and thumbnails!
Hi Shinobu,
Concerning the interframe issue, a fix has been added on the 07/13/07 where the dispose value is tested to draw each frame.
regards,
Hi,
I’m a Flex newbie and I get this error when trying to add the GIFPlayer to an existing component:
——–
TypeError: Error #1034: Type Coercion failed: cannot convert org.gif.player::GIFPlayer@4b5fb51 to mx.core.IUIComponent.
——–
I’m trying to add the GIFPlayer to a VBox using
——–
myVBox.addChild(myGIFPlayer);
——–
Any idea? Is it possible to use GIFPlayer within Flex?
Thanks!
JL
Hi JL,
In Flex, you can’t directly add a Sprite as a component child. You must add the GIFPlayer into a UIComponent and add it to your flex component.
It would give something like this :
var myGIFComponent:UIComponent = new UIComponent();
var myGIFPlayer:GIFPlayer = new GIFPlayer();
myGIFComponent.addChild( myGIFPlayer );
myVBox.addChild( myGIFComponent );
let me know
regards,
Whouhou! Works really well.
Thanks a lot!
Thibault you are atta-boy!
That`s very nice.
Thank U so much, very usefull thing!!!!
Hi,
Would it be possible to use this script on an embedded image? I use Flex.
Thanks for the help!
JL
The google code http trunk seems to be empty…
What about MouseEvent?
mattjpoole >> Thanks, I will update it
tltmusashi >> MouseEvent ?
yes, MouseEvents!
…
var myGIFLoader:GIFLoader = new GIFLoader();
…
myGIFLoader.AddEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
…
function onMouseOver(hEvent:MouseEvent):void{
trace(‘MouseOver’+hEvent.currentTarget.name);
}
istn work!
Hi Thibault,
Thanks again for that code! Can you just tell me if what I ask is possible? To use gifPlayer with an embedded image?
I use your code within Flex and would like to animate a gif that is embedded.
Thank you!
Hi JL,
I did an update for you, I have added a loadBytes method to the GIFPlayer class.
Just pass the GIF ByteArray that you embedded to the loadBytes method and it should run
You can download the update here :
http://www.bytearray.org/wp-content/projects/gifplayer/beta/GIFPlayer0.2.zip
let me know
kind regards,
Thibault
Hi Thibault,
Thanks for this new method! Unfortunately I’m not able to get a ByteArray from my embedded gif.
The only way I found to get a ByteArray from an image is:
———-
var testBM:Bitmap = testImg.content as Bitmap;
var myByte:ByteArray = new JPEGEncoder().encode(testBM.bitmapData);
———-
But of course this will generate a jpg, not a gif.
Can you help me with that? How can I get my ByteArray from my gif?
Another really small thing:
Could you add a “:void” return type to those functions:
- GIFDecoder.readNetscapeExt
- GIFDecoder.setPixels
I get a warning about that. I know it’s not really important but I prefere to have no warning at all!
Thank you again for your work, it’s really appreciated!
JL
Hi JL,
to embed your GIF as a ByteArray you can use the [Embed] tag in Flex :
[Embed(source="mygif.gif", mimeType="application/octet-stream")]
private var gifStream:Class;
then you can create an instance of it :
var gifBytes:ByteArray = new gifStream();
gifPlayer.loadBytes (gifBytes);
I have also updated the GIFDecoder class, so that you don’t have any more warnings
http://www.bytearray.org/wp-content/projects/gifplayer/beta/GIFPlayer0.2.zip
Hi tltmusashi,
To get MouseEvent’s you can add the GIFPlayer instance to an InteractiveObject :
var holder:Sprite = new Sprite();
holder.addChild ( myGIFPlayer );
addChild ( holder );
Then, you will be able to interact with the loaded GIF
kind regards,
Thibault
Woouhou! It works really well.
Thanks a lot Thibault!
Hi JL,
Happy it works
regards,
Thibault
Hi tltmusashi,
You can add the GIFPlayer object as a Sprite child and then you get interactivity events with the GIF
kind regards,
Thibault
Hey.
I was really wondering. Is there anyway to modify the height&width of the loaded gif? the function would really be useful.
Thanks!
Hi Piter,
I’m wondering, have you used the GIFPlayer to show the instant preview animation in your experiment, or did you built something yourself?
thanks,
Mugur.
Hi,
I’m able to add the animated gif to a UI component in flex, but then the animated gif appears choppy in the resulting swf(i think this has something to do with frame rates, but am not entirely sure). I’ve put up the swf, mxml, and gif files and would appreciate very much any help. I’m using GIFPlayer v0.2
The files are located here:
http://www.diegoolano.com/files/animatedgif/Display_bg.gif
http://www.diegoolano.com/files/animatedgif/animatedgif.mxml
http://www.diegoolano.com/files/animatedgif/animatedgif.swf
regards,
Diego
Whouhou! Works really well.
Thanks a lot!
Hi all!
I’ve used this code and it’s really cool! I use it to allow people in my project watching animated gifs streaming them with the red5 server. The resulting app is really cool! But i had to extend/change a little bit your code to allow your GIFPlayer class to be passed a ByteArray through a property to load the image via streaming option with AMF3 from red5. I was going to submit that idea to the google’s project, but the wiki is not working right now. I hope you read this post and think about implementing that thing in the next release, it works like a charm for me! If you need some help just tell me!
This project is amazing!
regards
Hi villalvilla,
Thanks for your kind comment !
Check comment N°39, I added such a feature in the release 0.2.
Let me know
kind regards,
Thibault
Hi Thibault,
First of all, congratulations for that cake, it´s amazing! but i have a question , is there some option to change width and height of the loaded object ?¿
Im trying modify the height value of the display object where the gif is added but the object disappears…
I saw at PiterWilson webCam Gif generator he has a fullScreen feature for the gif secuences then it´s possible make that.
Thanks Thibault.
Estoy usando “org.gif.player.GIFPlayer” (la version 0.2) en “Flex” y tengo un problema: Necesito redimensionar la imagen; No quiero que el gif resultante tenga su tamaño original.
¿Hay alguna posibilidad de hacer eso?
HI,
I am trying to make this thing work. I am new to Flex and am getting an easy error (well what I hope is easy to fix).
Can anyone help?
error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
Code:
import org.gif.player.GIFPlayer;
import org.gif.errors.FileTypeError;
import org.gif.events.FileTypeEvent;
import org.gif.events.FrameEvent;
import org.gif.events.GIFPlayerEvent;
import org.gif.events.TimeoutEvent;
var myGIFPlayer:GIFPlayer = new GIFPlayer();
public function MainMenuWeatherButtonClick():void
{
this.cursorManager.setBusyCursor();
viewstackMain.selectedIndex = 1;
vboxWeatherRadar.addChild( myGIFPlayer );
myGIFPlayer.load(new URLRequest(“http://sirocco.accuweather.com/nx_mosaic_640x480_public/sir/inmaSIRWI_.gif”));
myGIFPlayer.play();
this.cursorManager.removeBusyCursor();
}
thanks!!!
Hi Question W,
I tested your GIF image, and it runs fine. There might be an error somewhere else.
Can you try to remove the lines concerning the viewstackMain and cursorManager ?
let me know
kind regards,
Thibault
can’t set gif’s size,if refresh IE
Yeah I will right now. Wow I didn’t think I would get a reply any time soon. Thanks!!!
As soon as I change it to this…
I get a bunch of errors.
4
1120: Access of undefined property myGIFPlayer.
1
1120: Access of undefined property vboxWeatherRadar.
and 2
1084: var ‘myGIFPlayer’ will be scoped to the default namespace: main: internal. It will not be visible outside of this package.
So I don’t know what is up with the thing….. any ideas? thanks in advance
apparently its not showing the code because of script blocks….
lets try this
well that is a no but basically I commented out the function declaration the brackets and the requested items.
Do you have a sample project that you could post to the google code site? All I want to do is use your cool code to make a gif work in a flex project. Thanks, W
Hi, Thibault Imbert. The width/height property return 0, event after COMPLETE event dispatch. The GIFPlayerEvent has the ‘rect’, but it’s useless.
I’ve edited your GIFPlayer class (you should have done that).
All u needed 2 do is just to create a public var
public var rect:Rectangle;
And after in the readStream method to do so:
rect = aFrames[0].bitmapData.rect;
dispatchEvent (new GIFPlayerEvent( GIFPlayerEvent.COMPLETE , aFrames[0].bitmapData.rect));
U’d probably ask why did i do that. The answer is simple – 2 make thingz more useful.
Ex:
import org.gif.player.GIFPlayer;
import org.gif.events.GIFPlayerEvent;
var myGIFPlayer:GIFPlayer = new GIFPlayer();
myGIFPlayer.addEventListener(GIFPlayerEvent.COMPLETE, onCompleteGIFLoad);
myGIFPlayer.load(new URLRequest(“diego.gif”));
addChild(myGIFPlayer);
function onCompleteGIFLoad(event:GIFPlayerEvent):void
{
updatePos();
}
function updatePos():void
{
trace(“Now we can retrive the width/height in order to place/replace the player”, myGIFPlayer.rect);
}
cheers ^_^
Hello…
I have a problem with this gif…
http://smash.interfree.it/original.gif
When load some colors do not appear…why?
Smash >> some gif files exported via Photoshop are not frame-by-frame based, they are frame-by-frame but with ‘shared’ static background (see the photoshop preferences at the quality ‘web-based’ etc)
Gif player renders properly only those, which aren’t ‘web-based’, but i may be wrong.
var gif:GIFPlayer = new GIFPlayer();
addChild(gif);
gif.load(new URLRequest(“http://www.mb5u.com/uploads/jc/0835030.gif”));
gif.play();
//output
Error: Nothing to play
at org.gif.player::GIFPlayer/play()
at GIFPlayer_fla::MainTimeline/frame1()
Hi spotatoes,
Do not call the play method, just call the load method which will play the GIF automatically.
You can use methods like play, stop, etc once the GIFPlayerEvent.COMPLETE is fired.
let me know,
best,
Thibault
How to save an animated gif with the new fileReference of player 10?
Hi gino,
You can use the GIF Encoder class I did :
http://www.bytearray.org/?p=93
And save the GIF bytes on your disk and just play it
Hi. Thanks for doing the work of this interesting project. I just tried out the version 0.4 gif player and it worked fine on some GIF87a content, but failed to render some GIF89a content. I think the problem might be in this code (or my use of it) of the GIFPlayer.as in the update function, specifically
switch ( gifDecoder.disposeValue )
Here, the 89a files such as I have tried return a disposeValue of 0, which is not handled. If I try instead the same handling that you have case of disposeValue of 1, for the 0 case, it works fine for the GIF89a case. Happy to provide more details if you want.
I hope the GIFPlayer can load gif or jpg
How I do
Hi Tibault!
Congratulations for your great work!
I’ve been using this library for more or less 1 year and it worked wonderfull, but i found some gifs that doesn’t work with your library.
I’ve tried them and when your library tries to load them, only a white rectangle appears!
you can probe them from this links:
http://www.amezbros.com/1.gif
http://www.amezbros.com/2.gif
http://www.amezbros.com/3.gif
I’ve also uploaded this files to your online application and they don’t work. It’s strange, because they are only one frame long…
regards,
villalvilla
Encore un beau travail que ce player de gif.
Juste un petit problème , lors du chargement du gif , cela fait saccader mon animation flash en cours …
Salut Aurélien,
C’est un étrange bug, pourrai tu m’envoyer un fla ou un projet Flex d’exemple ?
Cool que tu apprécies ce petit player de GIF
Thibault
Here’s a tip how to convert these GIFs with cropped frames in them to a “normal” GIF file.
In Fireworks CS4, open one of such .gif files, then select File > Image Preview. Make sure you have Animated GIF type and then select Animation tab and deselect “Crop each frame”. OK.
After this open History panel, select and save the Export Settings history step as a custom command.
Now you can usse File > Batch Process, select all your gif files, select and add the newly made command and after that add Export (Settings: Use Settings from Each File) and run the batch.
Now you should have all your previously flickering gifs running OK in this excellent GIFPlayer class!
Hi Erki,
Thanks for that great information !
Thibault
Hey..excellent work.
It is a great help. thanks
Hello Thibault!
Merci pour ta classe!
I need to animate a GIF that I embedded and the ByteArray method you posted doesn’t work. I have an invalid cast error (can’t create a bytearray from an embedded GIF). If I create a new Bitmap class from the embedded Class, and then use the getBytes method, the loadBytes() doesn’t read nothing.
I’ll post my code.
[Embed( source="../assets/ajax-loader.gif", mimeType="application/octet-stream")]
private var loader_gif:Class;
var load_bmp:BitmapAsset = new loader_gif() as BitmapAsset;
var bytes:ByteArray = load_bmp.bitmapData.getPixels(new Rectangle(0, 0, load_bmp.width, load_bmp.height))
try
{
_loader_player.loadBytes(bytes);
}
catch (e:Error)
{
Dumper.error(“GIF error: ” + e.message);
}
I have to specify that if I do the same without embedding the image (using the load(:URLRequest) method) it works, so the problem is in how I get the bytes out of the embedded image.
Hi Luca,
Please try :
[Embed( source="../assets/ajax-loader.gif", mimeType="application/octet-stream")]
private var loader_gif:Class;
var gifBytes:ByteArray = new loader_gif() as ByteArray;
try
{
_loader_player.loadBytes(gifBytes);
}
catch (e:Error)
{
Dumper.error(”GIF error: ” + e.message);
}
let me know,
Thibault
I need to dynamically load a some image assets. The thing is, I dont know the type before its loaded. Is there a known way to test the file-type before trying to load the asset. It could be a jpeg, swf, png or animated gif.
It would be nice to be able to switch between Loader and GIFPlayer. Thanks in advance
Thibault,
I have v0.3 of your (wonderful) GIFPlayer, and have a couple questions for you:
1) Is it possible to resize a GIF after it has been loaded? I saw a couple other posts about this, and the mention of a solution, but whenever I set myGIFPlayer.height (or .width), the GIF is not displayed on the stage during runtime.
2) Is there a property in plae to dynamically set the playback rate of the GIF? I see how to change the value of delay in the GIFDecoder class, but don’t see a property in the GIFPlayer class (unless I’m missing something).
Thanks.
Thanks for the great work on this package. I’ve got the same question as Patrick Leffas… can I resize a GIFPlayer object? Simply setting myGIFPlayer.width disappears the image. I’m now playing with the GIFFrames array to see if I can resize each one individually. Any insight appreciated. I’ve got an app that pulls from an existing library of gifs that’re too big for the user interface.
Hi Joe and Patrick,
To resize the GIFPlayer object, just wait for the first FrameEvent.FRAME_RENDERED event to be dispatched, and resize it at this time, it should work smoothly.
Concerning delay time setting between each frame, good idea ! I will add this in a forthcoming update.
best,
Thibault
Hello,
i got a question about AS3.
Is it possible to export a .gif from a pure AS3 coded .fla ?
I only get a blank GIF. Would it be possible to use your code for such a conversion?
cheers Fried
as per our company norms i am not able to download the source code that u given in this blog. can u suggest me any other alternative. thanks in advance:)
Hi Girish,
You can download the sources on this page : http://code.google.com/p/as3gif/downloads/list
And get the latest sources here :
http://as3gif.googlecode.com/files/GIFPlayer%200.4.zip
let me know,
best,
Thibault
I love this. Thanks for another great project Thibault
Hi, Thibault Imbert.
Thanks you for this nice project, and I think I found a bug of it.
If I call the method ‘gotoAndStop’, then I can’t get the correct value of property ‘currentFrame’.
So, I think the private property ‘iIndex’ should update to a new value in the function ‘gotoAndStop’
iInc = iIndex = int(int(pFrame)-1);
Hi colorhook,
Yes, nice bug! I also added a modification in the gotoAndPlay method. I will post an update today
Thanks!
Thibault
Hi colorhook,
It is fixed in 0.5 with some other minor improvements
http://code.google.com/p/as3gif/
Thanks
It just a good idea!
Hi Thibault,
A kill(); method to clear instances and memory maybe’ll be interesting.
Hi André,
Yes, the next release will integrate a dispose() method.
Thanks!
Thibault
Hi André,
I added a dispose() method in release 0.6
let me know,
Thibault
Hi!
I’m having a problem with some GIF files. It seems new frames are drawn but the old ones are not erased. The problem appears only on certain files. Here’s one of them: http://depositfiles.com/files/qjrb3rcp8
It looks like some kind of bug, hope you fix it!
Cheers!
i dont like this. i usually load bitmaps with bulkloader on higher level and pass the bitmaps to my classes. i cant modify the code to make it work.
isnt there a function like?
myGif.decodeBitmap(bitmap:Bitmap)
{
var gif = bitmap.decode(whatever);
addChild(gif);
}
i dont need the loading file event. its too much for a gif to have a loader in there.
when im calling myGif.width and myGif.height this also makes problems. i dont like -.-
Hi guys.
I’ve written a UI component wrapper for this GIFPlayer:
package
{
import flash.events.IOErrorEvent;
import flash.utils.ByteArray;
import mx.core.UIComponent;
import org.bytearray.gif.events.FileTypeEvent;
import org.bytearray.gif.events.GIFPlayerEvent;
import org.bytearray.gif.player.GIFPlayer;
public class AnimatedGIF extends UIComponent
{
private var myGIFPlayer:GIFPlayer;
private var _gifStream:Class;
/**
* Constructor
*/
public function AnimatedGIF()
{
super();
myGIFPlayer = new GIFPlayer();
//add as a child
addChild ( myGIFPlayer );
//loads stream
loadGifStream();
// listen for the IOErrorEvent.IO_ERROR event, dispatched when the GIF fails to load
myGIFPlayer.addEventListener ( IOErrorEvent.IO_ERROR, handleError );
// listen for the GIFPlayerEvent.COMPLETE event, dispatched when GIF is loaded
myGIFPlayer.addEventListener ( GIFPlayerEvent.COMPLETE, handleCompleted );
// listen for the FileTypeEvent.INVALID event, dispatched when an invalid file is loaded
myGIFPlayer.addEventListener ( FileTypeEvent.INVALID, handleError );
}
public function set gifStream(c:Class) : void
{
_gifStream = c;
loadGifStream();
}
public function get gifStream() : Class
{
return _gifStream;
}
/**
* @private
*/
private function loadGifStream() : void
{
if (_gifStream)
{
myGIFPlayer.stop();
// we load a gif file
var gifBytes:ByteArray = new _gifStream();
myGIFPlayer.loadBytes(gifBytes);
}
}
/**
* @private
* Handles when the GIF fails to load or an invalid file is loaded
*/
private function handleError(e:IOErrorEvent) : void
{
trace(e.text);
}
/**
* @private
* Handles the GIF player completed
*/
private function handleCompleted(e:GIFPlayerEvent) : void
{
myGIFPlayer.play();
}
/**
* @private
*/
override public function set visible(value:Boolean):void
{
super.visible = value;
if (value)
{
myGIFPlayer.play();
}
else
{
myGIFPlayer.stop();
}
}
}
}
Now you can easy use animated gifs in mxml:
[Embed(source="spinner_20x20.gif", mimeType="application/octet-stream")]
private var gifStream:Class;
my previous message was truncated…
Now you can easy use animated gifs in mxml:
[Embed(source="spinner_20x20.gif", mimeType="application/octet-stream")]
private var gifStream:Class;
Oh..looks like this forum ‘kills’ any XML tags.
About MXML, hope you’ve got main idea.
Hi,
excellent work.
It is a great help. thanks
I updated it.
it fix problem.
(CellRenderer 0 ) ? delay : 100;
switch ( gifDecoder.disposeValue )
{
case 1:
if ( !iIndex )
{
if(bitmapData == null)
{
bitmapData = aFrames[ 0 ].bitmapData.clone();
}
else
{
bitmapData.draw ( aFrames[ 0 ].bitmapData );
}
}
else
{
bitmapData.draw ( aFrames[ iIndex ].bitmapData );
}
break
case 2:
bitmapData = aFrames[ iIndex ].bitmapData;
break;
}
dispatchEvent ( new FrameEvent ( FrameEvent.FRAME_RENDERED, aFrames[ iIndex ] ) );
}
Good luck!
This package is awesome. player and encoder both works fine in most case. but when I pass a output from encoder to player (i.e. player.loadBytes(encoder.stream), it gives no response. can anyone help?
That’s what I need.
Hi Thibault, hello everybody,
I am not familiar with any program language at all. I am looking for a gif-player, with that the user is only able to start the gif until it reaches its end. During playing the gif the user should not have the option to stop it until the endframe is reached ( so I need a play and a rewind button). Unfortunately I am not able to modify your player. Is there anyone who can do that for me, please?! I want to integrate the player into an HTML document. Is that possible?
Many thanks in advance
Tissi
var _mcLoader:MovieClip = new MovieClip()
var gifPlayer:GIFPlayer = new GIFPlayer();
gifPlayer.totalFrames;
_mcLoader.addChild(loadBalken);
loadContainer.rawChildren.addChild(_mcLoader);
gifPlayer.load(new URLRequest(‘img/ajax-loader.gif’));
listen you cant add an Flash Sprite or Movieclip to an Uicomponent
You have to take the rawChildren
Thanks for your class & help… I’m able to run an animated GIF under flex 3, if not executing a remoteObject call… but when I start my animated GIF, which is supposed to be there to run while my remoteObject call retrieves results from a DB, it “hangs” (maybe see 1st 2 frames) until remoteObject call completes… which is obviously not the intended result… any help here on what to do to keep animation running during remoteObject call would be greatly appreciated!
Thanks,
Tom
can any body give me the mxml code for runnig the code of walv
Hi,
This gif player is awesome and just what I needed for my project.
However, I would like to load my GIF and it not play straight away. I tried the gifplayer.stop () when the image is loaded and then using gifplayer.play() to start it.
However, in doing this, the gif does not display until .play() is called. I am able to stop it once it has played and the gif remains on display.
Any suggestions how I can solve this would be greatly appreciated.
Many Thanks
Scott
Hi Scott,
I am happy that you like the GIFPlayer !
Concerning your issue, you can instantiate the GIFPlayer object by passing false for the autoPlay parameter.
var myGIFPlayer:GIFPlayer = new GIFPlayer(false);
That would do the trick
let me know,
best,
Thibault
Thibault,
Thank you for your speedy response
I tried that, and still get the same result. Perhaps it might be something in the rest of my code causing it? Do you think that could affect it?
I’m fairly new to AS3 and have had subject myself pretty intensivly to it, so my troubleshooting skills aren’t up to much yet.
Also, I was wondering if it is possible to increase and decrease the speed that the loaded if plays at?
Many Thanks
Scott
Hi there, first of all i want to say that its an awesome add-on to the flash community
Unfortunately i have a little problem. A couple of images do not play well, the first frame is good, but the second shows the first and the second, the third shows the first, the second and the third, and so on. Then when its done with the animation it starts over at frame 1 again.. Seems like something is wrong..
And i must say, it depends on the image =/ which i saved the same way as working ones =/
example:
working:http://i4.photobucket.com/albums/y106/tvledden/sprites/th_RoyC51.gif
notworking: http://i4.photobucket.com/albums/y106/tvledden/sprites/Leah.gif
notworking:http://s4.photobucket.com/albums/y106/tvledden/sprites/?action=view¤t=Sage_Ph.gif&sort=ascending
Do you know of this problem?
I just want to express my gratitude for making and sharing these excellent GIF tools. I’ve never really liked GIFs, but they are an “industry standard” and now they are easy to use in Flex/Flash. Thank you!
PS: When I get a chance, I plan to attempt an APNG player based on your code. It should be an excellent framework to start from!
Trackbacks/Pingbacks (16)
[...] AS3 GIF Player Class 0.1 [...]
[...] via: bytearray [...]
[...] 上禮拜回老家 再加上週日都在玩電吉他 所以又好幾天沒寫文章了~>0< 今天就來介紹一個滿實用的網站 – ByteArray.org 而這個網站是以ActionScript3.0為主 進行開發一些實驗性的Project 目前的Project有八個 WiiFlash、Raster、MouseGesture、Live JPEG Encoder、PageFlip、 SMTP Mailer、GIF Animation Encoder、GIFPlayer 其中我比較感興趣的是Raster、MouseGesture、Live JPEG Encoder、SMTP Mailer 也就是比較偏向繪圖、影像、網路應用的部分 接著就來簡單介紹一下我個人覺得超猛的滑鼠手勢辨識Project – MouseGesture 不多說~先來玩看看再說拉~ 以下是一些擷取畫面 最左邊是字母跟數字的手勢說明,中間是手勢的圖畫區,右邊顯示滑鼠手勢輸入的文字 還可以輸入空格、點,也可以刪除文字 [...]
[...] bytearray.org
[...] created a wrapper around a component build by Thibault Imbert. Because it is an extenstion of the Flex SWFLoader, which allready can load SWF and images, you can [...]
I challenged GIFPlayer. However, it failed. Then, I corrected GIFPlayer….
現在、Progression Frameworkの実験として、「Flickrから最新写真一覧のRSSを読み込んで、アルバムっぽく表示する」というのを作ってみとるんですわ。でまぁ、RSSやら画像のロード中に表示する…
[...] http://www.bytearray.org/?p=95 [...]
[...] 介绍 as3gif下载地址(Google Code) 本文对您有用吗? 何不留下评论继续交流, 或者在您的博客上引用本文继续探讨. 您可以订阅读者对本文的回应或者订阅本博客以在您的阅读器中自动获取更新. [...]
[...] fotografa del GIF. Si queremos mostrar un GIF animado, tendremos que usar una librería externa: AS3 GIF Player. Es muy sencillo utilizarlo, pero si ustedes lo piden, podemos repasarlo en un próximo artículo. [...]
[...] alternatives to load animated gifs in Flash/Flex projects. Please see the following links: http://www.bytearray.org/?p=95 [...]
[...] alternatives to load animated gifs in Flash/Flex projects. Please see the following links: http://www.bytearray.org/?p=95 [...]
[...] primer fotograma. Sin embargo, gracias a los buenos oficios de Thibault Imbert tenemos la librería AS3 GIF Player Class, disponible en [...]
[...] http://www.bytearray.org/?p=95 [...]
[...] zips etc ascollada – collada file type as3syndicationlib – xml feeds (rss/atom) GIF Player GIF [...]
[...] 介绍 [...]
[...] Imbert (bytearray.org)有一个使用ActionScript动态加载GIF动画并播放的Project。 这个项目也可以在Google [...]