Thanks Josh,
I seem to be having trouble with removing lists when the list has been touched.
After applying your suggestions to my code, if I remove the list without touching it, everything is cleared from memory.
If I touch a list renderer to select it and then try to clear the list the following items remain referenced, so cannot be cleared.
Any ideas what might be causing this?
Found reference to [object PidListItemRenderer], label:'MainMenu _renderer'
Found reference to [object Image], label:'MainMenu img'
Found reference to [object List], label:'MainMenu List'
Found reference to [object PidListItem], label:'PidListRentalsItem11'
package feathers.bespokeRenderers
{
public class PidListItem
{
public var _pid:String;
public var _address:String;
public var _price:String;
public var _access:String;
public var _aid:String;
public var _thumb:String;
public function PidListItem(pid:String, address:String, price:String, access:String, aid:String, thumb:String = null) {
this._pid = pid;
this._address = address;
this._price = price;
this._access = access;
this._aid = aid;
this._thumb = thumb;
}
}
}
package feathers.bespokeRenderers
{
import feathers.controls.List;
import feathers.controls.Label;
import feathers.controls.renderers.IListItemRenderer;
import feathers.controls.renderers.DefaultListItemRenderer;
import feathers.core.FeathersControl;
import feathers.controls.Button;
import feathers.controls.ImageLoader;
import flash.geom.Point;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestHeader;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
import flash.events.IOErrorEvent;
import flash.display.Loader;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.events.SecurityErrorEvent;
import starling.events.Event;
import starling.events.Touch;
import starling.events.TouchEvent;
import starling.events.TouchPhase;
import starling.text.TextFormat;
import starling.animation.Transitions;
import starling.animation.Tween;
import starling.core.Starling;
import starling.display.Image;
import starling.events.Touch;
import starling.events.TouchEvent;
import starling.events.TouchPhase;
import starling.textures.Texture;
import starling.text.BitmapFont;
import starling.text.TextField;
import starling.display.Sprite;
import starling.textures.TextureSmoothing;
import com.greensock.layout.*;
import com.greensock.*;
import com.greensock.easing.*;
import com.Main;
import starling.extensions.brinkbit.fullscreenscreenextension.FullScreenExtension;
public class PidListItemRenderer extends DefaultListItemRenderer implements IListItemRenderer {
private var _pid:String;
private var _containerSprite:Sprite;
private var _addressText:TextField;
private var _priceText:TextField;
private var _statusText:TextField;
private var _indicator:Image;
private var _boldTextFormat:starling.text.TextFormat;
private var _lightTextFormat:starling.text.TextFormat;
private var _greyQuad:starling.display.Quad;
private var _photoOverlay:Image;
private var _imageLoadTryCount:int;
private var _imageLoader:ImageLoader;
override protected function initialize():void {
super.initialize();
_imageLoadTryCount = 0;
this.isQuickHitAreaEnabled = true;
_boldTextFormat = new starling.text.TextFormat(Main.FONT_BOLD, 35, Main.FONT_COLOUR_DARK, "left", "top");
_lightTextFormat = new starling.text.TextFormat(Main.FONT_LIGHT, 31, Main.FONT_COLOUR_DARK, "left", "top");
if(!_containerSprite) {
_containerSprite = new Sprite();
_containerSprite.touchable = false;
addChild(_containerSprite);
_greyQuad = new starling.display.Quad(242, 160 , 0x666666);
_greyQuad.touchable = false;
_containerSprite.addChild(_greyQuad);
_indicator = new Image(Main.assets.getTexture("pidlistIndicator"));
_indicator.touchable = false;
_indicator.x = FullScreenExtension.screenWidth - 60;
_indicator.y = 5;
_containerSprite.addChild(_indicator);
_priceText = new TextField(300,40, "",_boldTextFormat);
_priceText.x = 250;
_priceText.y = 12;
_priceText.touchable = false;
_containerSprite.addChild(_priceText);
_addressText = new TextField(360,100, "",_lightTextFormat);
_addressText.x = 250;
_addressText.y = 52;
_addressText.touchable = false;
_containerSprite.addChild(_addressText);
_photoOverlay = new Image(Main.assets.getTexture("pidListItemS1Overlay"));
_photoOverlay.touchable = false;
_photoOverlay.width = 242;
_photoOverlay.height = 160;
addChild(_photoOverlay);
this.addEventListener(starling.events.Event.REMOVED_FROM_STAGE, destroy);
}
}
override protected function draw():void {
super.draw();
const dataInvalid:Boolean = isInvalid(INVALIDATION_FLAG_DATA);
if (dataInvalid) {
if (_data) {
_addressText.text = this._data._address;
_priceText.text = this._data._price;
if (this._data._access == "lock") {
_indicator.texture = Main.assets.getTexture("pidlistClockIndicator");
_indicator.readjustSize();
} else if (this._data._access == "done") {
_indicator.texture = Main.assets.getTexture("pidlistTickIndicator");
_indicator.readjustSize();
} else {
_indicator.texture = Main.assets.getTexture("pidlistIndicator");
_indicator.readjustSize();
}
loadThumbnail();
} else {
_addressText.text = "";
_priceText.text = "";
}
}
}
private function loadThumbnail():void {
if (!_imageLoader){
_imageLoader = new ImageLoader();
_imageLoader.addEventListener( Event.COMPLETE, loader_completeHandler );
_imageLoader.addEventListener( IOErrorEvent.IO_ERROR, loader_ioErrorHandler );
_imageLoader.maintainAspectRatio = false;
_imageLoader.textureSmoothing = TextureSmoothing.BILINEAR;
}
_imageLoader.alpha = 0;
_imageLoader.source = this._data._thumb;
_containerSprite.addChild(_imageLoader);
}
private function loader_completeHandler(e:starling.events.Event):void {
_imageLoader.width = 242;
_imageLoader.height = 160;
TweenMax.to(_imageLoader, .5, {alpha:1});
}
private function loader_ioErrorHandler(e:starling.events.Event, data:IOErrorEvent):void {
if (_imageLoadTryCount < 6) {
trace("IMAGE LOAD RETRY");
_imageLoadTryCount++;
_containerSprite.removeChild(_imageLoader);
_imageLoader = null;
//wait half a second before trying again
TweenMax.delayedCall(.5,loadThumbnail);
} else {
trace("IMAGE LOADING ERROR");
loadMissingImage();
}
}
private function loadMissingImage():void {
_imageLoader.source = Main.assets.getTexture("missingImageS2");
_imageLoader.width = 242;
_imageLoader.height = 160;
_imageLoader.touchable = false;
TweenMax.to(_imageLoader, .5, {alpha:1});
}
private function destroy(e:Event):void {
this.removeEventListener(starling.events.Event.REMOVED_FROM_STAGE, destroy);
try{
_containerSprite.removeChild(_greyQuad);
_containerSprite.removeChild(_indicator);
_containerSprite.removeChild(_priceText);
_containerSprite.removeChild(_addressText);
removeChild(_photoOverlay);
removeChild(_containerSprite);
_greyQuad = null;
_indicator = null;
_priceText = null;
_addressText = null;
_photoOverlay = null;
trace("renderer destroyed");
} catch(e:Error) {
trace("destroying renderer error");
}
try{
_containerSprite.removeChild(_imageLoader);
_containerSprite = null;
} catch(e:Error) {
trace("destroying _imageLoader1 error", e.message);
}
try{
_imageLoader.dispose();
} catch(e:Error) {
trace("destroying _imageLoader2 error", e.message);
}
try{
_imageLoader = null;
} catch(e:Error) {
trace("destroying _imageLoader3 error", e.message);
}
}
}
}