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

本文介绍了一个使用ActionScript 3编写的GIF播放器类,该类能够加载并播放动态GIF文件。通过简单的API调用即可实现GIF文件的加载、播放控制等功能,并提供了错误处理机制。

用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/

内容概要:本文系统梳理了多个科研领域的前沿研究与技术实现,重点涵盖FDTD方法中的完美匹配层(PML)研究,以及Matlab/Simulink在电磁、电力、控制、通信、信号处理、图像处理、路径规划、能源系统优化等领域的仿真与算法实现。文中列举了大量基于Matlab和Python的科研案例,如风电功率预测、负荷预测、无人机三维路径规划、电池系统故障诊断、雷达模拟、通信编码、微电网优化调度等,强调结合智能优化算法(如粒子群、遗传算法、深度学习等)提升系统性能。同时,提供了丰富的代码资源与仿真模型,涵盖永磁同步电机控制、逆变器设计、多智能体任务配、虚拟电厂调度等复杂系统,助力科研人员快速开展复现实验与创新研究。; 适合人群:具备一定编程基础,熟悉Matlab/Python工具,从事电气工程、自动化、通信、人工智能、新能源、控制科学等相关领域研究的研发人员及研究生。; 使用场景及目标:① 学习实现FDTD仿真中的PML边界条件以有效抑制数值反射;② 掌握Matlab/Simulink在多物理场建模、控制系统设计与优化算法中的综合应用;③ 借助提供的代码资源完成科研复现、课程设计、竞赛项目或工程原型开发; 阅读建议:此资源以科研实战为导向,不仅提供理论方法,更强调代码实现与仿真验证。建议读者结合自身研究方向,按目录顺序查阅相关模块,下载配套代码进行调试与二次开发,以达到学以致用、融会贯通的目的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

游鱼_

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

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

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

打赏作者

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

抵扣说明:

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

余额充值