Flash AS3: How to Make scroll bar react to dynamic textfield movement?

Posted by HeroicNate on Stack Overflow See other posts from Stack Overflow or by HeroicNate
Published on 2010-06-07T13:33:29Z Indexed on 2010/06/07 14:12 UTC
Read the original article Hit count: 216

I've been looking for a tutorial and answer to this for a while but can't find what I'm looking for. I am loading html text into a dynamic textfield, and I have a scrollbar controlling the scroll using the code below. What I want to do is also add scroll up/down buttons and have the scroll bar move in relation to the text scroll. I was just going to use "tracklistingtext.scrollV -- " for the scroll buttons, but right now the scroll bar doesn't recognize the text movement. What do I need to do to get the scroll bar to listen to the text scroll position?

var listTextreq:URLRequest=new URLRequest("tracklist.txt");
var listTextLoader:URLLoader = new URLLoader();
var bounds:Rectangle=new Rectangle(scrollMC.x,scrollMC.y,0,300);
var scrolling:Boolean=false;

function fileLoaded(event:Event):void {
 tracklistingtext.htmlText=listTextLoader.data;
 tracklistingtext.multiline=true;
 tracklistingtext.wordWrap=true;
 scrollMC.addEventListener(MouseEvent.MOUSE_DOWN, startScroll);
 stage.addEventListener(MouseEvent.MOUSE_UP, stopScroll);
 addEventListener (Event.ENTER_FRAME, enterHandler);

}

listTextLoader.addEventListener(Event.COMPLETE, fileLoaded);
listTextLoader.load(listTextreq);

function startScroll(e:Event):void {
 scrolling=true;
 scrollMC.startDrag(false,bounds);
}

function stopScroll(e:Event):void {
 scrolling=false;
 scrollMC.stopDrag();
}

function enterHandler (e:Event):void {
 if (scrolling == true) {
  tracklistingtext.scrollV = Math.round(((scrollMC.y - bounds.y)/300)*tracklistingtext.maxScrollV);
 }
}

Any help is greatly appreciated.

© Stack Overflow or respective owner

Related posts about actionscript-3

Related posts about scrollbar