建站学 - 轻松建站从此开始!

建站学-个人建站指南,网页制作,网站设计,网站制作教程

当前位置: 建站学 > 图像设计 > Flash教程 >

AS3的GIF播放器及Encoder

时间:2011-10-02 21:05来源: 作者: 点击:
AS3GIF 让flash可以播放GIF动画文件,以及用ActionScript 3实现GIF编码的功能.     介绍     as3gif下载地址(Google Code) 收藏与此,查询方便。 播放功能: 用AS3GIF的类文件,可以通过load一个URLRequest或者load一个ByteArray来加载gif。

AS3GIF 让flash可以播放GIF动画文件,以及用ActionScript 3实现GIF编码的功能.

    介绍
    as3gif下载地址(Google Code)

收藏与此,查询方便。

播放功能:
用AS3GIF的类文件,可以通过load一个URLRequest或者load一个ByteArray来加载gif。
范例:

    package
    {
            import flash.display.Sprite;
            import flash.net.URLRequest;
            import org.gif.player.GIFPlayer;
          
            public class Main extends Sprite
            {
                    public function Main():void
                    {
                            var request:URLRequest = new URLRequest("diego.gif");
                          
                            var player:GIFPlayer = new GIFPlayer();
                            player.load(request);
                          
                            addChild(player);
                    }
            }
    }

编码功能:
范例:

    package
    {
            import flash.display.BitmapData;
            import flash.display.Shape;
            import flash.display.Sprite;
            import flash.utils.ByteArray;
            import org.gif.encoder.GIFEncoder;
            import org.gif.player.GIFPlayer;
          
            public class Main extends Sprite
            {
                    public function Main():void
                    {
                            var frames:Array = createFrames();
                          
                            var encoder:GIFEncoder = new GIFEncoder();
                          
                            encoder.setRepeat(0);                   //AUTO LOOP
                            encoder.setDelay(500);
                          
                            encoder.start();                        //MUST HAVE!
                          
                            encoder.addFrame(frames[0]);
                            encoder.addFrame(frames[1]);
                          
                            encoder.finish();                       //MUST HAVE!
                          
                            playGIF(encoder.stream);
                    }
                  
                    private function playGIF(data:ByteArray):void
                    {
                            data.position = 0;
                          
                            var player:GIFPlayer = new GIFPlayer();
                            player.loadBytes(data);
                          
                            addChild(player);
                    }
                  
                    private function createFrames():Array
                    {
                            var shape:Shape = new Shape();
                            shape.graphics.lineStyle(1, 0);
                          
                            shape.graphics.moveTo(60, 0);
                            shape.graphics.lineTo(60, 120);
                          
                            var frame1:BitmapData = new BitmapData(120, 120);
                            frame1.draw(shape);
                          
                            shape.graphics.clear();
                          
                            shape.graphics.lineStyle(1, 0);
                            shape.graphics.moveTo(0, 60);
                            shape.graphics.lineTo(120, 60);
                          
                            var frame2:BitmapData = new BitmapData(120, 120);
                            frame2.draw(shape);
                          
                            return [frame1, frame2];
                    }
            }
    }

 

(责任编辑:admin)
织梦二维码生成器
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片