« New Work: Interbank Banca Celular | Home | Very good Flash vs Silverlight comparison »
May 8, 2009
UIScrollBar component and scrollPosition
This is a very simple note that i want to share regarding the UIScrollBar component in flash and it's scrollPosition property.
I had the need to have a scrollbar on the bottom part of the menu i posted here but scrollPosition just didn't work. Here is why and how to workaround it.
UIScrollbar is a component that inherits the ScrollBar class. It adds a target property that will store the textfield reference.
Somehow i think the component listens to it's scroll property and reflects it on it's scrollPosition, so if you don't have a target set scrollPosition will always be 0.
The workaround is to create an instance of the ScrollBar class and add it to the stage via ActionScript.
The only way to use the ScrollBar class in flash is to have the UIScrollBar on the movie library so be sure to drag it from the component panel.
Here is a quick example:
import fl.controls.ScrollBar;
var myScrollBar:ScrollBar = new ScrollBar();
myScrollBar.height = 300;
myScrollBar.minScrollPosition = 0;
myScrollBar.maxScrollPosition = 10;
myScrollBar.scrollPosition = 5;
addChild(myScrollBar);
Hope this helps someone!
--fernando
Part of the problem with the UIScrollBar that I've been able to figure out is it's not detecting change events from a timeline-instantiated textfield.
But you don't have to resort to instantiating it with ActionScript, you can simply listen to the event yourself and force the scrollbar to update. I've posted this solution on my blog here: http://www.joeflash.ca/blog/2009/05/flash-cs3-uiscrollbar-bug.html