Recently Grant Skinner wrote about Designer ScrollBars in Flex 3 - this post is very useful in helping you amputate important usability features of the ScrollBars, but it omits another further disabling requirement which is also very common when implementing designer scrollbars. I’m talking about scrollbars with fixed size ScrollThumbs. One of the scrollbar features is to set the size of the ScrollThumb according to the size of the content that needs to be scrolled. Take a look at the sample application - the scrollbars are skinned and the ScrollThumb is sized nicely (or not so nicely) according to the content:
Well, I find this feature very useful - the size of the ScrollThumb is giving the user a hint about the amount of content that needs scrolling. But vanity has almost never been in favor of usability, so I’ll have to share with you how to accomplish this further amputation of the scrollbar features.
To make a fixed size ScrollThumb you need to do roughly two things:1. To extend the ScrollThumb class by overriding the setActualSize() method.
2. To replace the ScrollThumb on the existing ScrollBar instance. I’m providing a sample application with a View Source option, so you can check how I’ve implemented the FixedSizeScrollThumb and how the scrollbar is skinned:
I prefer to specify the size of the FixedSizeScrollThumb with styles. In case of a very tiny thumb it’s useful to make the hitArea of the thumb a bit larger. I use styles again to specify this additional padding for the hitArea.
Now, we’re ready to replace the traditional ScrollThumb with the new FixedSizeScrollThumb, and this is the most tricky and controversial part of the task. I use a simple utility class ScrollBarUtil, which provides the static replaceScrollThumb method:
public static function replaceScrollThumb(scrollBar:ScrollBar):void
{
if (scrollBar != null && !(scrollBar.scrollThumb is FixedSizeScrollThumb))
{
scrollBar.removeChild(scrollBar.scrollThumb);
var fixedSizeScrollThumb:FixedSizeScrollThumb = new FixedSizeScrollThumb();
fixedSizeScrollThumb.x = scrollBar.scrollThumb.x;
fixedSizeScrollThumb.y = scrollBar.scrollThumb.y;
fixedSizeScrollThumb.styleName = new StyleProxy(scrollBar, null);
fixedSizeScrollThumb.upSkinName = "thumbUpSkin";
fixedSizeScrollThumb.overSkinName = "thumbOverSkin";
fixedSizeScrollThumb.downSkinName = "thumbDownSkin";
fixedSizeScrollThumb.iconName = "thumbIcon";
fixedSizeScrollThumb.skinName = "thumbSkin";
scrollBar.scrollThumb = fixedSizeScrollThumb;
scrollBar.addChildAt(fixedSizeScrollThumb, scrollBar.getChildIndex(scrollBar.downArrow));
}
}
This method needs an initialized ScrollBar instance, which you can get usually like this:
ScrollBarUtil.replaceScrollThumb(
ScrollBar(someFlexContainer.rawChildren.getChildByName("verticalScrollBar")));
By now, we know how to replace the ScrollThumb, but still we don’t know when to do it. Which is the moment when the container’s scrollbar is available and needs to change its thumb? In the sample above I’m using the updateComplete event handler of the Flex Container.
I know this ScrollBar looks more like a VSlider or HSlider, and maybe you will try using a skinned slider instead of a scrollbar, but you should be aware that this approach will need custom code to detect whether the content needs scrolling, which is already implemented in the Container class from the Flex Framework.This post is tagged Adobe Flex, designer, fixed size, flex, Grant Skinner, ScrollBar, ScrollThumb





52 Comments
Awesome! This helped big time.
Is it possible to make this work for a TextArea? It doesn’t seem to have public access to rawChildren or verticalScrollBar…
Hi, Anna,
If you read carefully, you’ll see that the sample above is suitable only for components inheriting the Flex Container component. The TextArea component inherits from the ScrollControlBase component, which does not have rawChildren, but has verticalScrollBar and horizontalScrollBar properties. The problem you need to solve is how to access these properties when they are declared as protected. It’s easy - you just need to extend the Flex TextArea in the following way:
package { import mx.controls.TextArea; import mx.controls.scrollClasses.ScrollBar; public class TextArea extends mx.controls.TextArea { public function getVerticalScrollBar() : ScrollBar { return verticalScrollBar; } public function getHorizontalScrollBar() : ScrollBar { return horizontalScrollBar; } public function TextArea() { super(); } } }Now these protected properties are exposed through public methods and you can use them just like in the samples above.
Cheers
You’re absolutely right - work like a charm now!!! Thank you for this excellent extension.
Hi Vladimir,
I need to have the vertical scrollbar of a container, let’s say a Canvas, outside the Canvas. What Im doing right now is hidind the verticalScrollBar of the Canvas and using an independent VScrollBar component.
On creationcomplete of the container, I set the values for the scrollbar just like:
It seems to work fine BUT the thumbSize of the independent scrollbar is not sized correctly; the min and max values are correct but the thumbSize is smaller than the canvas’ vertical scroll bar.
Do you know how can I fix this?
Thank you in advance.
Alberto
Hi Alberto,
If I’m getting it right - you have a Canvas, which has no scrolling (scroll policies of the Canvas are set to “off”), and you want to control the scrolling position of that Canvas with a separate scroll-bar.
The solution to the problem depends on where the independent scroll-bar is placed.
Variant 1 - The Canvas and the scroll-bar are placed inside another Container
The solution is easy - you gotta keep the scroll policies of the contained Canvas to “off”, but you also need to add clipContent=”false” and make sure you haven’t switched off the scrolling policies of the Canvas Container. Thus you won’t need anymore an independent scroll-bar - the scroll-bar will show automatically inside the Canvas Container.
Variant 2 - The Canvas and the scroll-bar are placed in different containers, or the layout is so complicated so you need an independent scroll-bar to fulfill layout requirements
Every scroll-bar has a ScrollThumb, which is basically a Button - its dimensions vary depending on the size of the scrolled content. Simply setting minScrollPosition and maxScrollPosition is not enough - these positions are setting the range within we scroll, but in order to change the size of the ScrollThumb, you need to supply some more information like pageSize.
On creation completion try using the setScrollProperties()-method of the ScrollBar. Check its signature in the reference documentation.
Cheers
Hi Vladimir,
First of all, thank you for your fast and good response.
Yesterday, browsing the code of the ScrollBar component, I found the same solution you point out: using setScrollProperties() you can set all the scrollbar properties of an independent scrollbar.
So the problem was: I have one container with things and I dont want this container to show its internal scrollbar but I want this scrollbar outside the container. The way to do this is using an independent scrollbar and copy all the settings of the container scrollbar to this new scrollbar. But, what if I dont have access to the container scrollbar( scrollpolicies are set to “off”? What If I cant access container.verticalScrollbar.pageSize or maxScrollposition, etc? How can I calculate the needed parameters for the setScrollProperties method?
Thanks.
Alberto
Hi again Vladimir,
I have finally found a working solution. I have created a public method on my container class to calculate everything as the Container class does in its private createScrollbarsIfNeeded method. Then, I have created a public method, getScrollProperties, to return all these calculated properties in a custom class, ScrollProperties.
Now I can have the container scrollbar “off” and access the expected scroll properties if I had the scrollbars of the container ON.
I dont know if this is the best way to do it but it works
Cheers.
Alberto
Nice hearing from you, Alberto,
Basically you’ve done a custom component - when you do custom components you should always ask yourself the question: “Do I really need a custom component?”
Very often after nice thorough discussion with a designer you’ll find ways how to fit most of the things with nesting components, using constraints, styles etc. Doing this will prevent numerous hours of coding, testing and fixing bugs - after all the guys from Adobe have done lots of stuff with and inside the Flex Framework - try first utilizing the most of it.
When you have a solution based on off- the-shelf Flex Framework components, you can start analyzing is it OK in terms of performance and construction complexity. The conclusions from such analysis will lead you to the decision whether you need to code brand new components.
Nevertheless, you can always base your custom implementation on top of the Flex Framework implementation - the Flex components are priceless source of ideas and code that you can use - sometimes by just copying useful fragments, like I suppose you’ve done in your solution after careful reading of the Container’s code.
Best Regards,
Vladimir
Thanks for the nice tutorial, but it’s difficult for a Designer.
I tried to go with the following. Works fine as long as the height is not fixed,
but when I draw rectangle with fixed height e.g. 20, the total scroll-bar turns into a half.
How can I handle that?
Please Help!
package classes { import mx.controls.scrollClasses.ScrollThumb; import mx.skins.ProgrammaticSkin; public class myScrollBar extends ProgrammaticSkin { private var scrollH:Number; public function myScrollBar() { super(); } override protected function updateDisplayList(w:Number, h:Number):void { if(parent is ScrollThumb) { var myScrollThumb:ScrollThumb = ScrollThumb(parent); scrollH = myScrollThumb.height; } super.updateDisplayList(w,h); graphics.clear(); graphics.beginFill(0x000000); graphics.drawRect(0,0,15,scrollH); graphics.endFill(); } } }Hi, Mano,
I’m not sure what is supposed to do the code fragment you have put in your comment, and to which component you’re trying to apply this programmatic skin.
The article is definitely not written as a tutorial - it is more like a programmers guide for how to make a fixed sized scroll thumb. And it’s a bit hard to read and understand if you’re a designer, involved only with skinning and styling, but not in writing custom Flex components. So, I’ll try to dumb down my article in a set of steps, that are easy to follow from a designer:
1. Define the skin for the scroll-bar:
VScrollBar { down-arrow-skin: ClassReference("VScrollBar_downArrowSkin"); up-arrow-skin: ClassReference("VScrollBar_upArrowSkin"); track-skin: ClassReference("VScrollBar_trackSkin"); thumb-skin: ClassReference("VScrollBar_thumbSkin"); thumb-icon: ClassReference("VScrollBar_thumbIcon"); }This skin defines how your scroll-bar is going to look like. But this step is not enough to have a scroll-bar with a fix sized scroll thumb.
2. Download the source code from the samples in the article from here.
Copy-paste into your project the component and util packages from the code you’ve just downloaded.
3. Define the skin for the fix sized scroll thumb:
FixedSizeScrollThumb { thumbWidth: 4; thumbHeight: 4; hitAreaPadding : 10; }The styling in the fragment above defines the fixed dimensions of the scroll thumb. In cases of really tiny scroll thumb you can set a padding area with a particular size that, so you can grab the thumb everywhere inside this area, not just on the visible dimensions.
4. Replacing the scroll bar scroll thumb with a fixed size scroll thumb. This is the step where you need a programmer to get involved, but you can try it yourself.
First, you need to identify which is the container that will have a scroll bar. Let’s imagine this Canvas is that container:
<mx:Canvas id="longTextContainer" width="240" height="200" clipContent="true" x="0" y="0" updateComplete="ScrollBarUtil.replaceScrollThumb(longTextContainer.verticalScrollBar);"> <mx:Text width="90%" text="{loremIpsumLong}"/> </mx:Canvas>All you need to do is to add this attribute to the Canvas MXML:
The direction you’ve chosen for your solution has the advantage of declaratively skin all scroll thumbs in an application, instead of using programming logic to selectively skin just the scroll thumbs of the containers you’re interested in.
Good luck!
Thanks for the sudden response
Sorry, I couldn’t add the total detail before!
Here is the complete code which will describe my intentions!
I have 1 more question! I saw in the reference of ScrollThumb that it has a maxHeigh and minHeight properties! How can I change these if I have a TextArea?
Do you have any Flex Forum which you use to help guys like me?
This is the MXML file with the style declarations:
<mx:Canvas> <mx:Style> .myscroll { background-alpha: 1; up-arrow-skin: ClassReference( null ); down-arrow-skin: ClassReference( null ); track-skin: ClassReference( null ); thumb-skin: ClassReference("classes.myScrollBar"); } </mx:Style> <mx:TextArea verticalScrollBarStyleName=”myscroll” width=”110″ height=”110″ text="{a_long_paragraph}"/> </mx:Canvas>classes/myScrollBar.as
package classes { import flash.geom.Rectangle; import mx.controls.scrollClasses.ScrollThumb; import mx.skins.ProgrammaticSkin; public class myScrollBar extends ProgrammaticSkin { private var scrollH:Number; public function myScrollBar() { super(); } override protected function updateDisplayList(w:Number, h:Number):void { if(parent is ScrollThumb) { var myScrollThumb:ScrollThumb = ScrollThumb(parent); scrollH = myScrollThumb.height; } //super.updateDisplayList(w,h); graphics.clear(); graphics.beginFill(0x000000); graphics.drawRect(0,0,15,scrollH); graphics.endFill(); parent.parent.height = 110; } }My approach (if parent is ScrollThumb) might be wrong as I’m a designer and trying to write a little code!
I want it to accomplish this feature using as simple technique as I can digest it
If there is not a simple way then please help me by setting maxHeigh and minHeight properties.
Thanks once again
Mano, I have tried your approach with the programmatic skin, but I had no luck with it - the visual appearance of the ScrollThumb is like it has a fixed size, but it actual dimensions are not. I’ve tried to override setActualSize, but again no luck - something else is setting the actual dimensions.
So, you have to stick with the steps I’ve described you in my previous response.
First, you should do steps 1, 2, 3.
Then, check out my MXML file:
<?xml version="1.0" encoding="utf-8"?> <mx:Application layout="absolute" xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> <![CDATA[ import mx.core.mx_internal; import util.ScrollBarUtil; use namespace mx_internal; ]]> </mx:Script> <mx:Style> .fixedThumbScrollBar { down-arrow-skin: ClassReference(null); up-arrow-skin: ClassReference(null); track-skin: ClassReference(null); thumb-skin: ClassReference(”skin.ScrollThumbSkin”); } FixedSizeScrollThumb { thumbWidth: 15; thumbHeight: 15; hitAreaPadding : 10; } </mx:Style> <mx:TextArea id=”textArea” verticalScrollBarStyleName=”fixedThumbScrollBar” x=”20″ y=”20″ width=”200″ height=”90″ updateComplete=”ScrollBarUtil.replaceScrollThumb(textArea.scroll_verticalScrollBar)”/> </mx:Application>In this sample I use a programmatic skin very similar to yours:
skin/ScrollThumbSkin.as
package skin { import mx.controls.scrollClasses.ScrollThumb; import mx.skins.ProgrammaticSkin; public class ScrollThumbSkin extends ProgrammaticSkin { override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void { var scrollThumb : ScrollThumb = ScrollThumb(parent); var thumbWidth : Number = scrollThumb.getStyle("thumbWidth"); var thumbHeight : Number = scrollThumb.getStyle("thumbHeight"); if (!isNaN(thumbWidth) && !isNaN(thumbHeight)) { graphics.clear(); graphics.beginFill(0x000000); graphics.drawRect(thumbWidth/2, 0, thumbWidth, thumbHeight); graphics.endFill(); } } } }Please, follow the steps carefully and try it like this!
Thanks, Works Perfect
Looking forward to see some more tutorials and unique topics from you
Thanks once again.
Hi,
I’ve been trying to apply your code to the TileList. Seems like it can’t find the rawChildren property at all. Any idea on how to go about it??
Thanks,
Damian
Hi, Damian,
It’s a bitch, but there is still no universal structure for all Flex components - some of them have directly the properties verticalScrollBar and horizontalScrollBar (e.g. Canvas), some of them are extending the ScrollControlBase component (e.g. TextArea, TileList). While the ScrollControlBase has the getters scroll_verticalScrollBar and scroll_horizontalScrollBar, they are marked with the mx_internal access modifier instead of being provided with public access. You can still access these properties, but you need to use the following imports:
import mx.core.mx_internal;
use namespace mx_internal;
The sample code below should show you how you can fix your problem:
<?xml version="1.0" encoding="utf-8"?> <mx:Application layout="absolute" xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> <![CDATA[ import mx.core.mx_internal; import util.ScrollBarUtil; use namespace mx_internal; ]]> </mx:Script> <mx:Style> .fixedThumbScrollBar { down-arrow-skin: ClassReference(null); up-arrow-skin: ClassReference(null); track-skin: ClassReference(null); thumb-skin: ClassReference(”skin.ScrollThumbSkin”); } FixedSizeScrollThumb { thumbWidth: 15; thumbHeight: 15; hitAreaPadding : 10; } </mx:Style> <mx:TileList id=”tileList” verticalScrollBarStyleName=”fixedThumbScrollBar” updateComplete=”ScrollBarUtil.replaceScrollThumb(tileList.scroll_verticalScrollBar)”/> </mx:Application>Hi there, i was trying to use your scrollbar, i wonder how do you do the glow effect in your ScrollThumb,
Thanks
Alex
Hi, Alex,
I don’t have to do anything to have a glow effect in my scroll thumb - well, that’s the programmer’s perspective in case you have someone specialized in skinning and styling components - this guy or girl (a.k.a. deseloper) usually uses the Flash IDE to prepare the symbols composing the skin and then compile them into SWC. The deseloper can put in those symbols whatever he wants - transparency, glow, blur, etc.
Another approach (which I don’t recommend) is to make a programmatic skin, where instead of using the cool drawing facilities of the Flash IDE, you code your ass off in attempts to achieve the nice glow. Programmatic skins have its application in some scenarios, but I doubt this simple scroll thumb needs so much effort.
Good luck, Alex
I spent two days looking how to do this. I tried to override the setHeight on the scrollThumb, but it won’t work. You really made my day today.
I’ve down load the zip files and looked at this over and over but I can’t seem to get it to work the error i’m getting is
track-skin: ClassReference(”VScrollBar_trackSkin”);
C:\Users\pj\Desktop\ScrollBar\Sample2\src\TestFixedSizeScrollThumb.mxml(16): Error: Definition VScrollBar_upArrowSkin could not be found.
up-arrow-skin: ClassReference(”VScrollBar_upArrowSkin”);
is there something I’m missing, thanks in advance.
Hi, Peter,
I’ve just downloaded the ZIP and imported it directly into Flex Builder 3 (the plugin version) and compiled it with Flex SDK 3.2, and it works just as expected - no errors whatsoever.
How do you import the ZIP into your workspace?
My guess is that you loose somehow the reference to the scrollAssets.swc library.
Hello there..
First off thanks for the great article. I have tried it and was able to make it work with a vertical control. I tried it with a HScrollBar and it does not seem to work. I Doing the exact same steps as with a VScrollBar and using Text in a Canvas approach just like your examples.
Is there a reason this would not work?
Hi,
Thank You very much. You saved my day.
Now I’ve got my list with custom scrollbar thumb
Hey nice work! What about the license? can we use it for commercial projects etc. too?
Simply said, YES!
Hi.
Thank you! This helped very much!
I just figured out a small workaround using ProgrammaticSkin so that you do not have to set the “ScrollBarUtil.replaceScrollThumb”-function and keep your MXML-code clean.
0. (optional) remove all ScrollBarUtil.replaceScroll… - commands in your mxml-Files
1. set this style to apply it to all Vertical Scrollbars (you can use an external css-file for that)
VScrollBar { thumbSkin: ClassReference("util.ScrollBarUtil"); }2. replace your ScrollBarUtil with the following:
package util { import component.scrollbar.FixedSizeScrollThumb; import flash.events.Event; import mx.controls.scrollClasses.ScrollBar; import mx.controls.scrollClasses.ScrollThumb; import mx.skins.ProgrammaticSkin; import mx.core.mx_internal; import mx.styles.StyleProxy; import mx.events.FlexEvent; use namespace mx_internal; public class ScrollBarUtil extends ProgrammaticSkin { private var scrollThumb : ScrollThumb; private var scrollBar:ScrollBar; public function replaceScrollThumb(e:Event = null):ScrollThumb { if (!(scrollBar.scrollThumb is FixedSizeScrollThumb)) { scrollBar.removeChild(scrollBar.scrollThumb); var fixedSizeScrollThumb : FixedSizeScrollThumb = new FixedSizeScrollThumb(); fixedSizeScrollThumb.x = scrollBar.scrollThumb.x; fixedSizeScrollThumb.y = scrollBar.scrollThumb.y; fixedSizeScrollThumb.styleName = new StyleProxy(scrollBar, null); fixedSizeScrollThumb.upSkinName = "thumbUpSkin"; fixedSizeScrollThumb.overSkinName = "thumbOverSkin"; fixedSizeScrollThumb.downSkinName = "thumbDownSkin"; fixedSizeScrollThumb.iconName = "thumbIcon"; fixedSizeScrollThumb.skinName = "thumbSkin"; scrollBar.scrollThumb = fixedSizeScrollThumb; scrollBar.addChildAt(fixedSizeScrollThumb, scrollBar.getChildIndex(scrollBar.downArrow)); return fixedSizeScrollThumb; } else { return scrollBar.scrollThumb; } } override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void { scrollThumb = ScrollThumb(parent); if (scrollThumb) { scrollBar = scrollThumb.parent as ScrollBar; if (scrollBar) { scrollBar.addEventListener(FlexEvent.UPDATE_COMPLETE, replaceScrollThumb); } } } } }Andreas, thank you for contributing further to this article!
Great work - much needed!!!
Even though I had to do some workarounds (for whatever reasons, Styles didn’t work as expected in my evironment), this was a GREAT help.
THANKS!!!!!
joey
Thanks a lot, this code works very well for me.
However;
I have a component with a vertical and a horizontal scroll bar. They have different thumb images, so I’ve tried to give them different CSS classes (for example with FixedSizeScrollThumb.vertical and FixedSizeScrollThumb.horizontal), but that doesn’t work.
Do you have any suggestions?
thanks
Have you tried this way:
<mx:Style> VScrollBar { down-arrow-skin: ClassReference("VScrollBar_downArrowSkin"); up-arrow-skin: ClassReference("VScrollBar_upArrowSkin"); track-skin: ClassReference("VScrollBar_trackSkin"); thumb-skin: ClassReference("VScrollBar_thumbSkin"); thumb-icon: ClassReference("VScrollBar_thumbIcon"); } HScrollBar { down-arrow-skin: ClassReference("VScrollBar_downArrowSkin"); up-arrow-skin: ClassReference("VScrollBar_upArrowSkin"); track-skin: ClassReference("HScrollBar_trackSkin"); thumb-skin: ClassReference("HScrollBar_thumbSkin"); thumb-icon: ClassReference("HScrollBar_thumbIcon"); } FixedSizeScrollThumb { thumbWidth: 4; thumbHeight: 4; hitAreaPadding : 10; } </mx:Style>You need to produce assets for the:
HScrollBar_trackSkin
HScrollBar_thumbSkin
HScrollBar_thumbIcon
Let me know if that worked for you!
Hi, thanks for the very useful tutorial. But i would like to know whether the following is possible with this:
Usually when user try to select full text in a document scrollbar moves down and let user to select full text…but in your example while selecting the text, scrollbar does not scroll down and does not let user to select full text.
I’ve the same situation — for some reason i cannot use TextArea and have to use text with Canvas.
Thank you
Chandra
So Greeeeeaaaaaaaat!!
I love you, all!
bT_T)=b
My CSS :
FixedSizeScrollThumb { thumbWidth: 13; thumbHeight: 28; hitAreaPadding : 13; } VScrollBar { upArrowSkin: ClassReference(null); downArrowSkin: ClassReference(null); trackSkin: Embed(source="scroll_line.png"); thumbSkin: ClassReference("com.util.ScrollBarUtil"); thumbIcon: Embed(source="scrollThumb.png"); }scrollThumb.png is 13*28I am using Flex 3.5, and the scrollThumb property is not public/not available in the ScrollBar class.
Hi Jim,
You’ve noticed that correctly. It has never been a public property - it is an mx_internal.
Please, read the code I’ve provided with the article and especially the FixedSizeScrollThumb.as . You’ll see I’m using the following lines:
But keep in mind that even with these lines added to your code, the Flex Builder code completion won’t hint you the mx_internal properties - you need to write them correctly to avoid compile errors.
Cheers,
Vladimir
Using mx_internal seems like hack. You have to look into ScrollBar.as to determine that the property exists. Is there another way to do this?
It’s not a hack, it is a proper usage of a Flex internal property. It is another question what are the available options for extending Flex components. Using mx_internal is one option, which has the disadvantage of being dependent on the Flex team and the modification they might make in the future.
When you design and develop a component, you’re thinking of limited scenarios for its usage. Basically, it is impossible to cover an infinite set of requirements. So, in the Flex team no one thought about having a fixed-size scroll-bar, probably because from usability standpoint this is a strange requirement… And when you need such very custom behavior you have no other choice but to use Flex internal properties.
Hello there.
Thank you so much about this example.
With a canvas it’s very nice but in my example - a tileList with short content, the ScrollThumb is not so nicely, it’s very large. How to fix it.
Thanks for you reply.
Cuong
I’m sorry about my problem.
I didn’t read clearly your solutions.
Thanks.
OMG. You totally saved my day
thankYou!
Hi Admin!
I got some problem with FCKEditor but I don’t know where I can post the question?
Please tell me.
Thank you and bless you.
Hi Admin, thank you for your post!
It is really helpful, but I am not able to access property scrollThumb of class ScrollBar
Basically, there is no such property in class mx.controls.scrollClasses.ScrollBar, and nothing is said about it in adobe livedocs.
What am I doing wrong? Do I have to use some other ScrollBar class? Or is it a matter of versions of SDK?
I’m using flex SDK 3.5 now
Hi George,
Please read the comments from Jul 7th, 2010. These comments answer your question!
I wanted to thank you for this post. I’ve spent a couple of days searching for this information and there enough depth here that not only was I able to get it to work but I learned something in the process. Every other similar topic I found wasn’t thorough enough, and my personal experience wasn’t great enough to do this on my own.
Not to mention this post is over 2 years old and is still getting comments regularly and they are being addressed.
I admire the dedication
Thank you again,
-Kyle
Thanks a lot, Kyle!
The feeling of appreciation and receiving such comment on a pressured Friday is just awesome
This is the best trick ever!!! I was having issues with variable row height item renders in a list. The client didn’t like the fact that the scrollbar thumb was resizing every time you scroll the list because each item has a different size…this totally fixed that!
I realize this is a pretty old post, but it came up in the top Google results as I was recently trying to do this same thing. I solved it a bit differently, using just a skin class, and the mx_internal namespace.
In my skin class (extends Border):
override public function get measuredWidth():Number { return 25; } override public function get measuredHeight():Number { return 45; } private var _isActualSizeSet: Boolean = false; override public function setActualSize(newWidth:Number, newHeight:Number):void { super.setActualSize(measuredWidth, measuredHeight); if(_isActualSizeSet) return; _isActualSizeSet = true; var scrollThumb: ScrollThumb = parent as ScrollThumb; var scrollBar: ScrollBar = scrollThumb.parent as ScrollBar; scrollThumb.setActualSize(measuredWidth, measuredHeight); scrollThumb.setRange(0, scrollBar.virtualHeight - scrollThumb.height, scrollBar.minScrollPosition, scrollBar.maxScrollPosition); var hitArea: Sprite = new Sprite(); hitArea.graphics.beginFill(0xff6600); hitArea.graphics.drawRect(0, 0, measuredWidth, measuredHeight); hitArea.visible = false; scrollThumb.addChild(hitArea); scrollThumb.hitArea = hitArea; }…then all one need do is set the skin style in CSS, like:ScrollBar { thumb-skin: ClassReference("com.whatever.skins.FixedSizeThumbSkin"); }…you could even use the nifty custom CSS selectors to control the size of the thumb this way too!Thanks for the great post!
//Matt
I could not get Matt Hayes code to work. For some reason, the actual size of the thumb is still the calculated thumb height. I have variableRowHeight = true.
I found that the height of the scroll thumb must include the height of the down arrow. Otherwise, the thumb goes past the track up to the lower boundary of the down arrow.
Incoming Links
Leave a Reply