A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Scrollbar won't scroll text.

  1. #1
    Member
    Join Date
    Apr 2004
    Location
    IA, USA
    Posts
    57

    Scrollbar won't scroll text.

    I followed a nice scrollbar tutorial here on Flashkit, and everything works- the buttons and whatnot- except the scrollbar itself. I can click and drag it just fine, but the arrows won't move it up and down, and the text doesn't scroll with the bar.

    My code is posted below; I'm hoping someone can point out what is wrong.

    I starred out what I think are the important bits.

    Code:
    onClipEvent (load) {
            //Text in scroll box.
    	whoText = "<TEXTFORMAT LEADING=\"2\"><P ALIGN=\"LEFT\">
            <FONT FACE=\"Georgia\" SIZE=\"18\" COLOR=\"#EDDABB\">
            Title Here</FONT></P></TEXTFORMAT><TEXTFORMAT LEADING=\"2\">
            <P ALIGN=\"LEFT\"><FONT FACE=\"Georgia\" SIZE=\"12\" COLOR=\"#EDDABB\">Lots of text here. 
            </FONT></P></TEXTFORMAT>";
    	scrolling = 0;
    	frameCounter = 1;
    	speedFactor = 2;
    	numLines = 20;
    	origHeight = scrollbar._height;
    	origX = scrollbar._x;
    
    	function initScrollbar() {
    		var totalLines = numLines+whoText.maxscroll-1;
    		scrollbar._yscale = 100*(numLines)/totalLines;
    		deltaHeight = origHeight-scrollbar._height;
    		lineHeight = deltaHeight/(whoText.maxScroll-1);
    	}
    
    	function updateScrollBarPos() {
    		scrollbar._y = lineHeight*(whoText.scroll-1);
    	}
    }
    
    onClipEvent (enterFrame) {
    	//if (whoText.maxscroll>1) {
    		initScrollbar();
    	//}
    	if (frameCounter%speedFactor == 0) {
    		if (scrolling == "up" && whoText.scroll>1) {
    			whoText.scroll--;
    			updateScrollBarPos();
    		} else if (scrolling == "down" && whoText.scroll<whoText.maxscroll) {
    			whoText.scroll++;
    			updateScrollBarPos();
    		}
    		frameCounter = 0;
    	}
    	frameCounter++;
    }
    onClipEvent (mouseDown) {
    	if (up.hitTest(_root._xmouse, _root._ymouse)) {
    		scrolling = "up";
    		frameCounter = speedFactor;
    		up.gotoAndStop(2);
    	}
    	if (down.hitTest(_root._xmouse, _root._ymouse)) {
    		scrolling = "down";
    		frameCounter = speedFactor;
    		down.gotoAndStop(2);
    	}
    
    //**********
    	if (scrollbar.hitTest(_root._xmouse, _root._ymouse)) {
    		scrollbar.startDrag(0, origX, deltaHeight, origX);
    		scrolling = "scrollbar";
    	}
    	updateAfterEvent();
    }
    //**********
    
    onClipEvent (mouseUp) {
    	scrolling = 0;
    	up.gotoAndStop(1);
    	down.gotoAndStop(1);
    	stopDrag();
    	updateAfterEvent();
    }
    
    //**********
    onClipEvent (mouseMove) {
    	if (scrolling == "scrollbar") {
    		whoText.scroll = Math.round((scrollbar._y)/lineHeight+1);
    	}
    	updateAfterEvent();
    }
    //**********

  2. #2
    i have no shoes. i am sad baby jeebus's Avatar
    Join Date
    Feb 2005
    Location
    australia
    Posts
    217
    i dont know if im actually going to be able to help you (ill try but cant promise...), but it would be much easier if you attached the file so i can look at it.

  3. #3
    Member
    Join Date
    Apr 2004
    Location
    IA, USA
    Posts
    57
    I've attached a simple example of what I'm doing. It has the same problem. I did some trace work on it, and after clicking the down button, for example, the lineHeight variable comes back as Infinity. This shouldn't be the case.

    Maybe that will help you help me.

    Thank you.
    Attached Files Attached Files

  4. #4
    Member
    Join Date
    Apr 2004
    Location
    IA, USA
    Posts
    57
    Aha! I've figured out the problem.

    A small little syntax error that is wrong in the tutorial on this site.

    Code:
    function initScrollbar() {
    		var totalLines = numLines+whoText.maxscroll-1;
    		scrollbar._yscale = 100*(numLines)/totalLines;
    		deltaHeight = origHeight-scrollbar._height;
    		lineHeight = deltaHeight/(whoText.maxScroll-1);
    	}
    That lineHeight variable should be equal to deltaHeight/(whoText.maxscroll-1);

    In other words, maxscroll is case sensitive, and it should not be maxScroll as shown in the tutorial.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center