<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" horizontalAlign="center" creationComplete="init();" backgroundColor="#FFFFFF" backgroundGradientColors="[#FFFFFF,#C0C0C0]">
<mx:Script>
<![CDATA[
import flash.net.URLRequest;
import org.bytearray.gif.player.GIFPlayer;
import org.bytearray.gif.events.FileTypeEvent;
import org.bytearray.gif.events.GIFPlayerEvent;
import org.bytearray.gif.events.FrameEvent;
import org.bytearray.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("spinner.gif");
//你的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 {
_totalFrame=_myGIFPlayer.totalFrames;
totalframe.text=String(_totalFrame);
}
private function onFrameRendered(event:FrameEvent):void {
currentframe.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.floor(Math.random() * _totalFrame) + 1; _myGIFPlayer.gotoAndPlay(numFrame); gotoplaybtn.label="gotoPlay(" + numFrame + ")"; }
private function gotoandstop():void { var numFrame:Number=Math.floor(Math.random() * _totalFrame) + 1; _myGIFPlayer.gotoAndStop(numFrame); gotostopbtn.label="gotoStop(" + numFrame + ")"; } ]]> </mx:Script> <mx:Image id="img" width="100" height="300"/> <mx:ApplicationControlBar width="80%" left="50" bottom="20"> <mx:Button label="Play" click="play();"/> <mx:Button label="Stop" click="stop();"/> <mx:Button id="gotoplaybtn" label="gotoPlay(rand)" click="gotoandplay();"/> <mx:Button id="gotostopbtn" label="gotoStop(rand)" click="gotoandstop();"/> <mx:Label text="TotalFrame:"/> <mx:Label id="totalframe"/> <mx:Label text="CurrentFrame:"/> <mx:Label id="currentframe"/> </mx:ApplicationControlBar></mx:Application>
<mx:Script>
<![CDATA[
import flash.net.URLRequest;
import org.bytearray.gif.player.GIFPlayer;
import org.bytearray.gif.events.FileTypeEvent;
import org.bytearray.gif.events.GIFPlayerEvent;
import org.bytearray.gif.events.FrameEvent;
import org.bytearray.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("spinner.gif");
//你的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 {
_totalFrame=_myGIFPlayer.totalFrames;
totalframe.text=String(_totalFrame);
}
private function onFrameRendered(event:FrameEvent):void {
currentframe.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.floor(Math.random() * _totalFrame) + 1; _myGIFPlayer.gotoAndPlay(numFrame); gotoplaybtn.label="gotoPlay(" + numFrame + ")"; }
private function gotoandstop():void { var numFrame:Number=Math.floor(Math.random() * _totalFrame) + 1; _myGIFPlayer.gotoAndStop(numFrame); gotostopbtn.label="gotoStop(" + numFrame + ")"; } ]]> </mx:Script> <mx:Image id="img" width="100" height="300"/> <mx:ApplicationControlBar width="80%" left="50" bottom="20"> <mx:Button label="Play" click="play();"/> <mx:Button label="Stop" click="stop();"/> <mx:Button id="gotoplaybtn" label="gotoPlay(rand)" click="gotoandplay();"/> <mx:Button id="gotostopbtn" label="gotoStop(rand)" click="gotoandstop();"/> <mx:Label text="TotalFrame:"/> <mx:Label id="totalframe"/> <mx:Label text="CurrentFrame:"/> <mx:Label id="currentframe"/> </mx:ApplicationControlBar></mx:Application>