我正在尝试创建一个类似于我的Mac上的Finder菜单的List。换句话说,如果我点击列表项,请按住鼠标并在列表中上下移动我想要更改所选项目。
在我的Flex应用程序中,如果我单击我的列表然后,在鼠标仍然向下的情况下,向上和向下移动列表,所选项目保持不变。
非常感谢任何建议。
由于
答案 0 :(得分:2)
在StackOverflow传统中,我在更多工作之后发布了我自己的问题的解决方案:
我的名单上有一个ItemRenderer。在ItemRenderer中,我声明了一个变量来保存对拥有List的引用。
private var _parentList:List;
在'设置数据' function我将此变量设置为所有者List。
override public function set data(value:Object):void {
super.data = value;
// Check to see if the data property is null.
if (value == null)
return;
// If the data property is not null.
// Get a reference to the parent list.
_parentList = this.owner as List;
...
然后我添加了一个EventListener来监听MouseDown事件。
// Attach an eventListener to the ItemRenderer.
this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
...
我的onMouseOver处理程序如下所示。
private function onMouseOver(event:MouseEvent):void {
//trace(data.LocationName);
if (event.buttonDown == true) {
_parentList.selectedIndex = itemIndex;
}
}
所以有了这个,我可以在我的列表上鼠标按下并按住鼠标按钮在列表中上下移动,光标下方的列表项始终被选中。最后一点是确保List响应ItemRenderer设置的selectedIndex。当用户通过与控件交互更改selectedIndex属性时,控件将调度更改和更改事件。以编程方式更改selectedIndex属性的值时,它将调度valueCommit事件。为了确保我响应我对所选列表项的程序化更改,我在valueCommit事件中添加了一个处理程序。
<s:List
id="locationsList"
dataProvider="{presenter.locations}"
itemRenderer="itemrenderers.locationListItemRenderer"
useVirtualLayout="false"
width="1869.698" height="1869.698"
y="65.151" x="65.151"
borderVisible="true"
borderColor="{presenter.backgroundColour}"
contentBackgroundAlpha="0"
contentBackgroundColor="0xff336c"
labelField="label"
change="presenter.onLocationListChange(event)"
valueCommit="presenter.onLocationListValueCommit(event)">
<s:layout>
<s:BasicLayout />
</s:layout>
</s:List>
到目前为止似乎工作正常。希望它有所帮助。