flash as3 加载gif图片播放类AS3 GIF Player Class

用as3写的播放gif,强,最近刚好要动态调用外部gif,嘻嘻,好好研究研究!

AS3 GIF Player Class 0.2 [ by Thibault Imbert ]

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 :

  1. // we create the GIFPlayer, it plays automatically by default   
  2. var myGIFPlayer:GIFPlayer = new GIFPlayer();   
  3. // we show it   
  4. addChild ( myGIFPlayer );   
  5. // we load a gif file   
  6. myGIFPlayer.load ( new URLRequest ("animation.gif") );   
  7. // you can also load any valid GIF stream (ByteArray) with the loadBytes method (version 0.2)   
  8. myGIFPlayer.loadBytes ( gifStream );   
  9. // listen for the IOErrorEvent.IO_ERROR event, dispatched when the GIF fails to load   
  10. myGIFPlayer.addEventListener ( IOErrorEvent.IO_ERROR, onIOError );   
  11. // listen for the GIFPlayerEvent.COMPLETE event, dispatched when GIF is loaded   
  12. myGIFPlayer.addEventListener ( GIFPlayerEvent.COMPLETE, onCompleteGIFLoad );   
  13. // listen for the FrameEvent.FRAME_RENDERED event, dispatched when a GIF frame is rendered on screen   
  14. myGIFPlayer.addEventListener ( FrameEvent.FRAME_RENDERED, onFrameRendered );   
  15. // listen for the FileTypeEvent.INVALID event, dispatched when an invalid file is loaded   
  16. myGIFPlayer.addEventListener ( FileTypeEvent.INVALID, onInvalidFileLoaded );   
  17. // get total frames   
  18. myGIFPlayer.totalFrames;   
  19. // standard methods   
  20. myGIFPlayer.play();   
  21. myGIFPlayer.stop();   
  22. myGIFPlayer.gotoAndStop(3);   
  23. myGIFPlayer.gotoAndPlay(3);  
// 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.

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 License.

Sources and documentation available at http://code.google.com/p/as3gif/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

游鱼_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值