Skip to content

Commit

Permalink
Fixing width and height properties, and also improving the dispose() …
Browse files Browse the repository at this point in the history
…functionality
  • Loading branch information
theturtle32 committed Jan 7, 2012
1 parent a06f244 commit e4ac043
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 16 deletions.
1 change: 0 additions & 1 deletion AS3GifPlayer/src/com/worlize/gif/GIFDecoder.as
Expand Up @@ -442,7 +442,6 @@ package com.worlize.gif
frameDecodedCount ++;
if (frameDecodedCount === framesToDecode && !_hasError) {
renderCompositedFrames();
cleanup();

var endTime:uint = (new Date()).valueOf();
totalDecodeTime = endTime - startTime;
Expand Down
25 changes: 22 additions & 3 deletions AS3GifPlayer/src/com/worlize/gif/GIFPlayer.as
Expand Up @@ -36,15 +36,15 @@ package com.worlize.gif
private var _frameCount:uint = 0;
private var _frames:Vector.<GIFFrame>;
private var _ready:Boolean = false;
private var _imageWidth:Number;
private var _imageHeight:Number;

public function GIFPlayer(autoPlay:Boolean = true) {
this.autoPlay = autoPlay;
if (stage) {
initMinFrameDelay();
}
else {
addEventListener(Event.ADDED_TO_STAGE, initMinFrameDelay);
}
addEventListener(Event.ADDED_TO_STAGE, initMinFrameDelay);
timer.addEventListener(TimerEvent.TIMER, handleTimer);
addEventListener(Event.REMOVED_FROM_STAGE, handleRemovedFromStage);
}
Expand Down Expand Up @@ -83,6 +83,7 @@ package com.worlize.gif
stop();
setReady(false);
unloadDecoder();
dispose();
initDecoder();
}

Expand All @@ -107,6 +108,9 @@ package com.worlize.gif
_frames = gifDecoder.frames;
_frameCount = _frames.length;
_currentFrame = -1;
_imageWidth = gifDecoder.width;
_imageHeight = gifDecoder.height;
gifDecoder.cleanup();
unloadDecoder();
setReady(true);
dispatchEvent(new Event('totalFramesChange'));
Expand Down Expand Up @@ -215,6 +219,13 @@ package com.worlize.gif
dispatchEvent(renderedEvent);
}

public function dispose():void {
if (_frames === null) { return; }
for (var i:int = 0; i < _frames.length; i ++) {
_frames[i].bitmapData.dispose();
}
}

public function get playing():Boolean {
return timer.running;
}
Expand Down Expand Up @@ -257,5 +268,13 @@ package com.worlize.gif
protected function handleAsyncDecodeError(event:AsyncDecodeErrorEvent):void {
dispatchEvent(event.clone());
}

override public function get width():Number {
return _imageWidth;
}

override public function get height():Number {
return _imageHeight;
}
}
}
Expand Up @@ -52,8 +52,10 @@ package com.worlize.gif.blocks
}

public function dispose():void {
bytes.clear();
bytes = null;
if (bytes) {
bytes.clear();
bytes = null;
}
}
}
}
6 changes: 4 additions & 2 deletions AS3GifPlayer/src/com/worlize/gif/blocks/ColorTableBlock.as
Expand Up @@ -54,8 +54,10 @@ package com.worlize.gif.blocks
}

public function dispose():void {
cachedEncodedBytes.clear();
cachedEncodedBytes = null;
if (cachedEncodedBytes) {
cachedEncodedBytes.clear();
cachedEncodedBytes = null;
}
}
}
}
6 changes: 4 additions & 2 deletions AS3GifPlayer/src/com/worlize/gif/blocks/DataBlock.as
Expand Up @@ -90,8 +90,10 @@ package com.worlize.gif.blocks
}

public function dispose():void {
bytes.clear();
bytes = null;
if (bytes) {
bytes.clear();
bytes = null;
}
}
}
}
6 changes: 4 additions & 2 deletions AS3GifPlayer/src/com/worlize/gif/blocks/HeaderBlock.as
Expand Up @@ -51,8 +51,10 @@ package com.worlize.gif.blocks
}

public function dispose():void {
bytes.clear();
bytes = null;
if (bytes) {
bytes.clear();
bytes = null;
}
}
}
}
6 changes: 4 additions & 2 deletions AS3GifPlayer/src/com/worlize/gif/blocks/ImageDataBlock.as
Expand Up @@ -42,8 +42,10 @@ package com.worlize.gif.blocks
}

public function dispose():void {
bytes.clear();
bytes = null;
if (bytes) {
bytes.clear();
bytes = null;
}
}
}
}
6 changes: 4 additions & 2 deletions AS3GifPlayer/src/com/worlize/gif/blocks/UnknownExtension.as
Expand Up @@ -29,8 +29,10 @@ package com.worlize.gif.blocks
}

public function dispose():void {
bytes.clear();
bytes = null;
if (bytes) {
bytes.clear();
bytes = null;
}
}
}
}

0 comments on commit e4ac043

Please sign in to comment.