Setting the vertical scroll position on a Spark RichEditableText control in Flex 4
The following example shows how you can programatically scroll a Spark RichEditableText control in Flex 4 by setting the verticalScrollPosition property.
Full code after the jump.
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/2009/08/19/setting-the-vertical-scroll-position-on-a-spark-richeditabletext-control-in-flex-4/ --> <s:Application name="Spark_RichEditableText_verticalScrollPosition_test" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo"> <mx:ApplicationControlBar width="100%" cornerRadius="0"> <mx:Form styleName="plain"> <mx:FormItem label="verticalScrollPosition:"> <s:HSlider id="slider" minimum="0" maximum="{richEditableTxt.contentHeight - richEditableTxt.height}" change="richEditableTxt.verticalScrollPosition = slider.value;" /> </mx:FormItem> </mx:Form> </mx:ApplicationControlBar> <s:RichEditableText id="richEditableTxt" widthInChars="20" heightInLines="10" textAlign="justify" horizontalCenter="0" verticalCenter="0"> <s:content> <s:p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tempus, eros ac dignissim interdum, elit sem euismod velit, eget laoreet urna metus nec enim. Cras ornare nulla imperdiet nulla blandit vehicula. Donec risus dolor, sollicitudin nec fringilla nec, aliquet vitae nisl. Duis tincidunt fermentum posuere. Nullam augue sem, rutrum a viverra aliquet, elementum interdum lacus. Aliquam dictum, nulla sit amet tempor commodo, tortor purus ullamcorper turpis, id aliquet dolor mauris vel turpis. Mauris placerat justo non orci porttitor hendrerit. Aenean mattis augue quis turpis dapibus sed eleifend mi sodales. Morbi sem tortor, ultricies vitae laoreet in, viverra id erat. Cras sed varius dolor. Sed vestibulum, sem at vehicula volutpat, enim augue facilisis nunc, ut dapibus nisi mi vel dui. Phasellus elementum leo quis velit mollis aliquam. Fusce a hendrerit lectus. Suspendisse potenti. Nulla urna diam, vulputate sed fringilla eget, consectetur ac risus. Duis sem nisl, hendrerit sit amet volutpat ut, posuere nec diam. Donec dignissim tortor in velit bibendum imperdiet. Sed nibh nulla, fringilla et auctor eu, tincidunt vel arcu.</s:p> <s:p>Phasellus egestas nunc et eros accumsan congue ornare nunc vestibulum. In quis erat magna, in mattis purus. Aliquam tempor, velit ac interdum sagittis, nisi neque sodales neque, ac tempus metus leo eget tellus. Cras non gravida tortor. Cras dictum rutrum vehicula. Morbi arcu odio, ultricies quis rhoncus aliquam, consectetur sit amet ligula. In aliquam fermentum mollis. Suspendisse ut massa nibh. Praesent tincidunt, tortor a semper egestas, purus mauris blandit magna, non bibendum leo leo varius odio. Suspendisse aliquet tempor arcu porta posuere.</s:p> </s:content> </s:RichEditableText> </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.
6 Responses to Setting the vertical scroll position on a Spark RichEditableText control in Flex 4
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


Doesn’t work with FlashBuilder B1.
I’ll try using the latest nightly build of Flex SDK a bit later.
So, check this out:
Standard FB b1 rendered the textbox as wide as the text. So slider didn’t work.
Downloaded latest nightly build, switched compiler, error: An internal build error..
restarted FB, no error, compiled, textbox as wide as the text… *frown* no good.
Went back to compiler properties, checked settings, disabled Network Monitor (completely unrelated…),
pressed “Apply”, compiled again, voila!
text is shown in a neat square box, slider does what it’s supposed to do.
Perfect.
Then I switched back to standard FB b1 Flex SDK, restarted FB, compiled:
Text is still shown in neat square box! *frown*?
Went back to compiler properties, checked settings, enabled Network Monitor (completely unrelated…still..), pressed “Apply”, compiled again, voila!
Textbox again as wide as text.
?
I can replicate this behaviour as much as I want.
I’m using the FB-plugin for eclipse by the way.
Is this a bug, or me being confused?
AH.. I have an other clue:
So, starting with FB b1 standard SDK, I get textbox as wide as the textlines in it.
Changing compilersettings to latest SDK, restart, compiling, same textbox still as wide as the text in it.
From menu: Project > Clean…
compiling again: Voila! Square textbox with wrapped text & working slider.
In between: I got the error:
unable to open ‘C:\Program Files\Adobe\Flash Builder Plug-in Beta\sdks\4.0.0.9377\frameworks/libs/netmon.swc’
So that was the reason for me to uncheck Network Monitor in the first place & press apply.
I guess it also preforms a ‘clean project’
Yeah, I doubt [m]any of these examples will work in the old Flex 4 Beta 1 SDK. It is super old (build 7219 vs 9377), and we have seen many renames since that old beta build.
And yes, when using nightly Flex 4 SDKs in Flash Builder 4, you’ll want to disable that network monitor since it isn’t included in Nightly SDK builds. That is/was a bug and has been fixed in newer (internal) Flash Builder 4 builds (or so I understand). I’m guessing you were seeing the odd behavior when switching SDKs because the project files weren’t always getting recompiled. Sometimes I’ll add a space and delete it just to force a recompile (or just try doing a Project > Clean).
Peter
Thanks for the example, I added some animation based on your example and posted it here http://jucast.tumblr.com/post/185468850/animated-text-scrolling-in-gumbo
Hello!
What if I update my richEditableText dinamically (for example, by clicking on a list)? It does not update my scroll properly (PS:I am very new to Flex, sorry if it is a very silly question) here is my code:
my_rich_text.textFlow = TextFlowUtil.importFromString(my_list.selectedItem.conteudo);
my_scroll.minimum = 0;
my_scroll.maximum = my_rich_text.contentHeight – my_rich_text.height;
my_rich_text.verticalScrollPosition = 0;
my_scroll.setVisible(Boolean(my_scroll.maximum > 0));
Thanks in advance!