forked from: Twitterのユーザーアイコンにgifアニメを使えるようにするswf

by aikawa3925 forked from Twitterのユーザーアイコンにgifアニメを使えるようにするswf (diff: 1)
♥0 | Line 51 | Modified 2011-11-04 22:38:29 | MIT License
play

ActionScript3 source code

/**
 * Copyright aikawa3925 ( http://wonderfl.net/user/aikawa3925 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/bJJT
 */

<?xml version="1.0" encoding="utf-8"?>
<!-- forked from zahir's Twitterのユーザーアイコンにgifアニメを使えるようにするswf -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" width="465" height="465">
    <fx:Script>
        <![CDATA[
            /*
             * Twitter のアイコンにアニメーションgifを適用できるようにする
             * 只それだけ
             */
            
            private var fr:FileReference;
            private const type:Array = [ new FileFilter("load gif file","*.gif;*.GIF") ];
            private var ba:ByteArray;
            
            private var fileName:String = "";
            
            private function start():void{
                s_btn.enabled = false;
                fr = new FileReference();
                fr.addEventListener(Event.SELECT, onSelect );
                fr.browse( type );
            }
            private function onSelect( e:Event ):void{
                fr.removeEventListener( Event.SELECT, onSelect );
                fr.addEventListener(Event.COMPLETE, onComp );
                fr.load();
            }
            private function onComp( e:Event ):void{
                fr.removeEventListener( Event.COMPLETE, onComp);
                
                fileName = fr.name;
                execute( fr.data );
            }
            private function execute( bytes:ByteArray ):void{
                ba = new ByteArray();
                bytes.readBytes( ba, 0, bytes.length - 1 );
                ba.position = ba.length;
                ba.writeByte(0x3C);
                ba.writeByte(0x2C);
                
                s_btn.enabled = true;
            }
            private function save():void{
                fr = new FileReference();
                fr.addEventListener(Event.SELECT, saveSelect);
                fr.save(ba,fileName);
            }
            private function saveSelect(e:Event):void{
                fr.removeEventListener(Event.SELECT, saveSelect);
            }
        ]]>
    </fx:Script>
    <s:HGroup horizontalCenter="0" verticalCenter="0">
        <s:Button label="Load gif file" click="start();"/>
        <s:Button id="s_btn" enabled="false" click="save();" label="Save gif file"/>
    </s:HGroup>
    <s:Label text="Twitterにgifファイルをupできるようにします" horizontalCenter="0" verticalCenter="-50"/>
    
</s:Application>