Hi, I have a Starling list that contains itemRenderers which, when touched, slide over to the left (.x=-320) to reveal other buttons for that itemRenderer.
The issue I have at the moment is that if an item has been touched and moved over to the left, if I drag the list, all the itemRenderers refresh and so move back to the .x=0 position.
How might I stop this refreshing happening?
I'm currently using the _active variable to record whether the renderer is active (moved over to the left) or not.
My itemRenderers:
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 var _active:Boolean;
public function PidListItem(pid:String, address:String, price:String, access:String, aid:String, thumb:String = null, active:Boolean = false)
{
this._pid = pid;
this._address = address;
this._price = price;
this._access = access;
this._aid = aid;
this._thumb = thumb;
this._active = active;
}
}
}
package feathers.bespokeRenderers
{
import //removed for ease of reading
public class PidListItemRenderer extends DefaultListItemRenderer implements IListItemRenderer {
protected var _pid:String;
...etc
override protected function initialize():void {
super.initialize();
this.isQuickHitAreaEnabled = false;
if(!_containerSprite) {
_containerSprite = new Sprite();
_containerSprite.touchable = false;
addChild(_containerSprite);
_editTourButton.label = "Edit Tour";
addChild(_editTourButton);
_editSlammerButton.label = "Edit Slammer";
addChild(_editSlammerButton);
_initialSelectionButton = new feathers.controls.Button();
_initialSelectionButton.addEventListener( Event.TRIGGERED, onTriggered );
addChild(_initialSelectionButton);
//edited for ease of reading
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;
} else {
_addressText.text = "";
_priceText.text = "";
}
}
}
public function loadThumbnail():void {
if (_photo) {
destroy();
}
if (!_loader) {
_loader = new Loader();
}
try{
if (this._data._thumb) {
_urlRq = new URLRequest(this._data._thumb);
_loader.contentLoaderInfo.addEventListener (flash.events.Event.COMPLETE, onImageLoadComplete, false, 0, true );
_loader.load ( _urlRq );
}
} catch (e:Error) {
}
}
private function onImageLoadComplete(e:flash.events.Event):void {
_loader.contentLoaderInfo.removeEventListener(flash.events.Event.COMPLETE, onImageLoadComplete);
_urlRq = null;
_bm = _loader.content as Bitmap;
_photoTexture = Texture.fromBitmapData(_bm.bitmapData);
_photo = new Image(_photoTexture);
_containerSprite.addChild(_photo);
_loader.unload();
_loader = null;
_bm = null;
}
private function destroy():void {
this.removeEventListener(starling.events.Event.REMOVED_FROM_STAGE, destroy);
_containerSprite.removeChild(_photo, true);
_photo = null;
//etc
}
private function onTriggered( e:Event ):void {
var itemTriggered:DisplayObject = e.target as DisplayObject;
switch (itemTriggered.name) {
case "_initialSelectionButton":
if (!this._data._active){
//open the buttons
//slide left
TweenMax.to(this, .5, {x:-320, ease:Quint.easeOut});
this._data._active = true;
} else {
//close the buttons
TweenMax.to(this, .5, {x:0, ease:Quint.easeOut});
this._data._active = false;
}
break;
}
}
}
}
_list = new List();
_list.topPullView = _pullView;
_list.itemRendererProperties.height = 160;
_list.itemRendererFactory = function():IListItemRenderer {
_renderer = new PidListItemRenderer();
var img:Image = new Image(Main.assets.getTexture("pidListItem_normal"));
img.scale9Grid = new Rectangle( 20, 20, 30, 30 );
_renderer.defaultSkin = img;
return _renderer;
};
_vl = new VerticalLayout();
_vl.hasVariableItemDimensions = false;
_vl.useVirtualLayout = true;
_list.layout = _vl;
_list.snapScrollPositionsToPixels = true;
_list.itemRendererProperties.hasLabelTextRenderer = false;
_list.verticalScrollPolicy = feathers.controls.ScrollPolicy.ON;
_list.horizontalScrollPolicy = feathers.controls.ScrollPolicy.OFF;
_list.scrollBarDisplayMode = feathers.controls.ScrollBarDisplayMode.FLOAT;
_list.verticalScrollBarFactory = myScrollBarFactoryFunction;
_list.isSelectable = true;
_list.hasElasticEdges = true;
_list.itemRendererProperties.width = FullScreenExtension.screenWidth;
_list.clipContent = true;
_list.autoHideBackground = true;
_list.addEventListener(FeathersEventType.RENDERER_ADD, renderedAdded);
_list.addEventListener(starling.events.Event.UPDATE, list_updateHandler);
_list.width = FullScreenExtension.screenWidth;
_list.y = _listY;
_list.height = FullScreenExtension.screenHeight;
_listCollection = new ListCollection(_salesItems);
_list.dataProvider = _listCollection;
addChild(_list);
_list.scrollToPosition(0,0);
TIA.