我有几天患这个问题了。 有一个列表,您可以在其中拖动项目。
[Bindable] public static var posts:ArrayCollection = new ArrayCollection();
[Bindable] private var dragit:Boolean = false;
protected function lst_itemClickHandler(evt:ItemClickEvent):void {
if (evt.label == 'mousedown') {
dragit = false;
return;
}
if (evt.label == 'mouseup') {
dragit = true;
return;
}
}
<s:List id="list" width="100%" height="100%" dataProvider="{posts}" itemRenderer="postIR" selectedIndex="0" dragEnabled="{dragit}" dragMoveEnabled="true" dropEnabled="true" useVirtualLayout="false"/>
此列表有一个项目渲染器(postIR),作为其按钮,图像,TextArea和另一个Tile List及其项目渲染器 - socIR的一部分。 这是postIR:
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:c="*"
autoDrawBackground="true" creationComplete="itemrenderer1_creationCompleteHandler(event)" maxHeight="120">
<fx:Script>
<![CDATA[
[Bindable] private var index:int;
[Bindable] private var socDP:ArrayCollection;
protected function itemrenderer1_creationCompleteHandler(event:FlexEvent):void
{
index = ((this.owner as List).dataProvider as ArrayCollection).getItemIndex(data);
socDP = Copypaste.socialVector[index] as ArrayCollection;
soc.addEventListener(ItemClickEvent.ITEM_CLICK, soc_itemClickHandler);
}
//Deleted some code
]]>
</fx:Script>
<c:CheckList id="soc" width="100%" height="100%" itemRenderer="socIR" mouseDown="txt_mouseDownHandler(event)" mouseUp="soc_mouseUpHandler(event)"
dataProvider="{socDP}" allowMultipleSelection="true" useVirtualLayout="false" click="soc_clickHandler(event)">
<c:layout>
<s:TileLayout requestedColumnCount="3" verticalAlign="top" padding="5"/>
</c:layout>
</c:CheckList>
//Deleted some code
</s:ItemRenderer>
这是socIR:
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
autoDrawBackground="true" click="itemrenderer1_clickHandler(event)" creationComplete="itemrenderer1_creationCompleteHandler(event)">
<s:layout>
<s:HorizontalLayout verticalAlign="middle" padding="5"/>
</s:layout>
<s:states>
<s:State name="normal"/>
<s:State name="selected"/>
</s:states>
<fx:Script>
<![CDATA[
protected function itemrenderer1_clickHandler(event:MouseEvent):void
{
if (this.selected) {
data.selected = true;
} else {
data.selected = false;
}
var parentList:List = owner as List;
var e:ItemClickEvent = new ItemClickEvent(ItemClickEvent.ITEM_CLICK, true);
e.item = data;
e.index = parentList.dataProvider.getItemIndex(data);
e.label = "selected";
dispatchEvent(e);
}
override public function set data(value:Object):void
{
super.data = value;
if (value.selected) {
data.selected = true;
} else {
data.selected = false;
}
}
protected function itemrenderer1_creationCompleteHandler(event:FlexEvent):void
{
if (data.selected) {
this.selected = true;
} else {
this.selected = false;
}
}
]]>
</fx:Script>
<s:CheckBox id="socCheck" selected.selected="true" selected.normal="false" mouseEnabled="false"/>
<s:Image source="{'images/socialicons/' + data.icon}"/>
<s:Label text="{data.label}"/>
</s:ItemRenderer>
在我需要拖动主列表中的项目之前,一切正常。在socIR中选择的项目或消失或随机洗牌。我使用了各种方法 - 在每个itemrenderer的向量中更改主类中的项时存储数据 - public static var socialVector:Vector。 = new Vector。(); ,但它只会增加混乱。我尝试使用useVirtualLayout,但它没有帮助。 请提出任何建议,以便在拖动项目时避免数据丢失问题。 感谢。