Flex 不支持GIF的解决方法

GIF图片,加载到Image后,不能动起来,需要把 gif 转换成 swf ,才可以。

 

 可以使用GIFPlayer 0.4.zip  来解决这个问题。

下载地址:http://code.google.com/p/as3gif/downloads/list

 

下载后,把org下所有目录及文件拷到工程下,即可。

How_to_use  

Basic UsageThe GIFPlayerThe GIFEncoder

The GIFPlayer class is used to play the gif animation.

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

Example:

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 class use to create a gif file by frames.

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

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值