Setting a specific number of columns in a TileList control in Flex
The following example shows how you can resize a Flex TileList control to a certain number of columns by setting the columnCount property in MXML or ActionScript.
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/08/07/setting-a-specific-number-of-columns-in-a-tilelist-control-in-flex/ -->
<mx:Application name="TileList_columnCount_test"
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:ArrayCollection id="arrColl">
<mx:source>
<mx:Array>
<mx:Object label="One" />
<mx:Object label="Two" />
<mx:Object label="Three" />
<mx:Object label="Four" />
<mx:Object label="Five" />
<mx:Object label="Six" />
<mx:Object label="Seven" />
<mx:Object label="Eight" />
<mx:Object label="Nine" />
<mx:Object label="Ten" />
</mx:Array>
</mx:source>
</mx:ArrayCollection>
<mx:ApplicationControlBar dock="true">
<mx:Form styleName="plain">
<mx:FormItem label="columnCount:">
<mx:HSlider id="slider"
minimum="1"
maximum="5"
value="5"
snapInterval="1"
tickInterval="1"
liveDragging="true" />
</mx:FormItem>
</mx:Form>
</mx:ApplicationControlBar>
<mx:TileList id="tileList"
dataProvider="{arrColl}"
columnCount="{slider.value}"
columnWidth="100"
rowCount="2"
rowHeight="100"
verticalScrollPolicy="on" />
</mx:Application>
View source is enabled in the following example.
You can also set the columnCount property using ActionScript, as seen in the following example:
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/08/07/setting-a-specific-number-of-columns-in-a-tilelist-control-in-flex/ -->
<mx:Application name="TileList_columnCount_test"
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.events.SliderEvent;
private function slider_change(evt:SliderEvent):void {
tileList.columnCount = evt.value;
}
]]>
</mx:Script>
<mx:ArrayCollection id="arrColl">
<mx:source>
<mx:Array>
<mx:Object label="One" />
<mx:Object label="Two" />
<mx:Object label="Three" />
<mx:Object label="Four" />
<mx:Object label="Five" />
<mx:Object label="Six" />
<mx:Object label="Seven" />
<mx:Object label="Eight" />
<mx:Object label="Nine" />
<mx:Object label="Ten" />
</mx:Array>
</mx:source>
</mx:ArrayCollection>
<mx:ApplicationControlBar dock="true">
<mx:Form styleName="plain">
<mx:FormItem label="columnCount:">
<mx:HSlider id="slider"
minimum="1"
maximum="5"
value="5"
snapInterval="1"
tickInterval="1"
liveDragging="true"
change="slider_change(event);" />
</mx:FormItem>
</mx:Form>
</mx:ApplicationControlBar>
<mx:TileList id="tileList"
dataProvider="{arrColl}"
columnCount="5"
columnWidth="100"
rowCount="2"
rowHeight="100"
verticalScrollPolicy="on" />
</mx:Application>
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/08/07/setting-a-specific-number-of-columns-in-a-tilelist-control-in-flex/ -->
<mx:Application name="TileList_columnCount_test"
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white"
initialize="init();">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.containers.ApplicationControlBar;
import mx.containers.Form;
import mx.containers.FormItem;
import mx.controls.HSlider;
import mx.controls.TileList;
import mx.core.ScrollPolicy;
import mx.events.SliderEvent;
private var arrColl:ArrayCollection;
private var slider:HSlider;
private var tileList:TileList;
private function init():void {
arrColl = new ArrayCollection();
arrColl.addItem({label:"One"});
arrColl.addItem({label:"Two"});
arrColl.addItem({label:"Three"});
arrColl.addItem({label:"Four"});
arrColl.addItem({label:"Five"});
arrColl.addItem({label:"Six"});
arrColl.addItem({label:"Seven"});
arrColl.addItem({label:"Eight"});
arrColl.addItem({label:"Nine"});
arrColl.addItem({label:"Ten"});
slider = new HSlider();
slider.minimum = 1;
slider.maximum = 5;
slider.value = 5;
slider.snapInterval = 1;
slider.tickInterval = 1;
slider.liveDragging = true;
slider.addEventListener(SliderEvent.CHANGE, slider_change);
var formItem:FormItem = new FormItem();
formItem.label = "columnCount:";
formItem.addChild(slider);
var form:Form = new Form();
form.styleName = "plain";
form.addChild(formItem);
var appControlBar:ApplicationControlBar = new ApplicationControlBar();
appControlBar.dock = true;
appControlBar.addChild(form);
Application.application.addChildAt(appControlBar, 0);
tileList = new TileList();
tileList.dataProvider = arrColl;
tileList.columnCount = 5;
tileList.columnWidth = 100;
tileList.rowCount = 2;
tileList.rowHeight = 100;
tileList.verticalScrollPolicy = ScrollPolicy.ON;
addChild(tileList);
}
private function slider_change(evt:SliderEvent):void {
tileList.columnCount = evt.value;
}
]]>
</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.
10 Responses to Setting a specific number of columns in a TileList control 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


Hi, thanks for this code.
I want to change column count without changing width of the list.
I mean tilelist’s width should remain same, but number of columns should change dynamically.
is it possible?
Yogini,
Instead of specifying the
columnWidthproperty, set thewidthproperty on the TileList object:<?xml version="1.0" encoding="utf-8"?> <mx:Application name="TileList_columnCount_test" xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white"> <mx:ArrayCollection id="arrColl"> <mx:source> <mx:Array> <mx:Object label="One" /> <mx:Object label="Two" /> <mx:Object label="Three" /> <mx:Object label="Four" /> <mx:Object label="Five" /> <mx:Object label="Six" /> <mx:Object label="Seven" /> <mx:Object label="Eight" /> <mx:Object label="Nine" /> <mx:Object label="Ten" /> </mx:Array> </mx:source> </mx:ArrayCollection> <mx:ApplicationControlBar dock="true"> <mx:Form styleName="plain"> <mx:FormItem label="columnCount:"> <mx:HSlider id="slider" minimum="1" maximum="5" value="5" snapInterval="1" tickInterval="1" liveDragging="true" /> </mx:FormItem> </mx:Form> </mx:ApplicationControlBar> <mx:TileList id="tileList" dataProvider="{arrColl}" columnCount="{slider.value}" width="600" rowCount="2" rowHeight="100" verticalScrollPolicy="on" /> </mx:Application>Peter
Hello Peter,
Is it possible to have “previous” and “next” button control the content in Tilelist control? I don’t want to show the scroll bar, but there are more items in the list that I can navigate.
Thanks for your help,
SHAH
ohh it worked…
Thanks :)
it was really helpful.
-Yogini.
Shah,
I believe you can set the
horizontalScrollPolicyand/orverticalScrollPolicyproperties to “off” and then just set thehorizontalScrollPositionproperty to programmatically scroll the content. Something like this should do the trick (although you’ll have to tweak the code if you want it to scroll vertically instead of horizontally):Peter
I have a component very close to the above example. I’m trying to use scrollToIndex with this.. It works with my stand alone example.
But in my application scrollToIndex is not working. I dont see any difference between stand alone code and application.
hi Peter deHaan
i have a tilelist with four columns and variable rows.
but now i need a gap between column cells and at the same time i need a smooth scrolling for tilelist
when i have more no of items.for scrolling now i am using with variable row height. for my tilelist
two bars are there one is upbar image above the tilelist and downbar below the tilelist. when we drag item
near to the bars the tilelist wants to start action of scrolling smoothly
these are twoissues i need ;
1) columncells gap
2) smooth scrolling
thanks
2) smooth scrolling
Yes I did
Hi,
I have the same question like chandra shekar. Is that possible to add columnscell gap in some way?
I have idea about blank element – but there’ll be problem with “selectable” of that kind of element…
Maybe is some way without stupid, irracional combination?
ok I got it.
I had item renderer inside tile list, so I added VBox up to image (or other element) and there it’s possible to add gap.