Disabling keyboard navigation on the Accordion container in Flex
The following example shows how you can disable keyboard navigation on the Flex Accordion container by extending the Accordion class and overriding the protected keyDownHandler() method.
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2008/06/10/disabling-keyboard-navigation-on-the-accordion-container-in-flex/ --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:comps="comps.*" layout="vertical" verticalAlign="middle" backgroundColor="white"> <comps:MyAccordion id="accordion" width="100%" height="100%"> <mx:VBox id="v1" label="One" width="100%" height="100%"> <mx:Label text="One" /> </mx:VBox> <mx:VBox id="v2" label="Two" width="100%" height="100%"> <mx:Label text="Two" /> </mx:VBox> <mx:VBox id="v3" label="Three" width="100%" height="100%"> <mx:Label text="Three" /> </mx:VBox> <mx:VBox id="v4" label="Four" width="100%" height="100%"> <mx:Label text="Four" /> </mx:VBox> <mx:VBox id="v5" label="Five" width="100%" height="100%"> <mx:Label text="Five" /> </mx:VBox> </comps:MyAccordion> </mx:Application>
/** * http://blog.flexexamples.com/2008/06/10/disabling-keyboard-navigation-on-the-accordion-container-in-flex/ */ package comps { import mx.containers.Accordion; import flash.events.KeyboardEvent; public class MyAccordion extends Accordion { public function MyAccordion() { super(); } override protected function keyDownHandler(evt:KeyboardEvent):void { } } }
View source is enabled in the following example.
Due to popular demand, here is the “same” example in a more ActionScript friendly format:
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2008/06/10/disabling-keyboard-navigation-on-the-accordion-container-in-flex/ --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" initialize="init();"> <mx:Script> <![CDATA[ import mx.containers.VBox; import mx.controls.Label; import comps.*; private var accordion:MyAccordion; private var v1:VBox; private var v2:VBox; private var v3:VBox; private var v4:VBox; private var v5:VBox; private var l1:Label; private var l2:Label; private var l3:Label; private var l4:Label; private var l5:Label; private function init():void { l1 = new Label(); l1.text = "One"; l2 = new Label(); l2.text = "Two"; l3 = new Label(); l3.text = "Three"; l4 = new Label(); l4.text = "Four"; l5 = new Label(); l5.text = "Five"; v1 = new VBox(); v1.label = "One"; v1.percentWidth = 100; v1.percentHeight = 100; v1.addChild(l1); v2 = new VBox(); v2.label = "Two"; v2.percentWidth = 100; v2.percentHeight = 100; v2.addChild(l2); v3 = new VBox(); v3.label = "Three"; v3.percentWidth = 100; v3.percentHeight = 100; v3.addChild(l3); v4 = new VBox(); v4.label = "Four"; v4.percentWidth = 100; v4.percentHeight = 100; v4.addChild(l4); v5 = new VBox(); v5.label = "Five"; v5.percentWidth = 100; v5.percentHeight = 100; v5.addChild(l5); accordion = new MyAccordion(); accordion.percentWidth = 100; accordion.percentHeight = 100; accordion.addChild(v1); accordion.addChild(v2); accordion.addChild(v3); accordion.addChild(v4); accordion.addChild(v5); addChild(accordion); } ]]> </mx:Script> </mx:Application>
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.
6 Responses to Disabling keyboard navigation on the Accordion container in Flex
Leave a Reply Cancel reply
-
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


Hey Peter,
Just wanted to say thank you again! This worked out perfectly for what I needed it for.
Thanks,
- Nick
I made an accordion some time ago on kind of this line, I extended the accordion, however i didnt wanted to disable keyboard, just wanted to disable navigation to disabled headers, but still be able to use both mouse and keyboard to navigate.
I use a recursive function to achieve this, however it acts funny if u disable all headers (but why disable all headers anyways..)
I was looking for code to open myform with the accordion totally collapsed. In other words, all accordion pages are not open. The default is to have the first page opened.
I looked through Adobe forums, adobe class for accordion and around the internet.
I think I need something like:
my_acc.getChildAt(my_acc.numChildren -1);
I tried:
cfformitem type=”script”
function formOnLoad(){
var theChild_obj:Object = {};
var theChild_obj:Object = info.getChildAt(info.numChildren -1);
}
/cfformitem
But this did not work.
I am using CFusion MX 7 with cfform format=”Flash”
Any help would be greatly appreciated.
Thanks, Thomary
I used a work around. added a blank page and defaulted to that one.
Thanks for all these pages.
I found a lot of useful pages here.
I created a blog, i plan to post articles about flex and coding as soon as i have some free time
By now i have the code i posted above (without errors, since i didnt parsed it to be digested by the postin machine in here..) with a working example.
You can read it here
http://faithoncode.wordpress.com/2008/11/11/flex-accordionheaders/
Regards
Thank a lot. I am creating all sorts of “key less” stuff now