微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

actionScript3.0 gifplayer

The GIFPlayer

The GIFPlayer class is used to play the gif animation.

It can load gif file from an URLRequest object or a ByteArray object.

gifplayer用于播放gif图片,它通过urlrequest对象,或者图片的二进制对象加载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);
                }
        }
}

 

The GIFEncoder

The GIFEncoder class use to create a gif file by frames.

Example(draw two frames and add to GIFEncoder then play the gif data by GIFPlayer):

gif解码器,用于根据帧生成gif。

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];
                }
        }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐