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>