Play GIF pictures in Flex

Source: Internet
Author: User

Http://www.gnria.com/flex/flex-gifplayer.html

The image control in flex inserts a picture of a GIF animation by default only one frame is displayed, that is, it is not moving, and we can use the Gifplayer class package to implement a GIF image of the animation inserted in Flex.
Gifplayer Download: http://code.google.com/p/as3gif/
The examples demonstrate several common functions: play, stop, play to the first few frames, stop at the first few frames.

Gifplay.mxml

    <?xml version= "1.0" encoding= "Utf-8"?> <mx:application xmlns:mx= "Http://www.adobe.com/2006/mxml" layout= "Absolute" horizontalalign= "center" creationcomplete= "Init ();" Preloader= "Com.preload.PreLoad" BAC
            Kgroundcolor= "0x414141" > <mx:style source= "flex/yfskin/yflexskin.css"/> <mx:Script> <!
            [cdata[import Flash.net.URLRequest;
            Import Org.gif.player.GIFPlayer;
            Import org.gif.events.FileTypeEvent;
            Import org.gif.events.GIFPlayerEvent;
            Import org.gif.events.FrameEvent;
            Import org.gif.events.TimeoutEvent;
            private var _mygifplayer:gifplayer = new Gifplayer ();
            private Var _totalframe:number;
           
            private Var _currentframe:number;
                Private Function init (): void {var request:urlrequest = new URLRequest ("Md.gif"); _mygifplayer.load (Request);
                Img.addchild (_mygifplayer);
                _mygifplayer.addeventlistener (Gifplayerevent.complete, oncompletegif);
                _mygifplayer.addeventlistener (frameevent.frame_rendered, onframerendered);
            _mygifplayer.addeventlistener (Timeoutevent.time_out, ontimeout); } Private Function Oncompletegif (event:gifplayerevent): void {_totalfr
                ame = _mygifplayer.totalframes;
            Totalframe.text = String (_totalframe); } Private Function Onframerendered (event:frameevent): void {Currentfra
            Me.Text = String (_mygifplayer.currentframe);  } Private Function OnTimeOut (event:timeoutevent): void {trace ("GIF is
           
            Error! ");}
            Private function Play (): void {_mygifplayer.play ();
           
    }        Private Function Stop (): void {_mygifplayer.stop (); } Private Function gotoAndPlay (): void {var numframe:number = Math.flo
                or (Math.random () * _totalframe) + 1;
                _mygifplayer.gotoandplay (Numframe);
            Gotoplaybtn.label = "Gotoplay (" + Numframe + ")"; } Private Function gotoAndStop (): void {var numframe:number = Math.flo
                or (Math.random () * _totalframe) + 1;
                _mygifplayer.gotoandstop (Numframe);
            Gotostopbtn.label = "Gotostop (" + Numframe + ")"; }]]> </mx:Script> <mx:image id= "img" width= "217" height= "+" top= "le ft= "/> <mx:applicationcontrolbar width=" 80% "left=" bottom= "> <mx:button label=
         "Play" height= "click=" Play (); "Stylename=" Primarybutton "/>   <mx:button label= "Stop" height= "click=" Stop (), "/> <mx:button id=" gotoplaybtn "height=" "Lab" El= "Gotoplay (Rand)" click= "gotoAndPlay ();"/> <mx:button id= "gotostopbtn" height= "" Label= "Gotostop (RA nd) "click=" gotoAndStop (); "/> <mx:label text=" totalframe: "/> <mx:label id=" Totalfram E "/> <mx:label text=" currentframe: "/> <mx:label id=" Currentframe "/> < /mx:applicationcontrolbar> </mx:Application>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.