The forums have permanently moved to This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 8 of 8

Thread: scrollbar

  1. #1


    hello, i have one simple question. I did simple scrollbar for text which is loaded from external file. But, if the text in textfield is too short ( few words ) I dont want scrollbar to roll.
    I would be grateful for any useful advice.

    var loader:URLLoader = new URLLoader(new URLRequest("abcd.txt"));loader.addEventListener(Event.COMPLETE, completeHandler);
    function completeHandler(event:Event):void{
        var loadedText:URLLoader = URLLoader(;
        tSpeech.text =;
    tSpeech.multiline = true;
    tSpeech.wordWrap = true; 
    function upScrollText(evt:MouseEvent):void {
        tSpeech.scrollV -=1;
    bScrollUp.addEventListener(MouseEvent.CLICK, upScrollText);
    function downScrollText(evt:MouseEvent):void {
        tSpeech.scrollV +=1;
    bScrollDown.addEventListener(MouseEvent.CLICK, downScrollText);
    var bounds:Rectangle = new Rectangle(bScrollDrag.x, bScrollDrag.y,0,100);
    var dragging:Boolean = false;  
    function dragScroll(evt:MouseEvent):void{
        dragging = true;
    function dropScroll(evt:MouseEvent):void{
        dragging = false 
    bScrollDrag.addEventListener(MouseEvent.MOUSE_DOWN, dragScroll);
    stage.addEventListener(MouseEvent.MOUSE_UP, dropScroll);
    function checkSlider(evt:Event):void {
        if(dragging) {
            tSpeech.scrollV = Math.round(bScrollDrag.y - bounds.y)*tSpeech.maxScrollV/100
    stage.addEventListener(Event.ENTER_FRAME, checkSlider);
    function speechScrolled(evt:Event):void{
        bScrollDrag.y = bounds.y + (tSpeech.scrollV*100/tSpeech.maxScrollV);
    tSpeech.addEventListener(Event.SCROLL, speechScrolled);
    tSpeech.mouseWheelEnabled = true;

  2. #2
    For that you need to check if the text maxScrollV is bigger then 1. If it is there is something to scroll if not the text is short and you don`t need the scroller.
    Also i advice that you add the enter frame event when the mouse is down on the button element instead of having it run the check on every frame.

  3. #3
    thank you,
    i have to say that I am AS3 beginer. It would help if you give me example what you mean in code.

  4. #4
    var bounds:Rectangle = new Rectangle(bScrollDrag.x, bScrollDrag.y,0,100);
    and now i tried change the 100 in previous code to 0. It do what i want it to do. now my question is, how i can change number there with:
    if (tSpeech.maxScrollV > 1) {}
    Last edited by Hutar; April 16th, 2012 at 04:10 PM.

  5. #5
    Well this might have more then one answer. I guess there is more then one approach to tackle this problem. I usually make the scroll bar an separate component (set of movie clips and the code to control them), and i add this component via addChild() and set the object i need scrolled for target to that component. Using this approach allows to add/remove the scroll bar on conditions and to reuse the component more then once with no much code to it.

    TextScrollerDemo demonstrates what i mean with this. In this small demo you can change the text in focus. To add extra text so the scroller to get bigger(notice that the scrollers head updates position after the amount of text changes), the scroll bar component can change size to match the text field height.

    This basic functionality is achieved with a such set of movie clips(totally editable) and a single class that controls them.
    The class itself is very simple to use.
    var scroller:MovieClip = new TextScroller(target:textField);
    The TextScroller class he 2 public methods.
    1. set/get methods for the target that will be scrolled.
    2. .updateScroller() - that will rearrange the elements of the scroll bar to match the current text field height.

    So in your case how would you use this component to implement what you are looking for.
    //lets name the targeted textField textFieldA
    var scroller:MovieClip; 
    if(textFieldA.maxScrollV >1){
        scroller = new TextScroller(textFieldA);
        scroller.x = textFieldA.x + textFieldA.width;
        scroller.y = textFieldA.y; 
    I am not that good in explanations but i hope you can understand what i mean with all that.

    You can download the source for the demo from :

    This .rar contains and TextScrollerDemo.fla (cs4,cs5,cs5.5). The .fla file have in its library all the items that the scroll bar needs in folder called TextScrollerAssets. you can change the movieClips as much as you want short from renaming then. NOTE: The class only arrange them on the y axis. If you make changes on the x axis in the moviClip component the class wont be able to compensate for that.
    Feel free to use this as much as you want on any sort of projects. If you have more questions i will be happy to answer them.

    Regards Thovas

  6. #6
    thank you
    and could i ask you to upload it in CS3 ( I feel like livining in cave )?
    Last edited by Hutar; April 16th, 2012 at 05:02 PM.

  7. #7
    i don`t have cs3 installed for some time now. will see what i can do though

    Edit: The .rar is updated and have CS3 version in it also
    Last edited by Thovas; April 16th, 2012 at 05:56 PM.

  8. #8
    one more time, thnx

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012