简体   繁体   English

Feathers(基于Starling的Adobe AIR库)列表控件在第二次实例化时不起作用

[英]Feathers (Starling-based Adobe AIR library) List control doesn't work the second time it's instantiated

I'm having a problem with a Feathers List control. 我在Feathers List控件上遇到问题。 It works the first time I enter the screen that contains the list, but the second time I enter that screen in the same app execution, the scrolling list doesn't scroll at all plus texts don't appear. 第一次进入包含列表的屏幕时此方法有效,但是第二次在同一应用程序执行中进入该屏幕时,滚动列表完全不滚动,并且不显示任何文本。 No error appears in the console. 控制台中没有出现错误。

I've tried lots of stuff, but I still have the same problem: It only works the first time it's instantiated. 我已经尝试了很多东西,但是我仍然遇到同样的问题:它仅在第一次实例化时起作用。 If I exit the screen and come back, it doesn't work at all! 如果我退出屏幕并返回,则根本不起作用!

When exiting the screen it's disposed and when coming back to that screen it's a new instance of List. 退出屏幕时,将对其进行处置;返回该屏幕时,它将是List的新实例。 Why does it work only the first time? 为什么只能在第一次使用?

Also, I tried not using a custom ItemRenderer at all, so only the images appear, no text, and still the same happens. 另外,我尝试完全不使用自定义ItemRenderer,因此仅显示图像,不显示文本,并且仍然发生相同的情况。 The list doesn't respond to scroll events the SECOND time is instantiated. 该列表不响应第二时间实例化的滚动事件。 So it's not a problem with the ItemRenderer. 因此,ItemRenderer没问题。

Ok, here's some code: 好的,这是一些代码:

        typeList = new List();
        typeList.x = Settings.appResolution[0] - Settings.menuTypeColumnWidth;
        typeList.y = Settings.topBarHeight;
        typeList.width = Settings.menuTypeColumnWidth;
        typeList.height = Settings.appResolution[1] - Settings.topBarHeight;
        typeList.dataProvider = new ListCollection(listContents);
        typeList.itemRendererProperties['labelField'] = 'text';
        typeList.itemRendererProperties['accessoryLabelField'] = 'articles';
        typeList.itemRendererProperties['iconSourceField'] = 'thumbnail';
        var listLayout:VerticalLayout = new VerticalLayout();
        listLayout.gap = Settings.menuTypeItemGap;
        typeList.layout = listLayout;
        typeList.addEventListener(Event.CHANGE, onListChange);
        typeList.itemRendererType = MenuTypeItemRenderer;

As you can see it's nothing out of the ordinary. 如您所见,这与众不同。

Thanks for your help. 谢谢你的帮助。

确定执行第二次实例化时,列表使用的ListCollection是否仍然可用?

_list.dataProvider = new ListCollection(items);

Here's a sample of code I've used. 这是我使用的代码示例。 See if it offers any clues. 看看它是否提供任何线索。 I call the clearList function before the class is removed from the stage. 在从舞台上删除该类之前,我先调用clearList函数。

private function onAddedToStage(e:starling.events.Event):void {

removeEventListener(starling.events.Event.ADDED_TO_STAGE, onAddedToStage);
addEventListener(starling.events.Event.REMOVED_FROM_STAGE, onRemovedFromStage);


//only do this if a list does not already exist.
if(!_list){

items = new <ListItem>[];
for(var i:int = 0; i < 20; i++) {
items.push(new ListItem("Item text"));
}

_list = new List();
_list.itemRendererFactory = function():IListItemRenderer {
renderer = new ListItemRenderer();  
// pass your skins in here
renderer.defaultSkin = new Image(AssetManager.getAtlas().getTexture("listItemClear_normal"));
renderer.defaultSelectedSkin = new Image(AssetManager.getAtlas().getTexture("listItemClear_selected"));
return renderer;
};

vl = new VerticalLayout();  
vl.hasVariableItemDimensions = false;
_list.layout = vl;                      
_list.scrollerProperties.snapScrollPositionsToPixels = true;
_list.scrollerProperties.verticalScrollPolicy = Scroller.SCROLL_POLICY_AUTO;
_list.scrollerProperties.horizontalScrollPolicy = Scroller.SCROLL_POLICY_OFF;
_list.scrollerProperties.scrollBarDisplayMode = Scroller.SCROLL_BAR_DISPLAY_MODE_FLOAT;

//need to use a factory as we are not using a theme
_list.scrollerProperties.verticalScrollBarFactory = myScrollBarFactoryFunction;

_list.isSelectable = false;
_list.scrollerProperties.hasElasticEdges = true;
_list.itemRendererProperties.height = 60r;

_list.addEventListener(starling.events.Event.CHANGE, list_changeHandler);
_list.width = 320;
_list.height = StartUp._stageHeight;

addChild(_list);

_list.dataProvider = new ListCollection(items);
}
}



public function myScrollBarFactoryFunction():IScrollBar {

scrollBar = new SimpleScrollBar();
scrollBar.direction = SimpleScrollBar.DIRECTION_VERTICAL;
scrollBar.thumbProperties.defaultSkin = new Scale3Image(new Scale3Textures(AssetManager.getAtlas().getTexture("vertical-scroll-bar-thumb-skin"), 5, 14, Scale3Textures.DIRECTION_VERTICAL));      
scrollBar.thumbProperties.width = 4;
scrollBar.thumbProperties.minHeight = 20;
scrollBar.width = 4;
return scrollBar;

}


public function clearList():void {

if (_list) {
scrollBar = null;           
renderer = null;
vl = null;
removeChild(_list);     
_list = null;   

items.length = 0;
items = null;
}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM