From 6e123c3c8b1d37c61c6f3482e209986a1ff265c4 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Tue, 24 Mar 2009 22:24:02 +0000 Subject: [PATCH] Added scrollToKey(). git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@793 ed5b42cb-e716-0410-a449-f6a68f950b19 --- src/as/com/threerings/flex/DSetList.as | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/as/com/threerings/flex/DSetList.as b/src/as/com/threerings/flex/DSetList.as index fa8cd41b..01b00473 100644 --- a/src/as/com/threerings/flex/DSetList.as +++ b/src/as/com/threerings/flex/DSetList.as @@ -7,6 +7,7 @@ import mx.core.IFactory; import mx.core.ScrollPolicy; import mx.collections.ArrayCollection; +import mx.collections.IList; import mx.collections.Sort; import mx.controls.List; @@ -66,6 +67,15 @@ public class DSetList extends List _data.refresh(); } + /** + * Scroll so that the entry with the specified key is visible. + */ + public function scrollToKey (key :Object) :Boolean + { + var scrollIdx :int = findKeyIndex(key, false); + return (scrollIdx == -1) ? false : scrollToIndex(scrollIdx); + } + /** * Initialize listening on the specified object. * @@ -148,12 +158,13 @@ public class DSetList extends List } /** - * Find the index of the specified entry key from the raw list. + * Find the index of the specified entry key from the raw or filtered list. */ - protected function findKeyIndex (key :Object) :int + protected function findKeyIndex (key :Object, raw :Boolean = true) :int { - for (var ii :int = 0; ii < _data.list.length; ii++) { - if (Util.equals(key, DSet_Entry(_data.list.getItemAt(ii)).getKey())) { + var list :IList = raw ? _data.list : _data; + for (var ii :int = 0; ii < list.length; ii++) { + if (Util.equals(key, DSet_Entry(list.getItemAt(ii)).getKey())) { return ii; } }