Dec 03

Flash CS3, UIScrollBar, scroll arrows not displaying on dynamic text

Tag: FlashTyrone @ 10:01 pm

I am currently working on a Flash CS project and I recently came across an issue with using the UIScrollBar component..  The issue was quite intermittent; but after attaching the scroll bar component to dynamic the text box I was expecting to see bars and the arrows when the contents within the text box were larger than the constraints defined for the text box. After running the project both within the browser and in the SWF player, I noticed that on some occasions the scrolling was active and on some, inactive. 

After a few hours of research, I still couldn’t find a resolution to this issue. Then, I turned to the Flash CS3 documentation and after some careful reading of the UIScrollBar component documentation, I found the answer. The documentation mentioned that if you are dynamically loading text from an external source from ActionScript and then assigning that text to the dynamic text box, you must call the update() method on the scroll bar component to alert it that the contents have changed. So, if you have an instance of a dynamic text box on the stage called mytext_txt, and you attach a UIScrollBar component to the box by dragging the component on top of it.  You then must assign a instance name to the scroll bar component so that you can reference it within ActionScript.  Let’s say I name it mytext_scroll. Here is what the ActionScript 3 would look like:

 

   1:  import flash.display.*;
   2:  import flash.events.*;
   3:   
   4:  var textLoader:URLLoader = new URLLoader();
   5:  var simpleReq:URLRequest = new URLRequest("mytext.txt");
   6:   
   7:  textLoader.load(simpleReq);
   8:  textLoader.addEventListener(Event.COMPLETE, textComplete);
   9:   
  10:  function textComplete(event:Event):void {
  11:      mytext_txt.text = textLoader.data;
  12:      mytext_scroll.update();
  13:  }

 

Notice the update() on line 12. This seem to do the trick for me.  Hopefully, I was able to help someone figure this issue out. Until next time…

Happy Coding!





6 Responses to “Flash CS3, UIScrollBar, scroll arrows not displaying on dynamic text”

  1. det says:

    Hi!, Do you know how to just remove it when it is disabled. Thanks.

  2. Tyrone says:

    I’m not sure if I understand your question that well. When the UIScrollBar is disabled, it shouldn’t display at all. That’s the behavior that I have been seeing. Also, if the content within the dynamic textbox is smaller than the actual size of the textbox then the scrollbar is usually not shown. This is as much as I can say right now. Thanks for your comment.

  3. Gerri says:

    Fantastic!! THanks

  4. Mark says:

    The UIScrollBar component shows up even when there’s very little text, however the scrollbar is disabled so you just see an ugly grey bar that doesn’t do anything. If the component is disabled you know you don’t need it, in which case I set the component to .visible=false, see code below:

    myScrollBar.update();
    if(quest_mc.mySB.enabled==false)
    {
    myScrollBar.visible=false;
    }

  5. Mark says:

    Sorry, that code above had an error in it. It should be…

    myScrollBar.update();
    if(myScrollBar.enabled==false)
    {
    myScrollBar.visible=false;
    }

  6. Tyrone says:

    Ok…Cool. Thanks for sharing that.

Leave a Reply