Looping through items in a Spark List control in Flex 4
The following example shows how you can loop through items in a Spark List control in Flex 4 by setting the Boolean arrowKeysWrapFocus property.
The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 trial, see http://www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4.
For more information on getting started with Flex 4 and Flash Builder 4, see the official Adobe Flex Team blog.
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2010/02/03/looping-through-items-in-a-spark-list-control-in-flex-4/ --> <s:Application name="Spark_List_arrowKeysWrapFocus_test" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"> <s:controlBarContent> <s:CheckBox id="ch" label="arrowKeysWrapFocus:" selected="true" /> </s:controlBarContent> <s:List id="lst" arrowKeysWrapFocus="{ch.selected}" horizontalCenter="0" verticalCenter="0"> <s:layout> <s:VerticalLayout gap="0" horizontalAlign="contentJustify" requestedRowCount="5" /> </s:layout> <s:dataProvider> <s:ArrayList> <fx:Array> <fx:Object label="Application" /> <fx:Object label="BorderContainer" /> <fx:Object label="Button" /> <fx:Object label="ButtonBar" /> <fx:Object label="ButtonBarButton" /> <fx:Object label="CheckBox" /> <fx:Object label="ComboBox" /> <fx:Object label="DataGroup" /> <fx:Object label="DataRenderer" /> <fx:Object label="DropDownList" /> </fx:Array> </s:ArrayList> </s:dataProvider> </s:List> </s:Application>
View source is enabled in the following example.
Or you can set the Boolean arrowKeysWrapFocus property using ActionScript, as seen in the following example:
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2010/02/03/looping-through-items-in-a-spark-list-control-in-flex-4/ --> <s:Application name="Spark_List_arrowKeysWrapFocus_test" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"> <s:controlBarContent> <s:CheckBox id="ch" label="arrowKeysWrapFocus:" change="lst.arrowKeysWrapFocus = ch.selected;" /> </s:controlBarContent> <s:List id="lst" horizontalCenter="0" verticalCenter="0"> <s:layout> <s:VerticalLayout gap="0" horizontalAlign="contentJustify" requestedRowCount="5" /> </s:layout> <s:dataProvider> <s:ArrayList> <fx:Array> <fx:Object label="Application" /> <fx:Object label="BorderContainer" /> <fx:Object label="Button" /> <fx:Object label="ButtonBar" /> <fx:Object label="ButtonBarButton" /> <fx:Object label="CheckBox" /> <fx:Object label="ComboBox" /> <fx:Object label="DataGroup" /> <fx:Object label="DataRenderer" /> <fx:Object label="DropDownList" /> </fx:Array> </s:ArrayList> </s:dataProvider> </s:List> </s:Application>
This entry is based on a beta version of the Flex 4 SDK and therefore is very likely to change as development of the Flex SDK continues. The API can (and will) change causing examples to possibly not compile in newer versions of the Flex 4 SDK.
Peter deHaan
Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.
-
Add Widgets (Content Sidebar)
This is your Content Sidebar. Edit this content that appears here in the widgets panel by adding or removing widgets in the Content Sidebar area.
5 Responses to Looping through items in a Spark List control in Flex 4
-
Categories
- Accordion
- AccordionHeader
- ActionScript
- AddChild
- AdvancedDataGrid
- Alert
- alpha
- Animate
- AnimateProperties
- Application
- Application (Spark)
- ArrayCollection
- BarChart
- baseColor
- beta
- beta1
- beta2
- Bitmap
- Bitmap/BitmapData
- BitmapData
- BitmapFill
- BitmapFill (Spark)
- BitmapGraphic
- BitmapImage
- BitmapImage (Spark)
- BitmapImageResizeMode
- Border (Spark)
- BorderContainer (Spark)
- Box
- BuildInfo
- Button
- Button (Spark)
- ButtonBar
- ButtonBar (Spark)
- ByteArray
- Camera
- Charting
- CheckBox
- CheckBox (Spark)
- ClassFactory
- CollectionEvent
- Color
- ColorPicker
- ColorUtil
- ComboBox
- ComboBoxArrowSkin
- Compiler
- Component
- Component (Spark)
- Configuration
- Container
- ContextMenu
- ContextMenuEvent
- ContextMenuItem
- CSSCondition
- CSSSelector
- CSSStyleDeclaration
- CurrencyFormatter
- CursorManager
- Data Binding
- DataGrid
- DataGrid (Spark)
- DataGridColumn
- Date
- DateBase
- DateChooser
- DateField
- DateFormatter
- Debugging
- DefaultComplexItemRenderer
- DefaultTileListEffect
- DropDownList
- DropDownList (Spark)
- DropDownListButtonSkin
- DropDownListSkin
- DropShadowFilter
- E4X
- Effects
- Ellipse
- EmailValidator
- Embed
- Event
- Fade
- FileFilter
- FileReference
- fill
- Filters
- Flash
- Flash Integration
- FlashVars
- Flex 3 SDK
- Flex Builder
- Flex Builder 3
- Flex SDK
- Flex4
- FLVPlayback
- FocusManager
- FontLookup
- Fonts
- Form
- Form (Spark)
- FormHeading (Spark)
- FormItem
- FormItem (Spark)
- Forms
- FTETextField (Spark)
- FullScreen
- FullScreenEvent
- FxAnimateColor
- FxButtonBar
- FxCheckBox
- FXG
- FxHScrollBar
- FxHSlider
- FxList
- FxNumericStepper
- FxRadioButton
- FxRotate3D
- FxScroller
- FxTextArea
- FxTextInput
- FxToggleButton
- FxVScrollBar
- FxVSlider
- getStyleDeclaration()
- GradientEntry
- Graphic (Spark)
- HBox
- HDividedBox
- HGroup (Spark)
- HorizontalLayout
- HorizontalList
- HSBColor (Spark)
- HScrollBar (Spark)
- HSlider
- HSlider (Spark)
- HTML template
- ID3Info
- Image
- Image (Spark)
- ImageSnapshot
- itemRenderer
- JointStyle
- Label
- Label (Spark)
- Legend
- LegendItem
- LigatureLevel
- Line
- LinearGradientStroke
- LineScaleMode
- LinkBar
- LinkButton
- List
- List (Spark)
- Menu
- MenuBar
- Metadata
- MetadataEvent
- Model
- Mouse
- MouseCursor
- MouseEvent
- Move
- Namespace
- NavigatorContent (Spark)
- needsSWF
- NetConnection
- NetStream
- Nightly Builds
- NumberBaseRoundType
- NumberFormatter
- NumberValidator
- NumericCompare
- NumericStepper
- NumericStepper (Spark)
- ObjectProxy
- ObjectUtil
- paddingLeft
- paddingRight
- Panel
- Panel (Spark)
- Parallel
- Path
- PieChart
- PieSeries
- PieSeriesItem
- PopUpAnchor (Spark)
- PopUpButton
- PopUpManager
- ProgrammaticSkin
- ProgressBar
- PropertyChangeEvent
- QName
- RadialGradient
- RadioButton
- RadioButton (Spark)
- RadioButtonGroup
- RadioButtonGroup (Spark)
- Rect
- RegExp
- Regular Expressions
- Repeater
- RichEditableText
- RichText
- RichText (Spark)
- RichTextEditor
- Rotate
- Rotate3D (Spark)
- Scroller (Spark)
- Sequence
- setStyle()
- SimpleText
- SimpleText (Spark)
- skinClass
- Slider
- SliderEvent
- SolidColor
- SolidColorStroke
- Sort
- SortField
- Sound
- SoundEffect
- Spinner (Spark)
- SpriteVisualElement (Spark)
- StageDisplayState
- States
- StringUtil
- StringValidator
- StyleManager
- Styles
- SWFLoader
- SWFObject
- System
- SystemManager
- TabBar
- TabBar (Spark)
- TabNavigator
- TabStopFormat
- Text
- Text Layout Framework (TLF)
- TextArea
- TextArea (Spark)
- TextBox
- TextConverter
- TextEvent
- TextFlow
- TextFlowUtil
- TextFormat
- TextGraphic
- TextInput
- TextInput (Spark)
- TextLayoutFormat
- TextView
- Themes
- TileLayout
- TileList
- TileOrientation
- Timer
- TitleWindow
- TitleWindow (Spark)
- TLF
- ToggleButton (Spark)
- ToggleButtonBar
- ToolTip
- Transition
- Tree
- TruncationOptions
- UIComponent
- UIFTETextField
- Updater
- URLLoader
- URLRequest
- URLUtil
- URLVariables
- ValidationResultEvent
- Validator
- Validators
- VBox
- VDividedBox
- Vector
- VerticalLayout
- VerticalLayout (Spark)
- VGroup (Spark)
- Video
- VideoDisplay
- VideoElement
- VideoElement (Spark)
- VideoEvent
- VideoPlayer (Spark)
- VideoPlayerScrubBar
- ViewStack
- VScrollBar (Spark)
- VSlider
- VSlider (Spark)
- XML
- XMLList
- XMLListCollection
- ZipCodeValidator
- ZipCodeValidatorDomainType
- Zoom
-
Articles
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
-
Meta


Peter : :
I had a couple of questions on this post…
1. I copy and pasted this example into a new Flex applcation and it ran perfectly. But then I changed “requestedRowCount” to 3 instead of 5, but it still showed 5. Any ideas why that would be?
2. Then, for extra kicks, I tried to push this a bit further… One of the things that’s really bothered me and my company is how much extra work it takes to set the “requestedRowCount” on a DropDownList as written about in your blog post here last April (http://blog.flexexamples.com/2009/04/05/setting-the-row-count-on-a-dropdownlist-control-in-flex-gumbo/). So, for fun, I replaced s:List with s:DropDownList in this example to see if I could get away with significantly less code to pull off a “requestedRowCount”. I ran it and it sorta worked… The DropDownList opened and I saw only 3 items listed, but then it immediately hit a RTE (Error #1009: Cannot access a property or method of a null object reference.) in DropDownListBase on setting the “spDelta” on line 662 (the dataGroup was null). I’ve tried several things to “trick it” like giving it a DataGroup, but that results in other RTE’s due to there not being a “typicalItem” or invalid “dataGroupProperties” (I can give you more details on those RTE’s as well if you’d like). At any rate… It seems to me that if “requestedRowCount” work with list as it does in this example without an RTE, that it should in DropDownList too. Can you please explain why it’s necessary for two custom classes just to get “requestedRowCount” on a DropDownList?
Thanks for your time in reading this and for doing these examples. They are invaluable! And, if it makes any difference in my question, the Flex 4 code we’re using at our company is around the 12073 revision mark from the Adobe repository. Thanks again and I look forward to your reply!
: : Michael
@Michael,
The
requestedRowCountworks fine for me in 4.0.0 (build 13895). I’m pretty sure we fixed that issue where theminHeightproperty on the Spark List skin was getting set to 112px (5 items+border if using default item renderer). You can get around the issue by creating a custom Spark List skin without theminHeightproperty set, or even better would be to download a newer Nightly build of the Flex 4.0 SDK from http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4.As for question #2, I’d download the latest nightly build of Flex 4.0 SDK and try again, if you’re still seeing an RTE, I’d file a bug right away at http://bugs.adobe.com/flex/ and somebody at Adobe will take a look.
Thanks,
Peter
Actually, I looked at that mess of a post on Spark DropDownList and row counts, and I found a way easier way in the latest SDK (or maybe it always worked and I missed the obvious before). You can just override the
layoutproperty on the DropDownList and set the requested row count on the VerticalLayout object directly.Again, I tested in 4.0.0 (build 13895) and it worked like I expected, but please download the latest nightly build and make sure you’re still not seeing any runtime errors (and file a bug if you do).
Thanks,
Peter
Peter : :
Thanks for the prompt reply, for taking the time to revisit and test some things out, and for reposting an example. Copy and pasting the code above in your second reply into our environment still produces an RTE, but as I mentioned in my first post, we are on / around revision 12073. I will acquire the latest nightly build and report back. Thanks again for your help!
: : Michael
Peter : :
Sorry for the delay in getting back to you. We have been pretty busy prepping for the 1.0 release of our product.
We upgraded our SDK last week to revision 14184. I retested this and it works perfectly (with the knowledge of the > 6 limitation because of the DropDownListSkin).
Thanks for all your help on this!
: : Michael