Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package display;
- import com.blazingmammothgames.util.ThreadPool;
- import event.CustomEvent;
- import gif.AnimatedGif;
- import haxe.io.Bytes;
- import openfl.display.Sprite;
- import openfl.errors.Error;
- import openfl.events.Event;
- import openfl.events.IOErrorEvent;
- import openfl.events.MouseEvent;
- import openfl.events.ProgressEvent;
- import openfl.net.URLLoader;
- import openfl.net.URLRequest;
- import openfl.net.URLLoaderDataFormat;
- import thread.ThreadsTools;
- import utils.Utils;
- class GifImage extends Sprite
- {
- public static inline var COMPLETE:String = "load_complete";
- //Loader object
- private var m_strUrl:String;
- private var m_urlLoader:URLLoader;
- //Loader Progress object
- private var m_spBckBarre:Sprite;
- private var m_spBarre:Sprite;
- //Gif object
- private var m_bytes:Bytes;
- private var m_gif:AnimatedGif;
- //Thread
- private var m_thread:ThreadPool;
- public function new(_url:String)
- {
- super();
- this.graphics.lineStyle(2.5, 0x000000);
- //this.graphics.beginFill(0xE3E3E3);
- this.graphics.drawRect(0, 0, Utils.stageWidth / 2 ,Utils.stageWidth / 2 );
- this.graphics.endFill();
- m_strUrl = _url;
- m_urlLoader = new URLLoader();
- m_urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
- m_urlLoader.addEventListener(Event.COMPLETE, onLoadComplete);
- m_urlLoader.addEventListener(ProgressEvent.PROGRESS, onProgressLoader);
- m_urlLoader.addEventListener(IOErrorEvent.IO_ERROR, onIoErrorEvent);
- m_urlLoader.load(new URLRequest(_url));
- }
- //__________________________________________________________________________________________________________
- //--------------------------------------------------
- // ENGINE FUNCTIONS
- //--------------------------------------------------
- private function onPlayGif(ev:MouseEvent):Void
- {
- m_gif.play();
- }
- private function onStopGif(ev:MouseEvent):Void
- {
- m_gif.stop();
- }
- //__________________________________________________________________________________________________________
- //--------------------------------------------------
- // HANDLER EVENT FUNCTIONS
- //--------------------------------------------------
- private function onLoadComplete(ev:Event):Void
- {
- m_urlLoader.removeEventListener(Event.COMPLETE, onLoadComplete);
- m_urlLoader.removeEventListener(ProgressEvent.PROGRESS, onProgressLoader);
- m_urlLoader.removeEventListener(IOErrorEvent.IO_ERROR, onIoErrorEvent);
- removeChild(m_spBarre);
- removeChild(m_spBckBarre);
- m_bytes = Bytes.ofString(m_urlLoader.data);
- m_gif = new AnimatedGif(m_bytes);
- //m_gif.play();
- addChild(m_gif);
- this.addEventListener(MouseEvent.MOUSE_OUT, onStopGif);
- this.addEventListener(MouseEvent.MOUSE_OVER, onPlayGif);
- }
- private function onProgressLoader(ev:ProgressEvent):Void
- {
- if (m_spBckBarre == null)
- {
- m_spBckBarre = new Sprite();
- m_spBckBarre.graphics.beginFill(0x303030);
- m_spBckBarre.graphics.drawRect(0, 0, this.width * 0.5, this.height * 0.10);
- m_spBckBarre.x = (this.width - m_spBckBarre.width) / 2;
- m_spBckBarre.y = (this.height - m_spBckBarre.height) / 2;
- addChild(m_spBckBarre);
- m_spBarre = new Sprite();
- m_spBarre.graphics.beginFill(0xf10013);
- m_spBarre.graphics.drawRect(0, 0, m_spBckBarre.width * 0.85, m_spBckBarre.height * 0.50);
- m_spBarre.x = (m_spBckBarre.width - m_spBarre.width) / 2;
- m_spBarre.y = (m_spBckBarre.height - m_spBarre.height) / 2;
- m_spBckBarre.addChild(m_spBarre);
- }
- var percent:Float = ev.bytesLoaded / ev.bytesTotal;
- m_spBarre.graphics.clear();
- m_spBarre.graphics.beginFill(0xf10013);
- m_spBarre.graphics.drawRect(0, 0, (m_spBckBarre.width * 0.85) * percent, m_spBckBarre.height * 0.50);
- //trace(ev.bytesLoaded, ev.bytesTotal);
- }
- private function onIoErrorEvent(ev:IOErrorEvent):Void
- {
- trace(ev.toString());
- }
- //__________________________________________________________________________________________________________
- //--------------------------------------------------
- // DISPOSE FUNCTION
- //--------------------------------------------------
- public function dispose():Void
- {
- m_urlLoader.removeEventListener(Event.COMPLETE, onLoadComplete);
- m_urlLoader.removeEventListener(ProgressEvent.PROGRESS, onProgressLoader);
- m_urlLoader.removeEventListener(IOErrorEvent.IO_ERROR, onIoErrorEvent);
- m_urlLoader = null;
- removeChild(m_gif);
- m_gif.stop();
- m_bytes = null;
- m_gif = null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement