School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,419 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,505 people online right now. Registration is fast and FREE... Join Now!




Custom scrollbar with dynamic textfield (AS 2)

 

Custom scrollbar with dynamic textfield (AS 2)

Pasquinel

3 Nov, 2008 - 03:37 PM
Post #1

New D.I.C Head
*

Joined: 2 Nov, 2008
Posts: 1

I have a problem getting a custom scroll bar working together with my scroll-buttons. I hope someone can help me further.

Here's the situation (I am using Actionscript 2):

I am pulling my text from an xml-file into a dynamic textbox.
Next to this textbox I have a up and a down button to scroll to the text. This works fine.

But, this way yoa are not able to see how many text is still to come, so I want to implement a custom scrollbar which will scroll with the text so you can see how much text is till to come. Also this scrollbar must be able to scroll the text, like the buttons do. And if you use the buttons to scroll, the scrolbar has to scroll along.

I can't seem to get the scrollbar working right. Either it scrolls, but the text is visible moving outside the dynamic textbox, and I cannot get thescrollbar and the up- and downbutton to work together.

The dynamic textfield is called 'content_tkst', the scrollbar is called scroller_mc.

The code for the buttons is as follows:

Two functions:

CODE

function scrup() {
    content_tkst.scroll=content_tkst.scroll-1;
        
}

function scrdown() {
    content_tkst.scroll=content_tkst.scroll+1;
}


And the code on the buttons:

Up-button:
CODE

on(press) { upint=setInterval(scrup,100);
}

on(release) { clearInterval(upint);
}


Down-button:
CODE

on(press) { downint=setInterval(scrdown,100);
}

on(release) { clearInterval(downint);
}


And here is the code I have sofar for the scrollbar:

CODE

var scrollUpper:Number = 227;
var scrollLower:Number = 517;

var textLower:Number = 196;
var textUpper = content_tkst.maxscroll;

var scrollRange:Number = scrollLower - scrollUpper;
var textRange = textLower - textUpper;
//trace (textRange);

function scroll() {
    //upint=setInterval(scrup,100);
    //setInterval(scrdown,100);
    var moved:Number = scroller_mc._y - scrollUpper;
    var pctMoved:Number = moved/scrollRange;
    var textMove:Number = pctMoved*textRange;
    content_tkst._y = textLower - textMove;

    
}

scroller_mc.onPress = function() {
    this.startDrag (false,this._x,scrollUpper,this._x,scrollLower);
    this.onMouseMove = scroll;
}

scroller_mc.onRelease = scroller_mc.onReleaseOutside = function() {
    this.stopDrag();
    this.onMouseMove = null;
}


Can someone please help me? I have been looking al over the internet, but everywhere there is a tut or a possible answer, the are talking about the components, and I don't want to use those.

Thnks in advance!

User is offlineProfile CardPM
+Quote Post


ksegars4

RE: Custom Scrollbar With Dynamic Textfield (AS 2)

25 May, 2009 - 06:45 PM
Post #2

New D.I.C Head
*

Joined: 25 May, 2009
Posts: 1

I have the same issue with the same code....please help!!!

var scrollUpper:Number = 6.5;
var scrollLower:Number = 308.4;

var textLower:Number = 10
var textUpper:Number = -2040;

var scrollRange:Number = scrollLower - scrollUpper;
var textRange:Number = textLower - textUpper;

function scroll() {
var moved:Number = scroller_mc._y - scrollUpper;
var pctMoved:Number = moved/scrollRange;
var textMove:Number = pctMoved*textRange;
text_mc._y = textLower - textMove;
}

scroller_mc.onPress = function() {
scroller_mc.startDrag(false,scroller_mc._x,scrollUpper,scroller_mc._x,scrollLower);
scroller_mc.onMouseMove = scroll;
}

scroller_mc.onRelease = scroller_mc.onReleaseOutside = function() {
scroller_mc.stopDrag();
scroller_mc.onMouseMove = null;
}

User is offlineProfile CardPM
+Quote Post

tdurant

RE: Custom Scrollbar With Dynamic Textfield (AS 2)

19 Jun, 2009 - 09:01 AM
Post #3

New D.I.C Head
*

Joined: 11 Apr, 2009
Posts: 1

Why don't you just drop in a scroll bar component and set it to auto like this:
CODE

import fl.controls.*;

mySb.setVScroll("auto");

easy cheesy
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 11:50PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month